jquery / esprima

ECMAScript parsing infrastructure for multipurpose analysis
http://esprima.org
BSD 2-Clause "Simplified" License
7.04k stars 786 forks source link

Unexpected token ** when left operand is parenthesized unary expression #2069

Closed luiscubal closed 3 years ago

luiscubal commented 3 years ago

Steps to reproduce

Parse the following code:

esprima.parse('(-1) ** 2')

Expected output

The expression (-1) ** 2 is accepted by mainstream browsers as valid and I believe that Esprima should accept it as well.

Actual output

Esprima fails with the following error:

> esprima.parse('(-1)**2')
Uncaught Error: Line 1: Unexpected token **
<stack trace>

Relevant references

The reason for Esprima's failure is that it identifies "(-1) 2" as "-1 2" which is indeed invalid.

luiscubal commented 3 years ago

Nevermind, I think this is a duplicate of https://github.com/jquery/esprima/issues/1981