aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-07 02:07:34 +0000
committerGitHub <noreply@github.com>2020-12-07 10:07:34 +0800
commit9eb65f3af36fd6546f83517f217625fdbaf9d6f1 (patch)
tree52e9a6c08fdb4d0add68eeed311f11d0c1b26ed0 /lib
parent2cbbf5c375a0fae88345c3ed3bc2829b4b1ac250 (diff)
downloadtracifyjs-9eb65f3af36fd6546f83517f217625fdbaf9d6f1.tar.gz
tracifyjs-9eb65f3af36fd6546f83517f217625fdbaf9d6f1.zip
extend trailing comma support (#4334)
Diffstat (limited to 'lib')
-rw-r--r--lib/parse.js17
1 files changed, 7 insertions, 10 deletions
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);