This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Rust port of Meta's babel-plugin-react-compiler built on the OXC toolchain. The goal is exact behavioral parity with the upstream TypeScript implementation. Codegen uses OXC AST-based code generation via the codegen_backend/ module.
The upstream reference lives at third_party/react/compiler/packages/babel-plugin-react-compiler/.
# Build everything
cargo build
# Build release (needed for conformance perf)
cargo build --release
# Run core crate unit tests
cargo test --package oxc_react_compiler
# Run a single unit test
cargo test --package oxc_react_compiler -- test_name
# Run conformance suite (the primary correctness metric)
cargo run --release --bin conformance -- --update --verbose
# Conformance with filter (run specific fixtures)
cargo run --release --bin conformance -- --filter "fixture-name-pattern"
# Conformance with diff output for failures
cargo run --release --bin conformance -- --diff
# Near-miss analysis (find almost-passing fixtures)
cargo run --release --bin conformance -- --near-miss
# Show full actual vs expected for failures
cargo run --release --bin conformance -- --show- Fixtures live in
third_party/react/compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/ - Each fixture is a
.js/.ts/.tsxfile paired with a.expect.mdcontaining expected output --updaterewrites the snapshot file attasks/conformance/snapshots/react_compiler.snap.md- Results have Β±1-2 non-determinism due to Rayon parallel execution and hashmap ordering
- The conformance runner's normalization layer compensates for cosmetic differences between OXC AST codegen and Babel output
Defined in pipeline.rs, this mirrors upstream's Pipeline.ts:
- HIR Construction β OXC AST β CFG-based HIR (
hir/build.rs) - HIR Pre-processing β prune_maybe_throws, drop_manual_memoization, inline_iifes, merge_consecutive_blocks
- SSA + Analysis β enter_ssa, eliminate_redundant_phi, constant_propagation, infer_types
- Mutation/Aliasing β analyse_functions, infer_mutation_aliasing_effects, dead_code_elimination
- Validation β hooks usage, ref access, setState-in-render, etc.
- Reactive Scope Construction β infer reactive places, build scope terminals, flatten loops/hooks, propagate dependencies
- Reactive Function + Codegen β build_reactive_function (CFG β tree IR), scope alignment/merging/pruning, codegen_backend (emit JS via OXC AST)
Source β oxc_parser β OXC AST
β oxc_semantic + hir::build β HIR (CFG with BasicBlocks, Terminals, Instructions)
β SSA passes β HIR in SSA form
β Aliasing analysis β HIR with mutation ranges
β Reactive scope inference β HIR with ReactiveScope annotations
β build_reactive_function β ReactiveFunction (tree-shaped IR)
β codegen_backend β JavaScript output with memoization
- HIRFunction β function lowered to CFG form (blocks, terminals, phis)
- BasicBlock β instructions + terminal (Goto, If, For, Return, etc.)
- Instruction β single operation with lvalue (Place) and value (InstructionValue enum)
- Place β identifier + effect (Read, Mutate, Freeze, etc.) + reactive flag
- ReactiveFunction β tree-shaped IR for codegen (ReactiveBlock β Vec)
- ReactiveScope β memoized scope with dependencies, declarations, and cache slot info
| Module | Responsibility |
|---|---|
hir/build.rs |
Lowers OXC AST β HIR CFG (largest file) |
hir/types.rs |
All IR data structures |
hir/globals.rs |
Known global function/type database |
hir/propagate_scope_dependencies_hir.rs |
Scope dependency computation |
hir/collect_hoistable_property_loads.rs |
Hoistable property analysis |
pipeline.rs |
Pass orchestration (second largest file) |
codegen_backend/codegen_ast.rs |
OXC AST-based codegen (ReactiveFunction β OXC AST) |
codegen_backend/module_emitter/ |
Module-level emission (directory module with 7 submodules) |
codegen_backend/hir_to_ast.rs |
HIR instruction β OXC AST conversion |
reactive_scopes/build_reactive_function.rs |
HIR CFG β tree-shaped ReactiveFunction |
optimization/constant_propagation.rs |
SSA constant folding |
optimization/dead_code_elimination.rs |
DCE pass |
inference/infer_mutation_aliasing_effects.rs |
Aliasing side-effect analysis |
options.rs |
PluginOptions, EnvironmentConfig, CompilationMode |
crates/oxc_react_compiler/β Core compiler (the main crate)crates/oxc_react_compiler_napi/β N-API bindings exposingtransform(filename, source, options?)to Node.jsnapi/β Published JS wrapper + Vite v8 plugin (vite.js)tasks/conformance/β Conformance test runner binary
Single entry point: oxc_react_compiler::compile(filename, source, options) -> CompileResult
Returns { transformed: bool, code: String, map: Option<String> }.
Each Rust module corresponds to an upstream TypeScript file. When debugging a pass, compare against the upstream source in third_party/react/compiler/packages/babel-plugin-react-compiler/src/. Key mappings:
pipeline.rsβEntrypoint/Pipeline.tshir/build.rsβHIR/BuildHIR.tshir/types.rsβHIR/HIR.tscodegen_backend/codegen_ast.rsβReactiveScopes/CodegenReactiveFunction.tsreactive_scopes/build_reactive_function.rsβReactiveScopes/BuildReactiveFunction.tsoptimization/constant_propagation.rsβOptimization/ConstantPropagation.ts
- Rust edition 2024, OXC v0.122.0
- All internal modules use
pub(crate)visibility; onlycompile()andoptionsare public - Flow syntax preprocessing is an inline function (
preprocess_flow_syntax) inpipeline.rs(Rust-specific; Babel parses Flow natively) - Fixture pragmas (first line comments like
// @flow,// @compilationMode "all") control per-fixture compiler options - The conformance runner's normalization layer compensates for cosmetic differences (whitespace, semicolons, trailing commas) between OXC AST codegen and Babel output
Before committing or when implementation is complete, always run formatting and linting:
# Format all code
cargo fmt --all
# Lint with all warnings as errors
cargo clippy --workspace --all-features --all-targets -- -D warnings