Yuku for TSRX
Parse, analyze and print TSRX with the Yuku parser
A TSRX parser, analyzer, and code generator, written in Zig on Yuku and shipped as one WebAssembly module. The tree is ESTree, with the node types of @tsrx/core.
export function Cart({ items }): unknown @{
const count = items.length;
<ul class="cart">
@for (const item of items; key item.id) {
<li>{item.label}</li>
} @empty {
<li>Your cart is empty</li>
}
@if (count > 0) { <li>{count} in the cart</li> }
<style>.cart { display: grid; gap: 4px; }</style>
</ul>
}
The program parse returns, as JSON: ESTree, with TSRX nodes such as JSXCodeBlock, JSXForExpression and JSXStyleElement.
Every diagnostic, with the TSRXnnnn code @tsrx/core reports. The parse also reports semantic errors here.
The program printed back to TSRX by generate.
The scopes, bindings, references, imports, and exports analyze finds.
Parsing performance
Against the official parser, @tsrx/core, both building an ESTree AST.
Shorter is faster. Median time per file to parse the 1,987 TSRX sources of the test suite, over 3 runs, each in a fresh Node.js 24 process on an Apple M5 Pro.
-
Fast
Parses the TSRX test suite 9.2x faster than
@tsrx/core, and the pages of tsrx.dev 4.8x faster. Benchmarks -
The official node types
ESTree, with TSRX's nodes named as
@tsrx/corenames them. Each of the 2,115 sources of the test suite parses, or fails, as it does in@tsrx/core, except where that accepts what TypeScript rejects. -
Runs everywhere
One WebAssembly module and no native addons: Node.js 16.4 or newer, Bun, Deno, Workers, and browsers. Runtimes
-
Scopes and bindings
Yuku's semantic model for TSRX: scopes, bindings, references, imports, and exports, for one file or a whole project.
-
Back to source
Print a program, or any node, back to TSRX, with formatting, type stripping, minification, and source maps.
-
A Yuku dialect
TSRX is one Zig file compiled into Yuku. Yuku parses, analyzes, and prints the JavaScript and TypeScript around it. How it works
Maintained by Jack Shelton, on tsrx-org/yuku. Thanks to Arshad Yaseen for his help.
Next: a CSS tree for every <style>, parsed in the same pass by yuku-css, once yuku#280 lands.