fix(parser): emit decimal bigint for zero-valued non-decimal literals in ESTree - #18203
Closed
contactjawad wants to merge 1 commit into
Closed
contactjawad wants to merge 1 commit into
contactjawad wants to merge 1 commit into
Conversation
… 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.
❌ Automation signalsActivity patterns show signs of automation. This is an automated analysis by AgentScan |
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/62034 |
|
commit: |
Member
|
This looks 100% LLM-generated, including the PR description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix the
bigintfield produced by the ESTree plugin for zero-valued BigInt literals written in a non-decimal radix (hex/octal/binary).0x0nnow yieldsbigint: "0"instead of"0x0".Why
parseBigIntLiteralcomputed the field with:The
|| valuefallback exists only for environments where the BigInt could not be constructed (node.value === null), in which case the raw source string is used. But0nis 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 result0x0nserialized to"0x0"while0xFFncorrectly serialized to"255", and the ESTree spec definesbigintas 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 decimalString(node.value)path, and only the unsupported-BigInt case uses the raw source string:Test
Added two ESTree fixtures under
test/fixtures/estree/bigInt/:hex-zero(0x0n→bigint: "0", the regression) andhex-nonzero(0xFFn→bigint: "255", showing consistency). Thehex-zerofixture fails before the change ("0x0" != "0") and passes after.