Improve binding patterns for arrow functions
This commit is contained in:
committed by
Richard van Velzen
parent
947b8750e8
commit
32c2cc33bb
15
lib/parse.js
15
lib/parse.js
@@ -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(":");
|
||||
|
||||
Reference in New Issue
Block a user