Allow expand in array literals

This commit is contained in:
Anthony Van de Gejuchte
2016-06-11 01:40:45 +02:00
committed by Richard van Velzen
parent 0a3d780327
commit f9cab7ad61
6 changed files with 89 additions and 9 deletions

View File

@@ -371,15 +371,15 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
}
}, AST_Scope);
var AST_Expansion = DEFNODE("Expansion", "symbol", {
var AST_Expansion = DEFNODE("Expansion", "expression", {
$documentation: "An expandible argument, such as ...rest, a splat, such as [1,2,...all], or an expansion in a variable declaration, such as var [first, ...rest] = list",
$propdoc: {
symbol: "AST_Symbol the thing to be expanded"
expression: "AST_Symbol the thing to be expanded"
},
_walk: function(visitor) {
var self = this;
return visitor._visit(this, function(){
self.symbol.walk(visitor);
self.expression.walk(visitor);
});
}
});
@@ -516,7 +516,7 @@ var AST_Destructuring = DEFNODE("Destructuring", "names is_array default", {
out.push(node);
}
if (node instanceof AST_Expansion) {
out.push(node.symbol);
out.push(node.expression);
}
}));
return out;

View File

@@ -657,7 +657,7 @@ function OutputStream(options) {
DEFPRINT(AST_Expansion, function (self, output) {
output.print('...');
self.symbol.print(output);
self.expression.print(output);
});
DEFPRINT(AST_Destructuring, function (self, output) {

View File

@@ -1166,7 +1166,7 @@ function parse($TEXT, options) {
next();
a.push(new AST_Expansion({
start: prev(),
symbol: as_symbol(AST_SymbolFunarg),
expression: as_symbol(AST_SymbolFunarg),
end: S.token,
}));
} else {
@@ -1385,7 +1385,7 @@ function parse($TEXT, options) {
var symbol = _make_symbol(sym_type);
children.push(new AST_Expansion({
start: prev(),
symbol: symbol,
expression: symbol,
end: S.token
}));
next();
@@ -1586,6 +1586,9 @@ function parse($TEXT, options) {
if (allow_trailing_comma && is("punc", closing)) break;
if (is("punc", ",") && allow_empty) {
a.push(new AST_Hole({ start: S.token, end: S.token }));
} else if (is("expand", "...")) {
next();
a.push(new AST_Expansion({start: S.token, expression: expression(),end: S.token}));
} else {
a.push(expression(false));
}
@@ -1956,7 +1959,7 @@ function parse($TEXT, options) {
next();
args.push(new AST_Expansion({
start: prev(),
symbol: as_symbol(AST_SymbolFunarg)
expression: as_symbol(AST_SymbolFunarg)
}));
} else {
args.push(expression(false));

View File

@@ -227,4 +227,8 @@ TreeTransformer.prototype = new TreeWalker;
self.value = self.value.transform(tw);
});
_(AST_Expansion, function(self, tw){
self.expression = self.expression.transform(tw);
});
})();