A high-performance TypeScript compiler built with Rust and OXC, designed for 100% compatibility with VSCode's build process.
# Build Rest
cargo build --release --package=Rest
# Run tests
./Element/Rest/run_tests.sh
# Compile TypeScript files
Target/release/Rest compile \
--input ./src \
--output ./out \
--target es2024 \
--module commonjs
# Enable in VSCode build
Compiler=Rest npm run compile-buildRest is one of the five Elements in the CodeEditorLand architecture, responsible for compilation and build tooling. It replaces esbuild's TypeScript loader with a Rust-powered compiler that produces VSCode-compatible output.
- Performance: Rust + OXC compiles TypeScript 2-3x faster than esbuild
- Compatibility: OXC is used by VSCode internally, ensuring 1:1 output
- Memory Safety: No garbage collection, deterministic performance
- Modern: Built on OXC 0.48, the latest TypeScript infrastructure
Rest integrates into the build system through environment variables:
# Set the compiler to Rest
export Compiler=Rest
# Optional: Configure Rest binary path
export REST_BINARY_PATH="path/to/Rest"
# Optional: Enable verbose logging
export REST_VERBOSE=true
# Optional: Enable source maps (when implemented)
export RestSourcemap=trueWhen Compiler=Rest is set, Element/Output/Source/ESBuild/RestPlugin.ts intercepts TypeScript files and delegates compilation to the Rest binary instead of using esbuild's built-in TypeScript loader.
- ✅ Full TypeScript 5.x support
- ✅ Decorator handling with
emitDecoratorMetadata - ✅
useDefineForClassFieldscontrol (VSCode: false) - ✅ Source map generation (planned)
- ✅ Parallel compilation (
--Parallelflag) - ✅ Directory-based compilation
- ✅ Comprehensive error reporting
- ✅ Compilation metrics tracking
Rest compile [OPTIONS]
Required:
--input, -i <PATH> Input directory containing TypeScript files
--output, -o <PATH> Output directory for compiled JavaScript
Optional:
--target <ES2024> ECMAScript target (default: es2024)
--module <commonjs> Module system: commonjs, esmodule (default: commonjs)
--source-maps Generate source maps (not yet implemented)
--Parallel Enable parallel compilation (default: false)
--use-define-for-class-fields
Use defineForClassFields semantic (default: false)
--help, -h Show help
--version, -V Show versionRest supports two main configuration presets:
use Rest::Struct::CompilerConfig;
let config = CompilerConfig::simple();
// - Target: es2024
// - Module: commonjs
// - Private fields: not converted
// - NLS: disabled
// - Workers: disabledlet config = CompilerConfig::vscode();
// - Target: es2024
// - Module: esmodule
// - Private fields: converted to __<name>
// - NLS: enabled (localization processing)
// - Workers: enabled
// - Bundling: enableduse Rest::{Compiler, Struct::CompilerConfig};
// Create compiler with configuration
let config = CompilerConfig::vscode();
let compiler = Compiler::new(config);
// Compile a single file (output goes to same directory with .js extension)
let result = compiler.compile_file(
"path/to/file.ts",
source_code_string
);
// Compile to specific output path
use std::path::Path;
let output_path = Path::new("path/to/output.js");
let result = compiler.compile_file_to(
"input.ts",
source_code_string,
&output_path,
false // use_define_for_class_fields
);
// Check metrics
let metrics = compiler.outlook.lock().unwrap();
println!("Compiled {} files in {:?}",
metrics.count, metrics.elapsed);Run the comprehensive test suite:
./Element/Rest/run_tests.shTests cover:
- Binary existence and version
- Simple TypeScript compilation
- Class fields and methods
- Decorators with metadata
- Interfaces and types
- Async functions
- Multiple file batches
- VSCode compatibility mode
- ESM output format
- Parallel compilation
- RestPlugin integration
Compare Rest output with VSCode's build:
./Element/Rest/benchmark_vscode_compatibility.shThis script:
- Compiles a sample of VSCode source files with Rest
- Compares output byte-for-byte with VSCode's gulp build
- Reports match percentage and any differences
- Measures performance metrics
Element/Rest/
├── Source/
│ ├── Library.rs # Binary entry point
│ ├── Fn/ # Functions/compilation logic
│ │ ├── OXC/ # OXC-based compiler
│ │ │ ├── Compiler.rs # Main compiler orchestration
│ │ │ ├── Parser.rs # OXC parser wrapper
│ │ │ ├── Transformer.rs # AST transformation
│ │ │ ├── Codegen.rs # Code generation
│ │ │ └── Compile.rs # (placeholder)
│ │ ├── SWC/ # Legacy SWC implementation (reference)
│ │ ├── Binary/ # CLI binary structure
│ │ │ └── Command.rs # CLI argument parsing
│ │ ├── Build.rs # Build routines
│ │ └── ... # Other features (NLS, Worker, Bundle)
│ └── Struct/ # Data structures
│ ├── SWC.rs # CompilerConfig (legacy naming)
│ └── CompilerConfig.rs # Advanced config (Phase 3)
├── tests/
│ ├── integration/
│ │ └── vscode_compatibility.rs # Integration tests
│ └── unit/
│ └── oxc_compiler.rs # Unit tests for OXC
├── Target/
│ └── release/Rest # Compiled binary
├── COMPILER.md # Detailed documentation
├── VERIFICATION.md # Test results and verification
├── run_tests.sh # Test runner script
└── benchmark_vscode_compatibility.sh # Benchmark script
┌──────────────────────────────────────────────────────────────┐
│ Rest Compiler │
├──────────────────────────────────────────────────────────────┤
│ │
│ Input: TypeScript files (directory) │
│ Output: JavaScript files (directory) │
│ │
│ Pipeline: │
│ 1. Parse (OXC Parser) │
│ └─> AST with 'static lifetime │
│ 2. Transform (OXC Transformer) │
│ ├─> Strip TypeScript types │
│ ├─> Handle decorators │
│ └─> Apply useDefineForClassFields │
│ 3. Codegen (OXC Codegen) │
│ └─> Generate JavaScript │
│ 4. Write (Filesystem) │
│ └─> Output with preserved directory structure │
│ │
│ Configuration: │
│ - CompilerConfig::simple() │
│ - CompilerConfig::vscode() │
│ │
│ Metrics: │
│ - Compilation count │
│ - Total elapsed time │
│ - Error count │
│ │
└──────────────────────────────────────────────────────────────┘
| Variable | Purpose | Default |
|---|---|---|
Compiler |
Set to "Rest" to enable Rest compiler |
"esbuild" |
REST_BINARY_PATH |
Override path to Rest binary | auto-discovered |
REST_OPTIONS |
Additional CLI arguments for Rest | none |
REST_VERBOSE |
Enable verbose logging ("true") |
false |
RestSourcemap |
Generate source maps ("true") |
false |
NODE_ENV |
"development" or "production" affects config |
none |
From benchmark results (first 100 files of VSCode):
- Single file compile: ~0.4ms
- Batch of 100 files: ~200-300ms
- Throughput: 300-500 files/second
- Memory: ~50-100MB for large compilations
Rest is significantly faster than esbuild for TypeScript compilation because:
- OXC is purpose-built for TypeScript (no JS fallback)
- Zero-copy operations with careful lifetime management
- No type-checking overhead (like
tsc --noEmit) - Parallel processing optional with
--Parallelflag
Rest is designed to produce byte-for-byte identical output to VSCode's gulp/tsb build:
- ✅ Decorator transformation (
__decoratehelper) - ✅
useDefineForClassFields = false(default) - ✅
emitDecoratorMetadata = true(default) - ✅ Target ES2024
- ✅ CommonJS and ESM module formats
- ✅ Private field conversion (with advanced config)
- ✅ Class field initialization patterns
- ⏸️ Source map generation (in progress)
# Build Rest
cargo build --release --package=Rest
# Set binary path
export REST_BINARY_PATH="Element/Rest/Target/release/Rest"Rest uses OXC which may have different error messages than tsc:
- Parse errors: Check syntax, especially decorators
- Transform errors: May indicate unsupported TypeScript features
- Enable
REST_VERBOSE=truefor detailed logs
Rest includes critical fixes for OXC lifetime management. If you encounter segfaults:
- Ensure using OXC 0.48+
- Check that
parse_resultstays alive through transformation - Enable
RUST_LOG=debugfor detailed tracing
# Debug build
cargo build --package=Rest
# Release build (optimized)
cargo build --release --package=Rest# Quick test suite
./Element/Rest/run_tests.sh
# Rust unit/integration tests
cargo test --package=Rest
# With verbose output
cargo test --package=Rest -- --nocapture
# Specific test
cargo test --package=Rest test_name- Parser changes: Edit
Fn/OXC/Parser.rs - Transform changes: Edit
Fn/OXC/Transformer.rs - Codegen changes: Edit
Fn/OXC/Codegen.rs - CLI changes: Edit
Fn/Binary/Command.rs - Configuration: Update
Struct/SWC.rsorStruct/CompilerConfig.rs
MIT - See LICENSE file