extend trailing comma support (#4334)

This commit is contained in:
Alex Lam S.L
2020-12-07 02:07:34 +00:00
committed by GitHub
parent 2cbbf5c375
commit 9eb65f3af3
3 changed files with 38 additions and 24 deletions

View File

@@ -1053,12 +1053,9 @@ function parse($TEXT, options) {
if (name && ctor !== AST_Accessor && !(name instanceof AST_SymbolDeclaration))
unexpected(prev());
expect("(");
var argnames = [];
for (var first = true; !is("punc", ")");) {
if (first) first = false; else expect(",");
argnames.push(maybe_destructured(AST_SymbolFunarg));
}
next();
var argnames = expr_list(")", !options.strict, false, function() {
return maybe_destructured(AST_SymbolFunarg);
});
var loop = S.in_loop;
var labels = S.labels;
++S.in_function;
@@ -1233,7 +1230,7 @@ function parse($TEXT, options) {
var newexp = expr_atom(false), args;
if (is("punc", "(")) {
next();
args = expr_list(")");
args = expr_list(")", !options.strict);
} else {
args = [];
}
@@ -1351,9 +1348,9 @@ function parse($TEXT, options) {
while (!is("punc", closing)) {
if (first) first = false; else expect(",");
if (allow_trailing_comma && is("punc", closing)) break;
if (is("punc", ",") && allow_empty) {
if (allow_empty && is("punc", ",")) {
a.push(new AST_Hole({ start: S.token, end: S.token }));
} else if (is("operator", "...") && parser === expression) {
} else if (parser === expression && is("operator", "...")) {
a.push(new AST_Spread({
start: S.token,
expression: (next(), parser()),
@@ -1593,7 +1590,7 @@ function parse($TEXT, options) {
var call = new AST_Call({
start : start,
expression : expr,
args : expr_list(")"),
args : expr_list(")", !options.strict),
end : prev()
});
mark_pure(call);