fix(react-compiler): preserve BigInt literals in compiled output - #26587
Open
Ranjeet2063 wants to merge 1 commit into
Open
fix(react-compiler): preserve BigInt literals in compiled output#26587Ranjeet2063 wants to merge 1 commit into
Ranjeet2063 wants to merge 1 commit into
Conversation
BigInt literals in component and hook bodies were previously lowered to `PrimitiveValue::Undefined` due to a missing match arm in `lower_expression`. This commit adds `PrimitiveValue::BigInt`: - Lowers `oxc::Expression::BigIntLiteral` to `PrimitiveValue::BigInt` - Emits proper `Expression::BigIntLiteral` during codegen - Handles BigInt truthiness and equality in constant propagation - Adds integration fixture and snapshot test Fixes oxc-project#26161
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.
Summary
Fixes #26161.
In
crates/oxc_react_compiler,lower_expressiondid not matchoxc::Expression::BigIntLiteral. Because of the missing arm, BigInt literals (such as1n,100n,0n) fell through to the unported fallback arm and were lowered toInstructionValue::Primitive { value: PrimitiveValue::Undefined, span }. As a result, code like<div>{String(1n)}</div>was incorrectly transformed to<div>{String(undefined)}</div>.Changes
react_compiler_hir:PrimitiveValue::BigInt { value: Str<'a>, raw: Option<Str<'a>>, base: BigintBase }.Debug, Clone, Copy, PartialEq, Eq, Hash.react_compiler_lowering/build_hir.rs:oxc::Expression::BigIntLiteral(lit)match arm inlower_expression, lowering AST BigInt literals toPrimitiveValue::BigInt._ =>wildcard arm fromlower_expressionso thatmatch expris now completely exhaustive across alloxc::ExpressionAST variants.react_compiler_reactive_scopes/codegen_reactive_function.rs:PrimitiveValue::BigIntarm inox_codegen_primitive_value, reconstructingoxc_ast::ast::Expression::new_big_int_literalpreserving value, raw representation, and base.react_compiler_optimization/constant_propagation.rs:is_truthy(value.as_str() != "0" && !value.as_str().is_empty()).js_strict_equalandjs_abstract_equal.Tests:
crates/oxc_react_compiler/fixtures/bigint-literal.jsand verified golden snapshot inbigint-literal.snap.Verification
cargo fmt --checkpasses cleanly.cargo clippy -p oxc_react_compiler -- -D warningspasses with 0 warnings.cargo test -p oxc_react_compilerpasses all 44 unit, snapshot, and transform tests.