Parsing error with unary and exponentiation operator
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 772
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the require('esprima').parse entry point and reproduce (+2)**4, (-2)**4, and (1+2)**4. Compare the parser behavior with the linked ECMAScript unary-plus and exponentiation references; done means these valid expressions parse consistently without the reported unexpected-token error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100