expand parameters
Conflicts: test/compress/harmony.js
This commit is contained in:
committed by
Richard van Velzen
parent
e8664e63ef
commit
9863f0efa3
26
lib/ast.js
26
lib/ast.js
@@ -363,10 +363,27 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||
}
|
||||
}, AST_Scope);
|
||||
|
||||
// TODO besides parameters and function calls, expansions can go in
|
||||
// arrays, array destructuring parameters, and array destructuring
|
||||
// assignment. But I'm not adding this right now because I'm trying
|
||||
// to do the most minimal and independent changesets.
|
||||
var AST_Expansion = DEFNODE("AST_Expansion", "symbol", {
|
||||
$documentation: "An expandible argument, such as ...rest",
|
||||
$propdoc: {
|
||||
symbol: "AST_SymbolFunarg the name of the argument as a SymbolFunarg"
|
||||
},
|
||||
_walk: function(visitor) {
|
||||
var self = this;
|
||||
return visitor._visit(this, function(){
|
||||
self.symbol.walk(visitor);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var AST_ArrowParametersOrSeq = DEFNODE("ArrowParametersOrSeq", "expressions", {
|
||||
$documentation: "A set of arrow function parameters or a sequence expression. This is used because when the parser sees a \"(\" it could be the start of a seq, or the start of a parameter list of an arrow function.",
|
||||
$propdoc: {
|
||||
expressions: "[AST_Expression|AST_Destructuring*] array of expressions or argument names or destructurings."
|
||||
expressions: "[AST_Expression|AST_Destructuring|AST_Expansion*] array of expressions or argument names or destructurings."
|
||||
},
|
||||
as_params: function (croak) {
|
||||
// We don't want anything which doesn't belong in a destructuring
|
||||
@@ -398,6 +415,8 @@ var AST_ArrowParametersOrSeq = DEFNODE("ArrowParametersOrSeq", "expressions", {
|
||||
start: ex.start,
|
||||
end: ex.end
|
||||
});
|
||||
} else if (ex instanceof AST_Expansion) {
|
||||
return ex;
|
||||
} else if (ex instanceof AST_Array) {
|
||||
if (ex.elements.length === 0)
|
||||
croak("Invalid destructuring function parameter", ex.start.line, ex.start.col);
|
||||
@@ -421,7 +440,7 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
||||
$documentation: "Base class for functions",
|
||||
$propdoc: {
|
||||
name: "[AST_SymbolDeclaration?] the name of this function",
|
||||
argnames: "[AST_SymbolFunarg|AST_Destructuring*] array of function arguments or destructurings",
|
||||
argnames: "[AST_SymbolFunarg|AST_Destructuring|AST_Expansion*] array of function arguments, destructurings, or expanding arguments",
|
||||
uses_arguments: "[boolean/S] tells whether this function accesses the arguments array"
|
||||
},
|
||||
args_as_names: function () {
|
||||
@@ -431,6 +450,9 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
|
||||
if (parm instanceof AST_SymbolFunarg) {
|
||||
out.push(parm);
|
||||
}
|
||||
if (parm instanceof AST_Expansion) {
|
||||
out.push(parm.symbol);
|
||||
}
|
||||
}));
|
||||
return out;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user