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.

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

Table of Contents

  1. Overview
  2. Architecture
  3. Compilation Pipeline
  4. Configuration
  5. CLI Usage
  6. Integration with Output
  7. Performance Benchmarks
  8. Related Documentation

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 🏗️

+---------------------------------------------------------+
|                       Rest                               |
|                                                          |
|  +------------------+  +------------------+              |
|  | Fn/Parse.rs      |  | Fn/Transform.rs  |             |
|  | OXC parser entry |  | OXC transformer  |             |
|  +------------------+  +------------------+              |
|                                                          |
|  +------------------+  +------------------+              |
|  | Fn/Build.rs      |  | Fn/Bundle.rs     |             |
|  | Build pipeline   |  | Module bundler   |             |
|  +------------------+  +------------------+              |
|                                                          |
|  +------------------+  +------------------+              |
|  | Struct/Compiler  |  | Fn/Worker.rs     |             |
|  | Config.rs        |  | Parallel worker  |             |
|  | Compiler config  |  | pool             |             |
|  +------------------+  +------------------+              |
+---------------------------------------------------------+

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:

TypeScript input (.ts, .tsx, .mts, .cts)
    |
    v
1. OXC Parser (oxc_parser)
    - Produces AST with full source location tracking
    - Handles TypeScript syntax extensions
    - Supports decorators, JSX, and modern ECMAScript
    |
    v
2. OXC Semantic Analysis (oxc_semantic)
    - Symbol resolution and scope analysis
    - Binding and reference tracking
    - Type checking (scope-level only, not full type inference)
    |
    v
3. OXC Transformer (oxc_transformer)
    - Decorator lowering to ES5/ES2015 patterns
    - Class field transformations (public/private field lowering)
    - TypeScript type annotation stripping
    - JSX transformation to createElement calls
    - Target ES version lowering
    |
    v
4. OXC Code Generator (oxc_codegen)
    - JavaScript source output
    - Source map generation (VLQ-encoded mappings)
    - (Optional) OXC Minifier for compressed output
    |
    v
JavaScript output (.js, .cjs, .mjs)

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",
				};
			});
		},
	};
}

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