Skip to content

Commit

Permalink
Fix parsing error in exponent expressions with unary left-hand sides.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jogibear9988 committed Nov 2, 2021
1 parent 27ad334 commit 9d19795
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Esprima/JavascriptParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,10 +1860,14 @@ private Expression ParseUnaryExpression()

private Expression ParseExponentiationExpression()
{
var startToken = _lookahead;

var expr = InheritCoverGrammar(parseUnaryExpression);
if (expr.Type != Nodes.UnaryExpression && Match("**"))
var startToken = _lookahead;

var isLeftParenthesized = this.Match("(");
var expr = InheritCoverGrammar(parseUnaryExpression);

var exponentAllowed = expr.Type != Nodes.UnaryExpression || isLeftParenthesized;

if (exponentAllowed && Match("**"))
{
NextToken();
_context.IsAssignmentTarget = false;
Expand Down

0 comments on commit 9d19795

Please sign in to comment.