Improve binding patterns for arrow functions

This commit is contained in:
Anthony Van de Gejuchte
2016-09-07 01:00:07 +02:00
committed by Richard van Velzen
parent 947b8750e8
commit 32c2cc33bb
12 changed files with 243 additions and 54 deletions

View File

@@ -1232,6 +1232,10 @@ function parse($TEXT, options) {
};
var arrow_function = function(args) {
if (S.token.nlb) {
croak("SyntaxError: Unexpected newline before arrow (=>)");
}
expect_token("arrow", "=>");
var argnames;
@@ -1425,12 +1429,13 @@ function parse($TEXT, options) {
if (is("punc")) {
switch (S.token.value) {
case ",":
case "]": // Last element
elements.push(new AST_Hole({
start: S.token,
end: S.token
}));
continue;
case "]": // Trailing comma after last element
break;
case "[":
case "{":
elements.push(binding_element(used_parameters, symbol_type));
@@ -1560,7 +1565,7 @@ function parse($TEXT, options) {
next();
a.push(new AST_Expansion({
start: prev(),
expression: as_symbol(AST_SymbolFunarg),
expression: binding_element(undefined, AST_SymbolFunarg),
end: S.token,
}));
if (!is("punc", ")")) {
@@ -2011,15 +2016,13 @@ function parse($TEXT, options) {
// It's one of those object destructurings, the value is its own name
a.push(new AST_ObjectKeyVal({
start: start,
quote: start.quote,
end: start,
key: name,
value: new AST_SymbolRef({
start: start,
end: start,
end: prev(),
name: name
}),
shorthand: true,
end: start,
}));
} else {
expect(":");