Skip to main content

Deep Dive

Rest - Deep Dive

Rest TypeScript compiler architecture, OXC toolchain pipeline, key modules, data flow, integration points with Output/Cocoon/Sky, and configuration reference.

Rest provides the technical foundation TypeScript compiler within the Land project. Rest is a Rust binary that uses the OXC toolchain to compile TypeScript 2-3x faster than esbuild while producing output compatible with VS Code’s build process.


Architecture

Rest is structured as a Rust library with a binary entry point. The compilation pipeline passes source files through OXC’s parser, transformer, and code generator in sequence. An optional parallel mode processes multiple files concurrently across CPU cores.

graph TB
    subgraph "Rest - TypeScript Compiler"
        Binary["Library.rs - Binary Entry Point"]
        CLI["CLI Argument Parsing\n--Input · --Output · --Parallel"]
        Compiler["Fn/OXC/Compiler.rs\nOrchestration"]
        Parser["Fn/OXC/Parser.rs\nOXC Parser"]
        Transformer["Fn/OXC/Transformer.rs\nAST Transformation"]
        Codegen["Fn/OXC/Codegen.rs\nCode Generation"]
        Config["Struct/CompilerConfig.rs\nConfiguration"]
    end

    subgraph "OXC Toolchain"
        OXCParser["oxc_parser\nTypeScript / JSX"]
        OXCTransform["oxc_transformer\nDecorators · Class Fields"]
        OXCCodegen["oxc_codegen\nJS Output"]
        OXCSemantic["oxc_semantic\nSymbol Table"]
    end

    subgraph "Output Integration"
        RestPlugin["Output/RestPlugin.ts\nesbuild plugin"]
        TargetRest["Target/Rest/\nCompiled artifacts"]
        TargetFinal["Target/Microsoft/VSCode/\nMerged final output"]
    end

    Binary --> CLI
    CLI --> Compiler
    Compiler --> Parser
    Parser --> OXCParser
    Compiler --> Transformer
    Transformer --> OXCTransform
    Transformer --> OXCSemantic
    Compiler --> Codegen
    Codegen --> OXCCodegen
    Compiler --> Config
    Codegen --> TargetRest
    RestPlugin --> Compiler
    TargetRest --> TargetFinal

Key Modules

PathDescription
Source/Library.rsBinary entry point; parses CLI arguments and dispatches to compiler
Source/Fn/OXC/Compiler.rsMain compilation orchestrator; coordinates parser, transformer, and codegen
Source/Fn/OXC/Parser.rsWraps oxc_parser with error normalization and source tracking
Source/Fn/OXC/Transformer.rsApplies TypeScript-to-JavaScript AST transformations including decorators
Source/Fn/OXC/Codegen.rsGenerates final JavaScript text from the transformed AST
Source/Fn/Build.rsDirectory-based compilation: walks source trees preserving structure
Source/Fn/Bundle/Bundling utilities for multi-file outputs
Source/Fn/NLS/Natural Language Support string extraction
Source/Fn/SWC/SWC integration shims (alternative transformer path)
Source/Fn/Worker/Worker thread support for parallel compilation
Source/Struct/CompilerConfig.rsConfiguration struct: decorator mode, class fields, source maps
Source/Struct/SWC.rsSWC-specific configuration types

Data Flow

sequenceDiagram
    participant CLI as CLI / RestPlugin
    participant Compiler as Compiler Orchestrator
    participant Parser as OXC Parser
    participant Transformer as OXC Transformer
    participant Codegen as OXC Codegen
    participant Disk as Output Directory

    CLI->>Compiler: Compile(input_path, config)
    Compiler->>Parser: Parse(source_text)
    Parser->>Compiler: AST + diagnostics
    Compiler->>Transformer: Transform(AST, options)
    Note over Transformer: emitDecoratorMetadata\nuseDefineForClassFields=false\nTypeScript stripping
    Transformer->>Compiler: Transformed AST
    Compiler->>Codegen: Generate(AST)
    Codegen->>Compiler: JavaScript text
    Compiler->>Disk: Write .js file
    Compiler->>CLI: CompilationResult (count, elapsed, errors)

When --Parallel is specified, the compiler fans out file compilation across Tokio worker threads and collects aggregated metrics.


Integration Points

Connecting ElementDirectionMechanismDescription
OutputConsumerProcess invocation / esbuild pluginOutput’s RestPlugin.ts invokes the Rest binary or calls it via plugin API
CocoonIndirect consumerCompiled artifactsCocoon loads the JavaScript produced by Rest from Target/Microsoft/VSCode/
SkyIndirect consumer@codeeditorland/output packageSky loads VS Code UI components compiled through the Rest pipeline

Configuration

OptionCLI Flag / VariableDefaultDescription
Input path--InputrequiredDirectory or file to compile
Output path--OutputrequiredDestination directory for compiled JavaScript
Parallel mode--ParalleloffEnable multi-core parallel compilation
Decorator metadataCompilerConfigtrueEmit emitDecoratorMetadata for VS Code compatibility
Class fields modeCompilerConfigfalse (VS Code default)useDefineForClassFields - off matches VS Code’s gulp build
Source mapsCompilerConfigdevelopment onlyInline source maps for debug builds

The CompilerConfig struct is populated from either CLI flags or from the esbuild plugin context when Rest is invoked as a plugin within the Output build pipeline.