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
Open

Parsing error with unary and exponentiation operator #1981

stonegray opened this issue Jul 16, 2019 · 0 comments

Comments

@stonegray
Copy link

@stonegray stonegray commented Jul 16, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.