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'
}
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 codePass code
that passes.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:Full stack:
Relevant references