npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tsn-compiler

v0.1.2

Published

AOT compiler: a TypeScript subset -> LLVM IR -> native executable

Readme

typescript native compiler tsn-compiler

An ahead-of-time (AOT) compiler that turns a subset of TypeScript into a standalone native executable — the way C++ or Rust do. There's no Node, V8, or JIT at runtime: the output is a self-contained binary.

.ts source ──▶ native executable

This is a learning-oriented compiler. It favors a clear, working end-to-end pipeline over feature breadth. See the language scope below for exactly what compiles.

Requirements

  • macOS on Apple Silicon (arm64) — the only configuration that's tested.
  • Node.js ≥ 22
  • clang++ on your PATH — install the Xcode Command Line Tools if you don't have it:
    xcode-select --install
    The compiler emits C++; clang++ compiles + links it into the final binary.

Usage

Run it without installing anything via npx (use the package name, tsn-compiler):

npx tsn-compiler <file.ts> [-o <output>] [--emit-cpp]

Or install it globally — the command it installs is tsn-compiler:

npm install -g tsn-compiler
tsn-compiler <file.ts>

Options

| Option | Description | | --------------------- | --------------------------------------------------------------- | | -o, --output <path> | Output executable path. Defaults to the source file's basename. | | --emit-cpp | Also write the generated C++ to <output>.cpp for inspection. | | -h, --help | Show help. |

Quick start

Create hello.ts:

console.log(20 + 22);

Compile and run it:

npx tsn-compiler hello.ts -o hello
./hello
# 42

Want to see the generated C++? Add --emit-cpp:

npx tsn-compiler hello.ts -o hello --emit-cpp
cat hello.cpp

Supported language

The goal is a small but complete pipeline. These features compile and run today:

  • Types: number, boolean, string, number/string arrays (T[]), and object literals with typed fields ({ x: number; y: number }).
  • console.log(...) for numbers, booleans, and strings.
  • Arithmetic: + - * / % (number is IEEE double, so 5 / 2 === 2.5), unary - / +
  • Comparisons & logic: < <= > >= === !== (numbers and strings), && || !
  • Strings: literals, concatenation ("a" + b; numbers coerce, e.g. "n=" + 5), lexicographic comparison, s.length, indexing s[i], and methods substring / slice / indexOf / charAt / charCodeAt / toUpperCase / toLowerCase
  • Variables: let / const (the type is inferred when you omit the annotation; var is not supported), assignment (x = e, a[i] = e, obj.f = e, +=, i++)
  • Control flow: if / else, while, for
  • Functions: top-level, typed params + return type, return, and calls (recursion works)
  • Arrays: literals (incl. empty []), indexing (xs[i], computed indices), .length, .push(v)
  • Objects: literals and field access (p.x)
function square(n: number): number {
  return n * n;
}
function sumOfSquares(a: number, b: number): number {
  return square(a) + square(b);
}
console.log(sumOfSquares(3, 4)); // 25

let xs: number[] = [10, 20, 30];
console.log(xs[0]); // 10
console.log(xs.length); // 3

let p: { x: number; y: number } = { x: 3, y: 4 };
console.log(p.x + p.y); // 7

let name = "Ada Lovelace";
console.log(name.length); // 12
console.log(name.toUpperCase()); // ADA LOVELACE
console.log(name.slice(0, 3)); // Ada
console.log("apple" < "banana"); // 1  (lexicographic; booleans print as 1/0)

console.log currently takes exactly one argument. A let/const without a type annotation infers its type from the initializer — an integer literal like const a = 12 compiles to int a = 12, a decimal to double, and so on.

Notes & limitations

  • number is an IEEE double (printed JS-style, shortest round-trip) — e.g. 20 / 6 prints 3.3333333333333335. Functions and object fields still accept scalars only (number/boolean/string) — arrays/objects can't be passed or returned yet.
  • var is not supported (and never will be) — use let or const.
  • Out of scope for now: null/undefined, classes, closures, exceptions, async, modules, generics, union/any types, and garbage collection.
  • Target is macOS arm64 only. Other platforms aren't supported yet.

How it works

The compiler runs four stages (see src/):

  1. Parse — the official typescript package parses your source into a TypeScript AST.
  2. Lower — that AST is lowered into a small, typed internal IR (src/ir/nodes.ts).
  3. Codegen — the IR is emitted as C++ source (src/codegen/emit.ts).
  4. Buildclang++ compiles + links the .cpp into a native executable (src/backend/clang.ts).

Development

git clone https://github.com/fardad-dev/typescript-native.git
cd typescript-native
npm install          # also builds dist/ via the prepare script

npm run build        # compile the compiler (tsc -> dist/)
npm test             # compile each tests/cases/*.ts, run it, diff against *.expected

# run the local build directly without a global install
node dist/index.js examples/test1.ts -o out --emit-cpp && ./out

Each language feature has a tests/cases/<name>.ts input paired with a <name>.expected stdout file; tests/e2e.test.ts compiles, runs, and diffs them.

License

MIT — see LICENSE.