Files
oxc/napi/transform-react
oxc-guard f799f174b5 release(crates): oxc v0.157.0 (#28719)
### 🚀 Features

- 8dd67a6 transform-react: Expose TypeScript transform options (Tomas Särnhammar)
- deed7dc parser: More friendly error for duplicate import attribute key (#28262) (sapphi-red)

### 🐛 Bug Fixes

- eaa8e90 ecmascript: Avoid numeric `+` folding when an operand may be a string (#28544) (camc314)
- b03c7b8 regular_expression: Allow incomplete oversized legacy quantifiers (#28449) (Boshen)
- 128c67d semantic: Check strict eval and arguments writes by reference flags (#28445) (Boshen)
- c97c43c parser: Reject TypeScript default exports in JavaScript (#28440) (Boshen)
- fdd119f span: Count Unicode characters when filtering typo suggestions (#28452) (Boshen)
- cb64638 regular_expression: Reject incomplete Unicode atom escapes (#28448) (Boshen)
- fc0eed3 semantic: Stop let-binding scans at arrow functions (#28444) (Boshen)
- 3421516 parser: Preserve default import names in reexports (#28442) (Boshen)
- a1e7e5f parser: Reject optional class members in JavaScript (#28439) (Boshen)
- 5b9a7bc parser: Parse sloppy let expressions and labels (#28438) (Boshen)
- 8e61652 regex: Reject templates without cooked values (#28345) (Boshen)
- 3b36543 parser: Preserve in-context after TypeScript type arguments (#28300) (Boshen)
- 2e3126c regex: Decode constructor patterns and flags consistently (#28298) (Boshen)
- 8a90be2 regex: Track capture groups and disjunction identity (#28297) (Boshen)
- 3dc2cb0 regex: Preserve escape values and boundaries (#28296) (Boshen)
- fc8acbc parser: Handle leading-zero numeric exponents (#28295) (Boshen)
- 91a638d parser: Normalize raw template line endings with invalid escapes (#28285) (Boshen)
- 2ac9a42 parser: Allow parenthesized private-in expressions (#28284) (Boshen)
- 052bca9 ast: Prevent greyed out fields in AST types in IDEs (#28335) (overlookmotel)
- ed7df7d ast/estree: Include comments in TS Program span (#28326) (camc314)

### ⚡ Performance

- 9b6b7bf regular_expression: Advance validated Unicode escapes directly (#28514) (Boshen)
- 82e1982 regular_expression: Share Unicode property name prefixes (#28513) (Boshen)
- 5395a40 regular_expression: Parse class set character prefixes once (#28512) (Boshen)
- 3708934 regular_expression: Defer literal range dash allocation (#28511) (Boshen)
- d85ee3d semantic: Skip arguments ancestry checks outside classes (#28510) (Boshen)
- cf81d07 semantic: Reuse private reference resolution (#28509) (Boshen)
- a79eebc semantic: Avoid duplicate maps for public JavaScript members (#28508) (Boshen)
- 235ca3b semantic: Skip escape checks for unescaped strings (#28507) (Boshen)
- babf44c parser: Reuse shorthand assignment target identifiers (#28504) (Boshen)
- 444f24a ecmascript: Short-circuit simple parameter checks for rest (#28503) (Boshen)
- 04b20c0 semantic: Compute duplicate parameter policy once per list (#28446) (Boshen)
- dbf8482 parser: Use token lookahead for simple function types (#28489) (Boshen)
- bca1275 parser: Avoid unused destructuring rest capacity (#28499) (Boshen)
- 691be5c parser: Compact cover initialized name storage (#28495) (Boshen)
- b3b5444 parser: Build simple arrow bindings directly (#28493) (Boshen)
- e1c9baf parser: Disambiguate single-identifier arrow heads (#28491) (Boshen)
- 550e98a regular_expression: Avoid rescanning unique capture names (#28450) (Boshen)
- 10e9fc7 parser: Skip duplicate lookup for singleton import attributes (#28441) (Boshen)
- 5238839 parser: Use a stack buffer for float separators (#28435) (Boshen)
- 6e35e3c parser: Fast-path leaf expressions before delimiters (#28432) (Boshen)
- 3d7512c parser: Decode Unicode identifiers once (#28414) (Boshen)
- 30f59f4 parser: Factor object type opening brace (#28430) (Boshen)
- 028a267 parser: Always inline postfix update parsing (#28429) (Boshen)
- 1b5a171 parser: Reuse export kind classification (#28424) (Boshen)
- 179a432 parser: Factor return type identifier parsing (#28416) (Boshen)
- 553dd1d parser: Inline hot paths and fold function dispatch (#28404) (Boshen)
- de75d56 parser: Combine parenthesized arrow lookahead (#28412) (Boshen)
- a768a0c parser: Reuse comment annotations after rewind (#28408) (Boshen)
- 563d92a parser: Skip redundant source cursor updates (#28409) (Boshen)
- 7941ca9 parser: Factor tuple identifier parsing (#28398) (Boshen)
- 426c151 parser: Construct completed tokens without intermediate writes (#28291) (Boshen)
- df42953 minifier: Don't request another pass for block unwrapping (#28315) (Dunqing)
- c2d663d parser: Avoid vectors for single parenthesized expressions (#28374) (Boshen)
- 50bd0a9 parser: Size delimited lists after the first element (#28373) (Boshen)
- bd869b5 parser: Bypass redundant operand parsing (#28372) (Boshen)
- 455fc09 parser: Skip keyword checks for plain identifier expressions (#28371) (Boshen)
- 61303fb parser: Fast-path identifier operands (#28306) (Boshen)
- 6cf5b1a parser: Guard arrow and conditional parsing (#28305) (Boshen)
- 3666939 parser: Specialize identifier reference parsing (#28303) (Boshen)
- 0d6641a parser: Skip inapplicable expression parsing paths (#28294) (Boshen)
- 3be7997 parser: Reduce lexer search batch size (#28292) (Boshen)
- ab5655a regex: Remove redundant character-class and quantifier checks (#28288) (Boshen)
- ec8e8d4 parser: Remove redundant grammar and lexer checks (#28287) (Boshen)
- c903f5c parser: Specialize known-token parsing (#28286) (Boshen)
- 2683225 str: `static_ident!` and `static_str!` macros guarantee const evaluation (#28340) (overlookmotel)
- df90836 ast: Reduce compile time of `#[ast]` macro (#28336) (overlookmotel)
- 8239dac parser: Replace dragonbox_ecma with zmij_ecma (#28282) (Boshen)
2026-11-02 19:40:44 +00:00
..
…

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. Fatal diagnostics appear in errors without producing code. Recoverable React Compiler diagnostics are omitted by default; set reactCompiler.reportDiagnostics to include them in errors while code is still produced, and 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".
reportDiagnostics boolean false Include recoverable React Compiler diagnostics (skipped functions, rule suppressions, lint findings) in result.errors while still emitting code. Fatal diagnostics are always reported.
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. Lint findings are recoverable diagnostics, so pair lint output with reportDiagnostics: true to receive them in errors.

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 true 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.refresh emits 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: false still removes TypeScript and transforms JSX, while jsx: "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.