Quick start

@tsrx/yuku is a fast TSRX (opens in new tab) parser, analyzer, and code generator, built on Yuku (opens in new tab).

Install#

npm install @tsrx/yuku

It runs in Node.js 16.4 or newer, Bun, Deno, Workers, and browsers. The package is one WebAssembly module, so there is nothing to compile and no native addon to pick. See Runtimes.

Parse, analyze, generate#

import { analyze, generate, parse } from "@tsrx/yuku";

const source = `export const List = ({ items }) => @{
  @for (const item of items; key item.id) {
    <li>{item.name}</li>
  } @empty {
    <p>Nothing yet</p>
  }
}`;

const { program, diagnostics } = parse(source);

analyze(source).rootScope.find("List");

generate(program).code;
  • parse builds an ESTree program, with TSRX's node types as @tsrx/core (opens in new tab) names them. It never throws: errors are in diagnostics, each with the TSRXnnnn code @tsrx/core reports.
  • analyze gives Yuku's semantic model: scopes, bindings, references, imports, and exports. Analyzer does the same for a project of files.
  • generate prints a program, or any node in it, back to TSRX.

The arrow above renders a JSXCodeBlock whose output is a JSXForExpression. Paste it into the playground to see the whole tree.

Where next#

To Read
Read a file and walk its tree Parse
Resolve names, in one file or across files Analyze
Print a changed tree, strip types, or emit a source map Generate
Show errors with their codes Diagnostics
See why it's fast How it works