ASTX is an AST-based binary format for JavaScript. Instead of distributing raw source code, you compile JavaScript to a compact binary that any JavaScript runtime can execute via the ASTX runtime library.
Status: Early stage – APIs may change between releases.
| Goal | How ASTX achieves it |
|---|---|
| Smaller distribution size | AST nodes are encoded with MessagePack and compressed with Zstd (level 22) |
| AOT optimisations | The compiler runs a configurable pipeline of AST transformers before encoding |
| Obfuscation | Binary format is significantly harder to reverse-engineer than minified JS |
| Runtime independence | The runtime only needs a JS engine – Node.js, Deno, Bun, or a browser |
| Full JS feature support | Works at the AST level, so any syntactically valid JS can be compiled |
| Package | Description |
|---|---|
@astx/compiler |
Parses, optimises, and encodes JS → .astx |
@astx/runtime |
Decodes and executes .astx files |
@astx/shared |
Shared types, constants, and the wire-format spec |
@astx/cli |
Command-line interface (astx compile / run / gen) |
# Compiler (e.g. in a build script)
npm install @astx/compiler
# Runtime (e.g. in your app)
npm install @astx/runtime
# CLI (global)
npm install -g @astx/cliimport { compile, saveToFile } from "@astx/compiler";
const program = compile(`
function greet(name) {
console.log("Hello, " + name);
}
greet("world");
`);
await saveToFile(program, "greet.astx");import { loadFromFile, run } from "@astx/runtime";
const program = await loadFromFile("greet.astx");
run(program, { mode: "vm" });astx compile src/index.js dist/index.astx
astx run dist/index.astx[MAGIC_HEADER: 4 bytes] [FORMAT_VERSION: 1 byte] [Zstd-compressed payload]
│
┌─────────────────────────┘
▼ (MessagePack array)
[valueDict, bytecode, sourceMap | null]
- valueDict – deduplicated string/number/other literal values
- bytecode – deduplicated array of encoded AST node arrays (index-referenced)
- sourceMap – optional
[line, col][]per bytecode slot;nullentries for synthetic nodes
This repo is managed with pnpm workspaces and Turborepo.
# Install dependencies
pnpm install
# Build all packages
pnpm -r build
# Type-check all packages
pnpm -r check-typesGPL-3.0 — see individual package LICENSE files for details.