Skip to main content

Elements

Rest

Rest is a high-performance TypeScript compiler built on the OXC (Oxidation Compiler) toolchain. It replaces esbuild's TypeScript loader with a Rust-powered OXC pipeline, producing VS Code-compatible output at 2-3x speed improvement.

PUBLISHED ELEMENTS Source/Content/doc/rest.md UNAVAILABLE UNAVAILABLE 9

Rest: OXC TypeScript Compiler ⛱️

Rest is a high-performance TypeScript compiler built on the OXC (Oxidation Compiler) toolchain:

  • Replaces esbuild’s TypeScript loader with a Rust-powered OXC pipeline
  • Produces VS Code-compatible output at 2-3x speed improvement
  • Handles decorators, class field transformations, JSX, and type stripping

Overview 📋

Rest is a Rust binary and library that provides a TypeScript-to-JavaScript compiler using the OXC toolchain:

  • Handles decorators, class field transformations, JSX, and TypeScript type stripping
  • Produces output compatible with VS Code’s module system
  • Integrates with Output’s build pipeline via RestPlugin
AttributeValue
LanguageRust (edition 2024)
Crate typeBinary + Library
OXC version0.48+
Dependenciesoxc_allocator, oxc_parser, oxc_transformer, oxc_codegen, oxc_semantic, oxc_span, oxc_ast, Common, clap, rayon
Consumed byOutput (optional RestPlugin)

Architecture 🏗️

Mermaid diagram

Module Map 🗺️

PathPurpose
Source/Binary.rsBinary entry point
Source/Fn/Build.rsBuild pipeline orchestration
Source/Fn/Bundle.rsModule bundling
Source/Fn/Transform.rsTypeScript transformation pipeline
Source/Fn/OXC.rsOXC compiler integration
Source/Fn/Worker.rsParallel worker pool
Source/Fn/NLS.rsNatural language search integration
Source/Struct/CompilerConfig.rsCompiler configuration types
Source/Library.rsLibrary root for integration
Source/Main.rsAlternative entry point

Compilation Pipeline 🔧

The OXC compilation pipeline processes TypeScript input through multiple stages:

Mermaid diagram

Parallel Processing ⚡

Rest uses rayon for parallel file compilation:

// Worker pool processes files in parallel
input_files.par_iter().map(|file| {
    compile_file(file, &config)
}).collect::<Result<Vec<Output>>>()

By default, one worker per logical CPU core is used. This can be overridden with the --workers N flag.


Configuration ⚙️

Rest reads configuration from CLI flags and environment variables:

FlagEnv VariableDefaultDescription
--entryREST_ENTRY(required)Entry point file or directory
--out-dirREST_OUT_DIRdist/Output directory
--targetREST_TARGETes2022Target ECMAScript version
--sourcemapREST_SOURCEMAPfalseGenerate source maps
--minifyREST_MINIFYfalseMinify output
--workersREST_WORKERSCPU countParallel worker count
--decoratorsREST_DECORATORSlegacyDecorator metadata mode
--class-fieldsREST_CLASS_FIELDSdefineClass field emit mode

Output Configuration 📝

rest --entry src/index.ts \
	--out-dir lib/ \
	--target es2022 \
	--sourcemap \
	--decorators legacy

CLI Usage 💻

# Single file compilation
rest --entry src/index.ts --out-dir dist/

# Directory compilation (parallel)
rest --entry src/ --out-dir dist/ --workers 8

# Minified production build
rest --entry src/index.ts --out-dir dist/ --minify --target es2021

# With source maps
rest --entry src/index.ts --out-dir dist/ --sourcemap

# Custom decorator behavior
rest --entry src/index.ts --out-dir dist/ --decorators stage3

Integration with Output 🔗

Rest integrates with the Output element’s build pipeline through the RestPlugin:

// Output/ESBuild/RestPlugin.ts
import { rest } from "@codeeditorland/rest";

export function RestPlugin(): ESBuild.Plugin {
	return {
		name: "rest",
		setup(build) {
			build.onLoad({ filter: /\.ts$/ }, async (args) => {
				const result = await rest.compile(args.path, {
					target: "es2022",
					sourcemap: true,
				});
				return {
					contents: result.code,
					loader: "js",
				};
			});
		},
	};
}

Note

Activated via environment variable: Compiler=Rest


Performance Benchmarks 📊

OperationesbuildRest (OXC)Improvement
Parse + transform 1000 files2.4s0.9s2.7x
Full bundle (100K LOC)1.8s0.7s2.6x
Minified bundle3.1s1.3s2.4x
Source map generation0.8s0.4s2.0x

Benchmarks performed on Apple M1 Max with 8 worker threads.



Project Maintainers: Source Open (Source/[email protected]) | GitHub Repository | Report an Issue