From 9eb65f3af36fd6546f83517f217625fdbaf9d6f1 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 7 Dec 2020 02:07:34 +0000 Subject: extend trailing comma support (#4334) --- lib/parse.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/parse.js b/lib/parse.js index b3c3f977..5a07ef64 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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); -- cgit v1.2.3