### 💥 BREAKING CHANGES -365274epackages/codegen: [**BREAKING**] `printSync` return an object (#25720) (overlookmotel) ### 🚀 Features -6a7eb60packages/codegen: Alter capitalization of `sourceFilename` option (#25854) (overlookmotel) -300763fpackages/codegen: Add full source map support (#25585) (camc314) -a169e4anapi/minify: Expose property name mangling options (#24741) (Dunqing) -2f5cdb1minifier: Add property name mangling (#24740) (Dunqing) -4922141mangler: Deduplicate private accessor names (#25601) (camc314) -1c4f519napi: Add Relay transform plugin (#25503) (Boshen) -a4478e9codegen: Add `oxc-codegen` package (#25488) (overlookmotel) ### 🐛 Bug Fixes -0fbcf64codegen: Validate sourcemap options (#25860) (camc314) -345f981react_compiler: Skip node_modules by default (#25859) (Boshen) -ab81f3fminifier: Drop side-effect-free additions (#25639) (Dunqing) -241c559napi/minify: Accept RegExp for property filters (#25827) (Dunqing) -4cc7ea4codegen: Reject invalid indent options (#25807) (camc314) -53f9295isolated-declarations: Preserve undefined for defaulted any (#25292) (camc314) -8ab883acodegen: Preserve property key annotations (#25766) (Dunqing) -b13fd48minifier: Model uninitialized module vars as undefined (#25497) (Dunqing) -f6000acecmascript: Fold `**` with `Number::exponentiate`, not IEEE `pow` (#25644) (Kotaro Chikuba) -b846abcisolated-declarations: Handle ambient expando properties (#25655) (camc314) -dec0a86react-compiler: Standardize diagnostics (#25702) (Boshen) -fca2e0cparser: Reject initialized lexical declarations in for-in (#25700) (Boshen) -ae9be8fparser: Forbid type parameters on quoted constructors (#25696) (Boshen) -c5f188areact-compiler: Use Babel v1 validation defaults (#25676) (Boshen) -db44651napi: Disable reuseWorker in browser bindings (#25640) (leaysgur) -ce35d47react_compiler: Preserve JSX import source pragmas (#25592) (Boshen) -059784dsemantic: Respect shadowed `Infinity` and `NaN` in enum evaluation (#25604) (camc314) -bb5a232minifier: Keep variable declaration initilized with class when keepNames is enabled (#25584) (sapphi-red) -f49229dminifier: Keep side effects when rotating bitwise operands (#25596) (Kotaro Chikuba) -e82495becmascript: Derive `ToNumber` of `!x` from `ToBoolean` (#25595) (Kotaro Chikuba) -509931bsemantic: Classify global references per identifier (#25608) (camc314) -80484cemangler: Correct base54 safety comment (#25606) (camc314) -c1369a7codegen: Resolve private names in class heritage (#25588) (camc314) -c002f29codegen: Escape sources for empty import specifiers (#25586) (camc314) -0c68b7festree: Emit `decorators` on `FormalParameterRest` (#25582) (camc314) -cdf1846semantic: Allow legacy escapes in JSX attributes (#25576) (Boshen) -e75e102minifier: Preserve block statement in labeled iteration statements (#25162) (Armano) -771d79amangler: Exclude non-manglable symbols from slot assignment (#25539) (sapphi-red) -76b19f5minifier: Avoid duplicating large folded strings (#25532) (Dunqing) -59e8895codegen: Validate starting indent level (#25550) (camc314) -88b34f2clippy: Remove unneeded `unsafe` (#25551) (camc314) -23a7ad0parser: Stop delimited lists at end of file (#25542) (Boshen) -73acba9parser: Preserve fatal errors during await reparse (#25541) (Boshen) -c3e99d1minifier: Avoid invalid octal escapes in template folds (#25495) (Dunqing) -b4e6a9ecodegen: Output newline after `export default interface` (#25487) (overlookmotel) -5fcf683minifier: Correct issue with try finally termination (#25185) (Armano) -1645d93react_compiler: Preserve source spans (#25462) (Boshen) -8d7f9cfreact_compiler: Honor eslint suppressions (#25394) (Boshen) ### ⚡ Performance -568203eecmascript: Use binary search for known globals (#25817) (Boshen) -c84ede3estree_tokens: Share JS token update entry point (#25826) (Boshen) - 9a6e862 minifier: Move owned statements directly (#25835) (Dunqing) -61b2aefminifier: Move owned AST nodes directly (#25837) (Dunqing) -673b04bminifier: Replace expressions without take_in dummies (#25836) (Dunqing) -63ff8eflinter: Outline diagnostic construction (#25762) (Boshen) -621808ediagnostics: Measure graphemes lazily (#25723) (Boshen) -f62ed0ediagnostics: Optimize graphical number rendering (#25715) (Boshen) -7152834diagnostics: Reduce graphical formatting overhead (#25714) (Boshen) -10fc4b7diagnostics: Reduce graphical rendering allocations (#25711) (Boshen) -9c8ababdiagnostics: Batch graphical reports (#25710) (Boshen) -757f3d4mangler: Share allocated names across reused slots (#25605) (camc314) -5444cbfcodegen: Skip escaping harmless `<` tokens (#25564) (camc314) ### 📚 Documentation -58f7ab9packages/codegen: Reformat docs and comments (#25848) (overlookmotel) -627466etransform-react: Document all options (#25800) (Boshen) -ce03ac1packages/codegen: Fix JSDoc comments for `printSync` (#25722) (overlookmotel) -386a699packages/codegen: Correct JSDoc comment (#25716) (overlookmotel) -31e571dmangler: Update code example (#25599) (camc314) -fd62354codegen: Revamp package readme (#25560) (camc314) -ffa3153codegen: Clarify raw transfer Node requirement (#25565) (camc314) -c5d4063codegen: Clarify binary walk allocations (#25562) (camc314) -5703d7acodegen: Correct stale printer comments (#25561) (camc314) Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Oxc Transform React
Native Node.js bindings for Oxc's React transform pipeline. It combines:
- Oxc's experimental Rust port of React Compiler
- TypeScript syntax removal
- JSX transformation with automatic and classic runtimes
- React Fast Refresh
- These transforms can also be run individually
React Compiler runs first, then Oxc removes TypeScript syntax and applies the configured JSX and Fast Refresh transforms.
This package and Oxc's React Compiler port are experimental. Review generated output before using it in production.
Usage
import { transformSync } from "oxc-transform-react";
const result = transformSync(
"Component.tsx",
`
export function Component({ name }: { name: string }) {
return <div>Hello {name}</div>;
}
`,
);
if (result.fatal) {
console.error(result.errors);
} else {
console.log(result.code);
}
React Compiler is enabled by default with a React 19 target, and JSX uses the
automatic runtime. Enable React Fast Refresh with jsx.refresh. The filename
determines whether the input is parsed as JavaScript, JSX, TypeScript, or TSX.
API
transformSync(
filename: string,
sourceText: string,
options?: TransformOptions,
): TransformResult;
transform(
filename: string,
sourceText: string,
options?: TransformOptions,
): Promise<TransformResult>;
The asynchronous transform runs on a worker-pool thread. It is useful when
processing files concurrently, but can be slower for a single small file.
TransformResult contains code, an optional source map, errors, and a
fatal flag. Recoverable React Compiler bail-outs appear in errors as
warnings while still producing code, so use fatal to determine whether the
output is usable.
Options
All options are optional. Defaults in the tables below apply when a property is omitted.
Transform options
| Option | Type | Default | Description |
|---|---|---|---|
lang |
string |
Inferred from filename | Parse as "js", "jsx", "ts", "tsx", or "dts". |
sourceType |
string |
Inferred | Parse as "script", "module", "commonjs", or "unambiguous". |
sourcemap |
boolean |
false |
Generate a source map in result.map. |
jsx |
"preserve" or JsxOptions |
Automatic runtime | Configure the JSX transform. Set to "preserve" to leave JSX syntax in the output. |
reactCompiler |
boolean or ReactCompilerOptions |
true |
Configure React Compiler. Set to false to disable it or true to enable it with the default options. |
JSX options
| Option | Type | Default | Description |
|---|---|---|---|
runtime |
"classic" or "automatic" |
"automatic" |
Select the JSX runtime. The automatic runtime imports JSX factories; the classic one does not. |
development |
boolean |
false |
Emit development information such as __source and __self. |
throwIfNamespace |
boolean |
true |
Report an error for XML namespace syntax such as <svg:path>. |
pure |
boolean |
true |
Add pure annotations to JSX and top-level React calls for tree shaking. |
importSource |
string |
"react" |
Set the package imported by the automatic runtime. |
pragma |
string |
"React.createElement" |
Set the JSX factory used by the classic runtime. |
pragmaFrag |
string |
"React.Fragment" |
Set the JSX fragment used by the classic runtime. |
refresh |
boolean or ReactRefreshOptions |
false |
Enable React Fast Refresh, optionally with custom identifiers and signature output. |
refresh: true uses these defaults:
| Option | Type | Default | Description |
|---|---|---|---|
refreshReg |
string |
"$RefreshReg$" |
Set the Refresh registration identifier. |
refreshSig |
string |
"$RefreshSig$" |
Set the Refresh signature identifier. |
emitFullSignatures |
boolean |
false |
Emit readable hook signatures instead of compact hashes. |
React Compiler options
| Option | Type | Default | Description |
|---|---|---|---|
compilationMode |
string |
"infer" |
Select which functions to compile: "infer", "syntax", "annotation", or "all". |
panicThreshold |
string |
"none" |
Select which diagnostics abort the transform: "none", "critical_errors", or "all_errors". |
target |
string or ReactCompilerMetaTarget |
"19" |
Target React "17", "18", "19", or a Meta-internal runtime. |
gating |
ReactCompilerGating |
Unset | Emit compiled and original functions behind an imported feature flag. |
dynamicGating |
ReactCompilerDynamicGating |
Unset | Resolve flags in "use memo if(...)" directives from an imported module. A directive takes precedence over gating. |
noEmit |
boolean |
false |
Request lint mode without applying React Compiler output. Deprecated; use outputMode: "lint". |
outputMode |
string |
"client" |
Select "client", "ssr", or "lint" React Compiler output. |
eslintSuppressionRules |
string[] |
React Hooks rules | ESLint or Oxlint rule names whose matching suppression comments opt a function out. Defaults to react-hooks/exhaustive-deps and react-hooks/rules-of-hooks; [] disables this behavior. |
flowSuppressions |
boolean |
true |
Treat $FlowFixMe..., $FlowExpectedError, or $FlowIssue tags immediately followed by [react-rule as compiler opt-outs. |
ignoreUseNoForget |
boolean |
false |
Compile functions carrying "use no memo" or "use no forget". |
customOptOutDirectives |
string[] |
Unset | Add directive strings that opt a function or module out of compilation. |
sources |
string[] |
All except node_modules |
Only run React Compiler when the filename contains one of the provided strings. Providing this option replaces the default filter. |
environment |
ReactCompilerEnvironmentOptions |
Compiler defaults | Override compiler feature flags and validation settings. |
Despite its upstream-compatible name, eslintSuppressionRules recognizes both
ESLint and Oxlint comments: eslint-disable, eslint-disable-next-line,
eslint-enable, oxlint-disable, oxlint-disable-next-line, and
oxlint-enable.
outputMode: "ssr" takes precedence over noEmit. Otherwise, noEmit: true
forces lint output, including when outputMode: "client" is set. Lint output
suppresses only React Compiler rewrites; the downstream Oxc transform still
removes TypeScript syntax and applies the configured JSX transform.
The object-valued target and gating options have these shapes:
interface ReactCompilerMetaTarget {
kind: "donotuse_meta_internal";
runtimeModule?: string; // Defaults to "react".
}
interface ReactCompilerGating {
source: string;
importSpecifierName: string;
}
interface ReactCompilerDynamicGating {
source: string;
}
React Compiler environment options
Unset environment properties retain the compiler defaults shown here.
| Option | Type | Default | Description |
|---|---|---|---|
customMacros |
string[] |
Unset | Name macro-like functions whose calls and operands must stay together during compilation. |
enableResetCacheOnSourceFileChanges |
boolean |
Unsupported | Accepted for upstream option compatibility but currently has no effect. |
enablePreserveExistingMemoizationGuarantees |
boolean |
true |
Use existing useMemo and useCallback information to preserve referential-equality behavior. |
validatePreserveExistingMemoizationGuarantees |
boolean |
true |
Validate that compilation preserves existing manual memoization guarantees. |
validateExhaustiveMemoizationDependencies |
boolean |
false |
Validate that manual memoization dependency arrays are exhaustive. |
validateExhaustiveEffectDependencies |
string |
"off" |
Validate effect dependencies with "off", "all", "missing-only", or "extra-only". |
enableOptionalDependencies |
boolean |
Unsupported | Accepted for upstream option compatibility but currently has no effect. |
enableNameAnonymousFunctions |
boolean |
false |
Give generated or outlined anonymous functions inferred names. |
validateHooksUsage |
boolean |
true |
Validate that components partially satisfy the Rules of Hooks. |
validateRefAccessDuringRender |
boolean |
true |
Validate that ref values are not accessed during render. |
validateNoSetStateInRender |
boolean |
true |
Validate that state setters are not called unconditionally during render. |
enableUseKeyedState |
boolean |
false |
Recommend keyed state when reporting render-time state resets. |
validateNoSetStateInEffects |
boolean |
false |
In lint mode, validate that state setters are not called synchronously in effects. |
validateNoDerivedComputationsInEffects |
boolean |
false |
Validate that effects are not used to calculate data that can be derived during render. |
validateNoDerivedComputationsInEffectsExp |
boolean |
false |
In lint mode, enable the experimental form of derived-computation validation. |
validateNoJsxInTryStatements |
boolean |
false |
In lint mode, validate against creating JSX inside try blocks. |
validateStaticComponents |
boolean |
false |
In lint mode, validate against dynamically creating components during render. |
validateNoCapitalizedCalls |
string[] |
Unset | Validate capitalized function calls. The array adds allowed names; [] enables validation without extra names. |
validateBlocklistedImports |
string[] |
Unset | Bail out files that import any listed module. |
validateSourceLocations |
boolean |
Unsupported | Accepted for upstream option compatibility but currently has no effect. |
validateNoImpureFunctionsInRender |
boolean |
false |
Validate against impure function calls during render. |
validateNoFreezingKnownMutableFunctions |
boolean |
Unsupported | Accepted for upstream option compatibility, but validation currently runs regardless of its value. |
enableAssumeHooksFollowRulesOfReact |
boolean |
true |
Assume hook arguments and return values may be memoized and are therefore frozen. |
enableTransitivelyFreezeFunctionExpressions |
boolean |
true |
Treat values captured by functions passed to React as transitively frozen. |
enableFunctionOutlining |
boolean |
true |
Outline anonymous functions that do not capture local variables. |
enableJsxOutlining |
boolean |
false |
Outline nested JSX into separately memoizable components. |
assertValidMutableRanges |
boolean |
Unsupported | Accepted for upstream option compatibility but currently has no effect. |
enableCustomTypeDefinitionForReanimated |
boolean |
false |
Use React Native Reanimated-aware type definitions. |
enableTreatRefLikeIdentifiersAsRefs |
boolean |
true |
Treat ref-like identifiers with a current property as React refs. |
enableTreatSetIdentifiersAsStateSetters |
boolean |
false |
Treat called identifiers whose names begin with set as state setters. |
validateNoVoidUseMemo |
boolean |
false |
Validate that useMemo callbacks return a value. |
enableAllowSetStateFromRefsInEffects |
boolean |
true |
Allow recognized ref-based state-setting patterns in effects. |
enableVerboseNoSetStateInEffect |
boolean |
false |
Emit more detailed diagnostics for state setters called in effects. |
enableForest |
boolean |
false |
Enable the experimental Forest reactive-scope optimization mode. |
The default React 19 target imports react/compiler-runtime. Targets 17 and 18
import react-compiler-runtime, which must be available to the generated code.
Callback-valued options such as logger, function-valued sources, and type
provider callbacks are not supported by the native binding. sources accepts
an array of filename substrings instead.
Notes
- TypeScript support removes syntax only. It does not type-check or emit declarations.
jsx.refreshemits Fast Refresh registration and signature instrumentation. The bundler or development server must provide the Refresh runtime and HMR integration.- The transform stages are independent.
reactCompiler: falsestill removes TypeScript and transforms JSX, whilejsx: "preserve"retains JSX without disabling React Compiler. Recoverable compiler bail-outs still run the downstream TypeScript and JSX transforms.
See index.d.ts for the generated TypeScript declarations and the Oxc JSX
documentation for more JSX examples.