Skip to content

Transformer

A high-performance transformer that rewrites unsupported syntax into forms supported by target runtimes.

Features

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

Rust

Use the umbrella crate oxc with the transformer feature.

Rust usage example can be found here.

Integrations