Skip to content

Commit a1adb48

Browse files
1 parent fa0e95a commit a1adb48

3 files changed

Lines changed: 137 additions & 8 deletions

File tree

Documentation/GitHub/DeepDive.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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.

Source/Fn/Binary/Command.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
pub fn Fn() -> ArgMatches {
3939
Command::new("Rest")
4040
.version(env!("CARGO_PKG_VERSION"))
41-
.author("Source 🖋️ Open 👐🏻 <Source/Open@PlayForm.Cloud>")
42-
.about("Rest ⛱️")
41+
.author("Source🖋️ Open👐🏻 <Source/Open@PlayForm.Cloud>")
42+
.about("Rest⛱️")
4343
.subcommand(
4444
Command::new("compile")
4545
.about("Compile TypeScript files using SWC")
@@ -102,7 +102,7 @@ pub fn Fn() -> ArgMatches {
102102
.action(SetTrue)
103103
.display_order(7)
104104
.required(false)
105-
.help("Parallel compilation ⏩"),
105+
.help("Parallel compilation⏩"),
106106
)
107107
.arg(
108108
Arg::new("Exclude")
@@ -122,7 +122,7 @@ pub fn Fn() -> ArgMatches {
122122
.display_order(4)
123123
.value_name("EXCLUDE")
124124
.required(false)
125-
.help("Exclude 🚫")
125+
.help("Exclude🚫")
126126
.default_value("node_modules"),
127127
)
128128
.arg(
@@ -133,15 +133,15 @@ pub fn Fn() -> ArgMatches {
133133
.display_order(2)
134134
.value_name("PARALLEL")
135135
.required(false)
136-
.help("Parallel ⏩"),
136+
.help("Parallel⏩"),
137137
)
138138
.arg(
139139
Arg::new("Pattern")
140140
.long("Pattern")
141141
.display_order(5)
142142
.value_name("PATTERN")
143143
.required(false)
144-
.help("Pattern 🔍")
144+
.help("Pattern🔍")
145145
.default_value(".ts"),
146146
)
147147
.arg(
@@ -151,7 +151,7 @@ pub fn Fn() -> ArgMatches {
151151
.display_order(3)
152152
.value_name("ROOT")
153153
.required(false)
154-
.help("Root 📂")
154+
.help("Root📂")
155155
.default_value("."),
156156
)
157157
.get_matches()

tests/unit/parser_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ fn test_parse_unicode_identifiers() {
532532
const π = 3.14159;
533533
let 你好 = "hello";
534534
function привет(): void {}
535-
const 🎉 = "celebrate";
535+
const🎉 = "celebrate";
536536
interface kabanay {}
537537
"#;
538538
let result = parse_source(source, "unicode.ts");

0 commit comments

Comments
 (0)