Better parentheses check for arrow expression argument list.
This commit is contained in:
committed by
Marijn Haverbeke
parent
1f801001cf
commit
f7fe322490
20
acorn.js
20
acorn.js
@@ -226,6 +226,11 @@
|
||||
|
||||
var inFunction, labels, strict;
|
||||
|
||||
// This counter is used for checking that arrow expressions did
|
||||
// not contain nested parentheses in argument list.
|
||||
|
||||
var metParenL;
|
||||
|
||||
// This function is used to raise exceptions on parse errors. It
|
||||
// takes an offset integer (into the current `input`) to indicate
|
||||
// the location of the error, attaches the position to the end
|
||||
@@ -491,6 +496,7 @@
|
||||
tokCurLine = 1;
|
||||
tokPos = tokLineStart = 0;
|
||||
tokRegexpAllowed = true;
|
||||
metParenL = 0;
|
||||
skipSpace();
|
||||
}
|
||||
|
||||
@@ -1689,20 +1695,16 @@
|
||||
case _parenL:
|
||||
var node = startNode(), tokStartLoc1 = tokStartLoc, tokStart1 = tokStart, val;
|
||||
next();
|
||||
var oldParenL = ++metParenL;
|
||||
if (tokType !== _parenR) {
|
||||
val = parseExpression();
|
||||
}
|
||||
expect(_parenR);
|
||||
if (eat(_arrow)) {
|
||||
if (val) {
|
||||
var innerParenL = input.slice(val.start, val.end).indexOf('(');
|
||||
if (innerParenL >= 0) unexpected(val.start + innerParenL);
|
||||
}
|
||||
if (metParenL === oldParenL && eat(_arrow)) {
|
||||
val = parseArrowExpression(node, !val ? [] : val.type === "SequenceExpression" ? val.expressions : [val]);
|
||||
} else
|
||||
// disallow '()' before everything but error
|
||||
if (!val) {
|
||||
unexpected(tokPos - 1);
|
||||
} else {
|
||||
// disallow '()' before everything but error
|
||||
if (!val) unexpected(lastStart);
|
||||
}
|
||||
val.start = tokStart1;
|
||||
val.end = lastEnd;
|
||||
|
||||
@@ -15945,9 +15945,9 @@ testFail("import { foo, bar }", "Unexpected token (1:20)", {ecmaVersion: 6});
|
||||
|
||||
testFail("import foo from bar", "Unexpected token (1:20)", {ecmaVersion: 6});
|
||||
|
||||
testFail("((a)) => 42", "Unexpected token (1:1)", {ecmaVersion: 6});
|
||||
testFail("((a)) => 42", "Unexpected token (1:6)", {ecmaVersion: 6});
|
||||
|
||||
testFail("(a, (b)) => 42", "Unexpected token (1:4)", {ecmaVersion: 6});
|
||||
testFail("(a, (b)) => 42", "Unexpected token (1:9)", {ecmaVersion: 6});
|
||||
|
||||
testFail("\"use strict\"; (eval = 10) => 42", "Assigning to eval in strict mode (1:15)", {ecmaVersion: 6});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user