技术事实和测量说明以英文为准,以避免不同翻译之间出现偏差。

A TypeScript Native Compiler, Built in Rust

Perry compiles supported TypeScript and JavaScript ahead of time to machine code. Native builds do not require an external JavaScript engine by default, while the Perry runtime and GC remain part of the executable.

A hybrid compiler, not “types make JavaScript static”

TypeScript annotations are mostly erased and do not prove a concrete runtime representation for every expression. Perry combines declared types, inference, known call shapes, and representation selection to optimize proved cases. Dynamic values, unknown receivers, prototypes, and other JavaScript behavior retain runtime paths.

That distinction matters: known numeric operations or object shapes may become direct machine operations, while other code uses the statically linked runtime and garbage collector. Some unsupported engine semantics require the optional V8 fallback or do not compile.

工作原理

From TypeScript source through SWC, Perry HIR, LLVM, and the linked runtime

TypeScript.ts 文件
SWC
解析器快速解析
HIR
转换Monomorphization
LLVM
代码生成机器码
可执行文件From ~330 KB; varies by features

想了解编译器内部是如何工作的吗? 编译器内部原理

深入了解:TypeScript 与 LLVM——单态化、NaN 装箱,以及 Perry 为何放弃 Cranelift。

The current pipeline

  1. Parse with SWC. Perry builds an AST and resolves modules before its own lowering passes.
  2. Lower to Perry HIR. The compiler records operations and the type or representation evidence it can actually prove.
  3. Specialize bounded known cases. Known calls and values can use direct paths; polymorphic cases keep checked, boxed, or dynamic fallbacks.
  4. Generate LLVM IR. LLVM optimizes and emits target-specific object code.
  5. Link and package. Perry links the required runtime, GC, libraries, and target-specific platform pieces.

Support is broad, not universal

The current project reports ~97% parity across 53 tracked Node modules and roughly ~50 native package/API implementations. Known gaps include dynamic code paths and parts of JavaScript, TypeScript, Node.js, and package compatibility.

Perry documents 11 targets, with narrower core support on some devices and HarmonyOS kept as a separate preview. “One codebase” is a portability goal, not a promise that every API and layout behaves identically on every platform.

Try it against real code

Run Perry’s checker and compile the exact package graph and target you intend to ship.

Get started