Transform plugin

Lower TypeScript, JSX, and modern syntax with the built-in transform plugin.

Introduction

The transform plugin wraps the oxc transformer and lowers TypeScript, JSX, and modern JavaScript syntax to a set of compilation targets. It also applies compile-time define replacements and injected imports.

Installation

The JS package exposes it as the builtin builtin:transform. In Rust it is a regular plugin named telarel_plugin_transform; add the crate as a dependency.

cargo add telarel_plugin_transform

Usage

JavaScript

import type { CodeResult } from "telarel";

import { compile } from "telarel";
import { transform } from "telarel/plugins/transform";

const result: CodeResult = await compile("const x: number = 1;", {
    plugins: [
        transform({
            targets: ["es2015"],
        }),
    ],
});

Rust

use telarel::{CodeResult, CompileOptions, Plugin, compile};
use telarel_plugin_transform::{TransformOptions, TransformPlugin, TransformTarget};

let transform_plugin: TransformPlugin = TransformPlugin::with_options(
    TransformOptions {
        targets: vec![TransformTarget::Es2015],
        ..TransformOptions::default()
    },
);

let result: CodeResult = compile(
    String::from("const x: number = 1;"),
    CompileOptions::default(),
    vec![Plugin::new_shared(transform_plugin)],
)
.await?;

TransformPlugin::new() uses the default options.

Options

OptionTypeDescription
targetsTransformTarget[]Compilation targets. Empty means the ES-next default.
typescriptTypeScriptOptionsTypeScript-specific transform options.
jsxJsxOptionsJSX runtime and pragma options.
injectRecord<string, ...>Imports injected for otherwise-free identifiers, keyed by the local name.
defineRecord<string, DefineValue>Compile-time replacements for free identifiers and member chains.
oxcOxcTransformOptionsEscape hatch for the raw oxc transform options.

The Rust TransformOptions additionally exposes helper_loader for controlling how runtime helpers are emitted.

Define

define replaces free identifiers and member chains with expression source strings. Quote string literals yourself, while scalars are stringified:

transform({
    define: {
        __DEV__: "false",
        "process.env.NODE_ENV": '"production"',
    },
});

Replacements run last, after inject and every transform.

Inject

inject adds imports for identifiers that would otherwise be free, keyed by the local binding name. A string value is a module source imported as a named specifier; a [source, imported] pair imports imported from source; the object form selects the specifier explicitly. Dotted keys such as "Object.assign" are replaced as member chains.

Injected imports run after all transforms, before define.

Last updated on

Copyright © 2026, Alpheus

On this page