Skip to content

Commit 551a680

Browse files
committed
Fix the format of bigint property on bigint literal
FIX: Fix an issue where the `bigint` property of literal nodes for non-decimal bigints had the wrong format. Closes #1371
1 parent 24baa2a commit 551a680

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

acorn-loose/src/expression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ lp.parseExprAtom = function() {
271271
node = this.startNode()
272272
node.value = this.tok.value
273273
node.raw = this.input.slice(this.tok.start, this.tok.end)
274-
if (this.tok.type === tt.num && node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1).replace(/_/g, "")
274+
if (this.tok.type === tt.num && node.raw.charCodeAt(node.raw.length - 1) === 110)
275+
node.bigint = node.value != null ? node.value.toString() : node.raw.slice(0, -1).replace(/_/g, "")
275276
this.next()
276277
return this.finishNode(node, "Literal")
277278

acorn/src/expression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,8 @@ pp.parseLiteral = function(value) {
598598
let node = this.startNode()
599599
node.value = value
600600
node.raw = this.input.slice(this.start, this.end)
601-
if (node.raw.charCodeAt(node.raw.length - 1) === 110) node.bigint = node.raw.slice(0, -1).replace(/_/g, "")
601+
if (node.raw.charCodeAt(node.raw.length - 1) === 110)
602+
node.bigint = node.value != null ? node.value.toString() : node.raw.slice(0, -1).replace(/_/g, "")
602603
this.next()
603604
return this.finishNode(node, "Literal")
604605
}

test/tests-bigint.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ if (typeof exports !== "undefined") {
33
var testFail = require("./driver.js").testFail;
44
}
55

6-
const newBigIntLiteral = (start, stringValue) => ({
6+
const newBigIntLiteral = (start, stringValue, bigint = stringValue) => ({
77
start: start,
88
type: "Literal",
99
end: start + stringValue.length + 1,
1010
value: typeof BigInt !== "undefined" ? BigInt(stringValue) : null,
1111
raw: `${stringValue}n`,
12-
bigint: stringValue
12+
bigint
1313
})
1414

1515
const digits = [
1616
{d: "0", ast: start => newBigIntLiteral(start, "0")},
1717
{d: "2", ast: start => newBigIntLiteral(start, "2")},
18-
{d: "0x2", ast: start => newBigIntLiteral(start, "0x2")},
19-
{d: "0o2", ast: start => newBigIntLiteral(start, "0o2")},
20-
{d: "0b10", ast: start => newBigIntLiteral(start, "0b10")},
18+
{d: "0x2", ast: start => newBigIntLiteral(start, "0x2", "2")},
19+
{d: "0o2", ast: start => newBigIntLiteral(start, "0o2", "2")},
20+
{d: "0b10", ast: start => newBigIntLiteral(start, "0b10", "2")},
2121
{d: "-0xbf2ed51ff75d380fd3be813ec6185780", ast: start => ({
2222
start: start,
2323
type: "UnaryExpression",
2424
end: start + 36,
2525
operator: "-",
2626
prefix: true,
27-
argument: newBigIntLiteral(start + 1, "0xbf2ed51ff75d380fd3be813ec6185780")
27+
argument: newBigIntLiteral(start + 1, "0xbf2ed51ff75d380fd3be813ec6185780", "254125715536285641815112686497309415296")
2828
})},
2929
{d: "02", error: start => `Identifier directly after number (1:${start + 2})`},
3030
{d: "2e2", error: start => `Identifier directly after number (1:${start + 3})`},

0 commit comments

Comments
 (0)