Skip to content

Commit 9d19795

Browse files
committed
Fix parsing error in exponent expressions with unary left-hand sides.
Esprima (correctly) rejects expressions like -1**2. - jquery/esprima#2070 However, expressions like (-1)**2 are valid but still rejected. This commit fixes this issue by identifying when the left operand is parenthesized. Fixes jquery/esprima#1981
1 parent 27ad334 commit 9d19795

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Esprima/JavascriptParser.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,14 @@ private Expression ParseUnaryExpression()
18601860

18611861
private Expression ParseExponentiationExpression()
18621862
{
1863-
var startToken = _lookahead;
1864-
1865-
var expr = InheritCoverGrammar(parseUnaryExpression);
1866-
if (expr.Type != Nodes.UnaryExpression && Match("**"))
1863+
var startToken = _lookahead;
1864+
1865+
var isLeftParenthesized = this.Match("(");
1866+
var expr = InheritCoverGrammar(parseUnaryExpression);
1867+
1868+
var exponentAllowed = expr.Type != Nodes.UnaryExpression || isLeftParenthesized;
1869+
1870+
if (exponentAllowed && Match("**"))
18671871
{
18681872
NextToken();
18691873
_context.IsAssignmentTarget = false;

0 commit comments

Comments
 (0)