Vercel's scriptc compiles TypeScript to native binaries with no JS engine
Original source
Scriptc by Vercel: TypeScript-to-Native compiler, no JavaScript engine in binary
Hacker News →Vercel Labs has released scriptc, a compiler that turns ordinary TypeScript into small, self-contained native executables — no Node, no V8, and no embedded JavaScript engine in the default output. A recursive Fibonacci program compiles to a 178KB binary that starts in roughly 2ms. Code is type-checked by the real TypeScript compiler and requires no annotations or dialect changes; the project’s claim is that anything that compiles behaves byte-for-byte like it would under Node. The pipeline runs tsc’s parser and checker into a typed intermediate representation, then lowers to C or LLVM and hands off to clang.
The compiler sorts every construct into three explicit tiers: statically compiled native code (the default), dynamically executed code via an embedded ~620KB quickjs-ng engine behind a —dynamic flag, or outright rejection with a specific error code and rewrite hint — nothing is silently miscompiled. A coverage command reports what fraction of a program can go fully static and names the blockers. The static surface is unusually broad, covering classes with dynamic dispatch, closures, monomorphized generics, async/await on stackful fibers, regular expressions, the standard library with JS-exact string and collection semantics, and much of Node’s API including fs, crypto, child_process, and a full native net/TLS/http server stack plus fetch. npm dependencies work under —dynamic by embedding their shipped JavaScript at build time rather than reading node_modules at runtime.
Correctness is enforced by two gates on every change: differential testing runs 800+ corpus programs under both Node and native builds, requiring identical stdout, stderr, and exit codes (down to JS-exact number formatting fuzzed against a million doubles), and a memory-safety lane reruns the corpus under AddressSanitizer with a reference-count audit where leaks and use-after-free are build failures. The handful of deliberate divergences from Node are documented and numbered. The project also adds compile-time evaluation via comptime, optional native FFI to C ABIs, and runtime-checked casts that turn TypeScript’s as into validated assertions. macOS arm64 is the primary target, with Linux and Windows produced by cross-compilation. The broader significance is a direct challenge to the assumption that TypeScript is too dynamic to compile ahead-of-time — in practice, most real code turns out to be static enough.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.