Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support "splice" node, which is like "block" but doesn't add the brac…

…kets in gen_code
  • Loading branch information...
commit 6e751ef4374526831c9f5b3139970a1d28175ac4 1 parent 84b85fa
@mishoo mishoo authored
Showing with 17 additions and 8 deletions.
  1. +17 −8 lib/process.js
View
25 lib/process.js
@@ -75,6 +75,12 @@ function ast_walker(ast) {
return a;
}) ];
};
+ function _block(statements) {
+ var out = [ this[0] ];
+ if (statements != null)
+ out.push(MAP(statements, walk));
+ return out;
+ };
var walkers = {
"string": function(str) {
return [ this[0], str ];
@@ -88,12 +94,8 @@ function ast_walker(ast) {
"toplevel": function(statements) {
return [ this[0], MAP(statements, walk) ];
},
- "block": function(statements) {
- var out = [ this[0] ];
- if (statements != null)
- out.push(MAP(statements, walk));
- return out;
- },
+ "block": _block,
+ "splice": _block,
"var": _vardefs,
"const": _vardefs,
"try": function(t, c, f) {
@@ -1200,6 +1202,13 @@ function gen_code(ast, options) {
return make_block_statements(statements)
.join(newline + newline);
},
+ "splice": function(statements) {
+ var a = make_block_statements(statements, true);
+ return MAP(a, function(line, i) {
+ // the first line is already indented
+ return i > 0 ? indent(line) : line;
+ }).join(newline);
+ },
"block": make_block,
"var": function(defs) {
return "var " + add_commas(MAP(defs, make_1vardef)) + ";";
@@ -1440,7 +1449,7 @@ function gen_code(ast, options) {
return add_spaces([ out, make_block(body) ]);
};
- function make_block_statements(statements) {
+ function make_block_statements(statements, noindent) {
for (var a = [], last = statements.length - 1, i = 0; i <= last; ++i) {
var stat = statements[i];
var code = make(stat);
@@ -1458,7 +1467,7 @@ function gen_code(ast, options) {
a.push(code);
}
}
- return MAP(a, indent);
+ return noindent ? a : MAP(a, indent);
};
function make_switch_block(body) {
Please sign in to comment.
Something went wrong with that request. Please try again.