Transformer
A high-performance transformer that rewrites unsupported syntax into forms supported by target runtimes.
Features
- Lowering ESNext to ES2015.
- Transforming TypeScript to JavaScript.
- Transforming JSX to JavaScript, with built-in React Refresh.
- Built-in support for popular plugins like styled-components.
- Replacing global variables.
- TypeScript Isolated Declarations Emit without using the TypeScript compiler.
General Options
The transform function accepts a filename, source code, and an options object:
js
import { transform } from "oxc-transform";
const result = await transform("lib.ts", sourceCode, {
// Force the source language. Inferred from filename by default.
lang: "tsx", // "js" | "jsx" | "ts" | "tsx" | "dts"
// Treat the source as script, module, or CommonJS. Inferred by default.
sourceType: "module", // "script" | "module" | "commonjs" | "unambiguous"
// The current working directory. Used to resolve relative paths.
cwd: "/path/to/project",
// Enable source map generation.
sourcemap: true,
// Configure runtime helper strategy.
helpers: {
mode: "Runtime", // "Runtime" (import from @oxc-project/runtime) or "External" (use global babelHelpers)
},
// See sub-pages for more options:
// typescript, jsx, target, assumptions, define, inject, decorator, plugins
});The transform function is async. A synchronous transformSync variant is also available with the same signature.
Installation
Node.js
- Use the node binding oxc-transform.
- Try on stackblitz.
Rust
Use the umbrella crate oxc with the transformer feature.
Rust usage example can be found here.
