BLOCKED - BigInt literals fail - Error: Line 37: Unexpected token ILLEGAL
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.1k
- Forks
- 773
- PR merge metrics
- No merged PRs in 30d
Description
BigInt literals like 1n, 10n fail.
However, BigInt(1), BigInt(10) pass.
Steps to reproduce
Below are both Fail code that throws the error, and converted code Pass code that passes.
// Fail code
function factorial(n) {
return n !== 1n ? n * factorial(n - 1n) : 1n;
}
// Pass code
function factorial(n) {
return n !== BigInt(1) ? n * factorial(n - BigInt(1)) : n;
}
Expected output
Fail code should pass.
Changing all "1n" to "BigInt(1)" is frustrating, mainly not feasible to do in a project.
Actual output
BigInt literals like 1n, 10n fail throws below error:
Error: Line 37: Unexpected token ILLEGAL
Full stack:
\node_modules\esprima\dist\esprima.js:5035
throw this.createError(index, line, col, description);
^
Error: Line 37: Unexpected token ILLEGAL
at ErrorHandler.constructError (\node_modules\esprima\dist\esprima.js:5012:22)
at ErrorHandler.createError (\node_modules\esprima\dist\esprima.js:5028:27)
at ErrorHandler.throwError (\node_modules\esprima\dist\esprima.js:5035:21)
at Scanner.throwUnexpectedToken (\node_modules\esprima\dist\esprima.js:5164:35)
at Scanner.scanNumericLiteral (\node_modules\esprima\dist\esprima.js:5837:19)
at Scanner.lex (\node_modules\esprima\dist\esprima.js:6251:26)
at Parser.nextToken (\node_modules\esprima\dist\esprima.js:2079:34)
at Parser.parseBinaryExpression (\node_modules\esprima\dist\esprima.js:3093:19)
at Parser.inheritCoverGrammar (\node_modules\esprima\dist\esprima.js:2285:37)
at Parser.parseConditionalExpression (\node_modules\esprima\dist\esprima.js:3141:26) {
index: 1224,
lineNumber: 37,
description: 'Unexpected token ILLEGAL'
}
Relevant references
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
Reproduce the failure with the BigInt literal examples and start at Scanner.scanNumericLiteral in node_modules/esprima/dist/esprima.js, following the parser path shown in the stack trace. Done means the 1n and 10n forms parse successfully without requiring BigInt(...), with the existing factorial example serving as the regression case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100