Skip to content

fix(parser): emit decimal bigint for zero-valued non-decimal literals in ESTree - #18203

Closed
contactjawad wants to merge 1 commit into
babel:mainfrom
contactjawad:fix-estree-bigint-zero-radix
Closed

contactjawad wants to merge 1 commit into
babel:mainfrom
contactjawad:fix-estree-bigint-zero-radix

Conversation

@contactjawad

Copy link
Copy Markdown

What

Fix the bigint field produced by the ESTree plugin for zero-valued BigInt literals written in a non-decimal radix (hex/octal/binary). 0x0n now yields bigint: "0" instead of "0x0".

Why

parseBigIntLiteral computed the field with:

node.bigint = String(node.value || value);

The || value fallback exists only for environments where the BigInt could not be constructed (node.value === null), in which case the raw source string is used. But 0n is falsy, so any zero-valued BigInt — regardless of radix — also fell through to the raw source string, which still carries the radix prefix. As a result 0x0n serialized to "0x0" while 0xFFn correctly serialized to "255", and the ESTree spec defines bigint as the string representation of the value in base 10.

How

Replace the falsy check with an explicit null check so real BigInt values (including 0n) always go through the decimal String(node.value) path, and only the unsupported-BigInt case uses the raw source string:

node.bigint = node.value == null ? value : String(node.value);

Test

Added two ESTree fixtures under test/fixtures/estree/bigInt/: hex-zero (0x0nbigint: "0", the regression) and hex-nonzero (0xFFnbigint: "255", showing consistency). The hex-zero fixture fails before the change ("0x0" != "0") and passes after.

… in ESTree

The ESTree plugin's parseBigIntLiteral used `String(node.value || value)`,
whose `|| value` fallback was meant only for the BigInt-unsupported case
(node.value === null). Because `0n` is falsy it also caught zero-valued
literals written in hex/octal/binary, so `0x0n` produced a radix-prefixed
`bigint` ("0x0") instead of the canonical decimal "0". Guard on
`node.value == null` instead so real BigInt values always serialize to decimal.
@github-actions

Copy link
Copy Markdown

❌ Automation signals

Activity patterns show signs of automation.

View full analysis →

This is an automated analysis by AgentScan

@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62034

@pkg-pr-new

pkg-pr-new Bot commented Aug 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: fc32d5f

@nicolo-ribaudo

Copy link
Copy Markdown
Member

This looks 100% LLM-generated, including the PR description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants