Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error with unary and exponentiation operator #1981

Open
stonegray opened this issue Jul 16, 2019 · 0 comments · Fixed by sebastienros/esprima-dotnet#201 · May be fixed by #2070
Open

Parsing error with unary and exponentiation operator #1981

stonegray opened this issue Jul 16, 2019 · 0 comments · Fixed by sebastienros/esprima-dotnet#201 · May be fixed by #2070

Comments

@stonegray
Copy link

Esprima does not seem to correctly parse the following code.

Steps to reproduce

require('esprima').parse('(+2)**4');

Actual output


/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:1995
	        throw this.unexpectedTokenError(token, message);
	        ^
Error: Line 1: Unexpected token **
    at ErrorHandler.constructError (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:5012:22)
    at ErrorHandler.createError (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:5028:27)
    at Parser.unexpectedTokenError (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:1985:39)
    at Parser.throwUnexpectedToken (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:1995:21)
    at Parser.consumeSemicolon (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:2297:23)
    at Parser.parseExpressionStatement (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:3649:15)
    at Parser.parseStatement (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:4112:39)
    at Parser.parseStatementListItem (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:3393:31)
    at Parser.parseScript (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:4723:29)
    at Object.parse (/Volumes/User/.npm-packages/lib/node_modules/esprima/dist/esprima.js:122:61) {
  index: 4,
  lineNumber: 1,
  description: 'Unexpected token **'
}


The error does not occur for 2**(+4), so it appears to be specific to the base.

The error does not occur for (1+2)**4, so it appears to be specific to the unary operator.

The same error does occur for the following similar expressions: (-2)**4, (~~2)**4

Relevant references

Unary operator: 12.5.6.1

Exponentiation operator: 12.6.4

luiscubal added a commit to luiscubal/esprima that referenced this issue Mar 8, 2021
Esprima (correctly) rejects expressions like -1**2.
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#1981
jogibear9988 added a commit to jogibear9988/esprima-dotnet that referenced this issue Nov 1, 2021
Esprima (correctly) rejects expressions like -1**2.
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
jogibear9988 added a commit to jogibear9988/esprima-dotnet that referenced this issue Nov 2, 2021
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
lahma pushed a commit to sebastienros/esprima-dotnet that referenced this issue Nov 2, 2021
…201)

* 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

* add test for unary left side
JohnWinston329 added a commit to JohnWinston329/esprima-dotnet that referenced this issue Dec 28, 2023
…(#201)

* 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

* add test for unary left side
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant