Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(react-compiler): preserve BigInt literals in compiled output - #26587

Open
Ranjeet2063 wants to merge 1 commit into
oxc-project:mainfrom
Ranjeet2063:fix/react-compiler-bigint-literal
Open

fix(react-compiler): preserve BigInt literals in compiled output#26587
Ranjeet2063 wants to merge 1 commit into
oxc-project:mainfrom
Ranjeet2063:fix/react-compiler-bigint-literal

Conversation

@Ranjeet2063

Copy link
Copy Markdown

Summary

Fixes #26161.

In crates/oxc_react_compiler, lower_expression did not match oxc::Expression::BigIntLiteral. Because of the missing arm, BigInt literals (such as 1n, 100n, 0n) fell through to the unported fallback arm and were lowered to InstructionValue::Primitive { value: PrimitiveValue::Undefined, span }. As a result, code like <div>{String(1n)}</div> was incorrectly transformed to <div>{String(undefined)}</div>.

Changes

  1. react_compiler_hir:

    • Added PrimitiveValue::BigInt { value: Str<'a>, raw: Option<Str<'a>>, base: BigintBase }.
    • Derives Debug, Clone, Copy, PartialEq, Eq, Hash.
  2. react_compiler_lowering/build_hir.rs:

    • Added oxc::Expression::BigIntLiteral(lit) match arm in lower_expression, lowering AST BigInt literals to PrimitiveValue::BigInt.
    • Removed unreachable _ => wildcard arm from lower_expression so that match expr is now completely exhaustive across all oxc::Expression AST variants.
  3. react_compiler_reactive_scopes/codegen_reactive_function.rs:

    • Added PrimitiveValue::BigInt arm in ox_codegen_primitive_value, reconstructing oxc_ast::ast::Expression::new_big_int_literal preserving value, raw representation, and base.
  4. react_compiler_optimization/constant_propagation.rs:

    • Handled BigInt truthiness in is_truthy (value.as_str() != "0" && !value.as_str().is_empty()).
    • Added BigInt equality in js_strict_equal and js_abstract_equal.
    • Supported BigInt interpolation in template literal constant propagation.
    • Handled BigInt in property load/store pattern matches.
  5. Tests:

    • Added crates/oxc_react_compiler/fixtures/bigint-literal.js and verified golden snapshot in bigint-literal.snap.

Verification

  • cargo fmt --check passes cleanly.
  • cargo clippy -p oxc_react_compiler -- -D warnings passes with 0 warnings.
  • cargo test -p oxc_react_compiler passes all 44 unit, snapshot, and transform tests.

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
@Ranjeet2063
Ranjeet2063 requested a review from Boshen as a code owner September 12, 2026 22:54
Copilot AI lite review requested due to automatic review settings September 12, 2026 22:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@camc314 camc314 added the A-react-compiler Area - React Compiler label Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-react-compiler Area - React Compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

react-compiler: BigInt literals are compiled to undefined

3 participants