yuku
v0.28.1
Published
A JavaScript and TypeScript compiler toolchain written in Zig
Maintainers
Readme
Parse, analyze, walk, build, and print JavaScript and TypeScript.
One package, no third-party dependencies. Written in Zig, running in Node.js, Bun, Deno, browsers, and edge runtimes.
Docs · Playground · GitHub
npm install yukuIt runs natively where its addon for the platform installs, and as WebAssembly everywhere else. Cloudflare Workers and Vercel Edge run WebAssembly only from a file, so there also install @yuku-toolchain/wasm.
import { b, parse, print, walk } from "yuku";
const file = parse(`
const RATE = 0.2;
export const tax = (price: number) => price * RATE;
export const scale = (RATE: number) => RATE * 2;
`, { path: "tax.ts", analyze: true });
const rate = file.rootScope.find("RATE");
walk(file.program, {
Identifier(node, ctx) {
if (file.referenceOf(node)?.binding === rate) ctx.replace(b.Literal({ value: 0.2 }));
},
});
print(file, { strip: true }).code;
// const RATE = 0.2;
// export const tax = (price) => price * 0.2;
// export const scale = (RATE) => RATE * 2;The guide documents how to parse, walk and build, analyze, and print.
Performance
yuku parses faster than the alternatives on npm, on small and large files.
Analyzing a whole codebase, it is faster than typescript-eslint and the TypeScript API, and on a single large file too.
Measured on an Apple M3, see the parser and analyzer benchmarks. Pass one walk all your visitors.
License
MIT
