|
| 1 | +# Rest — Deep Dive |
| 2 | + |
| 3 | +This document provides the technical foundation for the Rest TypeScript compiler |
| 4 | +within the Land ecosystem. **Rest** is a Rust binary that uses the OXC toolchain |
| 5 | +to compile TypeScript 2-3x faster than esbuild while producing output compatible |
| 6 | +with VSCode's build process. |
| 7 | + |
| 8 | +--- |
| 9 | + |
| 10 | +## Architecture |
| 11 | + |
| 12 | +Rest is structured as a Rust library with a binary entry point. The compilation |
| 13 | +pipeline passes source files through OXC's parser, transformer, and code |
| 14 | +generator in sequence. An optional parallel mode processes multiple files |
| 15 | +concurrently across CPU cores. |
| 16 | + |
| 17 | +```mermaid |
| 18 | +graph TB |
| 19 | + subgraph "Rest — TypeScript Compiler" |
| 20 | + Binary["Library.rs — Binary Entry Point"] |
| 21 | + CLI["CLI Argument Parsing\n--Input · --Output · --Parallel"] |
| 22 | + Compiler["Fn/OXC/Compiler.rs\nOrchestration"] |
| 23 | + Parser["Fn/OXC/Parser.rs\nOXC Parser"] |
| 24 | + Transformer["Fn/OXC/Transformer.rs\nAST Transformation"] |
| 25 | + Codegen["Fn/OXC/Codegen.rs\nCode Generation"] |
| 26 | + Config["Struct/CompilerConfig.rs\nConfiguration"] |
| 27 | + end |
| 28 | +
|
| 29 | + subgraph "OXC Toolchain" |
| 30 | + OXCParser["oxc_parser\nTypeScript / JSX"] |
| 31 | + OXCTransform["oxc_transformer\nDecorators · Class Fields"] |
| 32 | + OXCCodegen["oxc_codegen\nJS Output"] |
| 33 | + OXCSemantic["oxc_semantic\nSymbol Table"] |
| 34 | + end |
| 35 | +
|
| 36 | + subgraph "Output Integration" |
| 37 | + RestPlugin["Output/RestPlugin.ts\nesbuild plugin"] |
| 38 | + TargetRest["Target/Rest/\nCompiled artifacts"] |
| 39 | + TargetFinal["Target/Microsoft/VSCode/\nMerged final output"] |
| 40 | + end |
| 41 | +
|
| 42 | + Binary --> CLI |
| 43 | + CLI --> Compiler |
| 44 | + Compiler --> Parser |
| 45 | + Parser --> OXCParser |
| 46 | + Compiler --> Transformer |
| 47 | + Transformer --> OXCTransform |
| 48 | + Transformer --> OXCSemantic |
| 49 | + Compiler --> Codegen |
| 50 | + Codegen --> OXCCodegen |
| 51 | + Compiler --> Config |
| 52 | + Codegen --> TargetRest |
| 53 | + RestPlugin --> Compiler |
| 54 | + TargetRest --> TargetFinal |
| 55 | +``` |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +## Key Modules |
| 60 | + |
| 61 | +| Path | Description | |
| 62 | +| :--- | :--- | |
| 63 | +| `Source/Library.rs` | Binary entry point; parses CLI arguments and dispatches to compiler | |
| 64 | +| `Source/Fn/OXC/Compiler.rs` | Main compilation orchestrator; coordinates parser, transformer, and codegen | |
| 65 | +| `Source/Fn/OXC/Parser.rs` | Wraps `oxc_parser` with error normalization and source tracking | |
| 66 | +| `Source/Fn/OXC/Transformer.rs` | Applies TypeScript-to-JavaScript AST transformations including decorators | |
| 67 | +| `Source/Fn/OXC/Codegen.rs` | Generates final JavaScript text from the transformed AST | |
| 68 | +| `Source/Fn/Build.rs` | Directory-based compilation: walks source trees preserving structure | |
| 69 | +| `Source/Fn/Bundle/` | Bundling utilities for multi-file outputs | |
| 70 | +| `Source/Fn/NLS/` | Natural Language Support string extraction | |
| 71 | +| `Source/Fn/SWC/` | SWC integration shims (alternative transformer path) | |
| 72 | +| `Source/Fn/Worker/` | Worker thread support for parallel compilation | |
| 73 | +| `Source/Struct/CompilerConfig.rs` | Configuration struct: decorator mode, class fields, source maps | |
| 74 | +| `Source/Struct/SWC.rs` | SWC-specific configuration types | |
| 75 | + |
| 76 | +--- |
| 77 | + |
| 78 | +## Data Flow |
| 79 | + |
| 80 | +```mermaid |
| 81 | +sequenceDiagram |
| 82 | + participant CLI as CLI / RestPlugin |
| 83 | + participant Compiler as Compiler Orchestrator |
| 84 | + participant Parser as OXC Parser |
| 85 | + participant Transformer as OXC Transformer |
| 86 | + participant Codegen as OXC Codegen |
| 87 | + participant Disk as Output Directory |
| 88 | +
|
| 89 | + CLI->>Compiler: Compile(input_path, config) |
| 90 | + Compiler->>Parser: Parse(source_text) |
| 91 | + Parser->>Compiler: AST + diagnostics |
| 92 | + Compiler->>Transformer: Transform(AST, options) |
| 93 | + Note over Transformer: emitDecoratorMetadata\nuseDefineForClassFields=false\nTypeScript stripping |
| 94 | + Transformer->>Compiler: Transformed AST |
| 95 | + Compiler->>Codegen: Generate(AST) |
| 96 | + Codegen->>Compiler: JavaScript text |
| 97 | + Compiler->>Disk: Write .js file |
| 98 | + Compiler->>CLI: CompilationResult (count, elapsed, errors) |
| 99 | +``` |
| 100 | + |
| 101 | +When `--Parallel` is specified, the compiler fans out file compilation across |
| 102 | +Tokio worker threads and collects aggregated metrics. |
| 103 | + |
| 104 | +--- |
| 105 | + |
| 106 | +## Integration Points |
| 107 | + |
| 108 | +| Connecting Element | Direction | Mechanism | Description | |
| 109 | +| :--- | :--- | :--- | :--- | |
| 110 | +| **Output** | Consumer | Process invocation / esbuild plugin | Output's `RestPlugin.ts` invokes the Rest binary or calls it via plugin API | |
| 111 | +| **Cocoon** | Indirect consumer | Compiled artifacts | Cocoon loads the JavaScript produced by Rest from `Target/Microsoft/VSCode/` | |
| 112 | +| **Sky** | Indirect consumer | `@codeeditorland/output` package | Sky loads VSCode UI components compiled through the Rest pipeline | |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +## Configuration |
| 117 | + |
| 118 | +| Option | CLI Flag / Variable | Default | Description | |
| 119 | +| :--- | :--- | :--- | :--- | |
| 120 | +| Input path | `--Input` | required | Directory or file to compile | |
| 121 | +| Output path | `--Output` | required | Destination directory for compiled JavaScript | |
| 122 | +| Parallel mode | `--Parallel` | off | Enable multi-core parallel compilation | |
| 123 | +| Decorator metadata | `CompilerConfig` | `true` | Emit `emitDecoratorMetadata` for VSCode compatibility | |
| 124 | +| Class fields mode | `CompilerConfig` | `false` (VSCode default) | `useDefineForClassFields` — off matches VSCode's gulp build | |
| 125 | +| Source maps | `CompilerConfig` | development only | Inline source maps for debug builds | |
| 126 | + |
| 127 | +The `CompilerConfig` struct is populated from either CLI flags or from the |
| 128 | +esbuild plugin context when Rest is invoked as a plugin within the Output build |
| 129 | +pipeline. |
0 commit comments