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

yuku-ast

v0.8.7

Published

Typed AST toolkit for JavaScript and TypeScript ESTree trees: walker, builders, guards, and syntactic utilities

Downloads

3,504,207

Readme

yuku-ast

A typed, mutating AST walker and syntactic utilities for JavaScript and TypeScript ESTree trees, powered by Yuku.

Works with any ESTree / TypeScript-ESTree AST. Traversal order is driven by tables generated from the yuku-parser AST definition, so it can never drift from the parser, and there is no runtime key discovery.

Install

npm install yuku-ast

Walking

Handlers are keyed by node type, by alias group, or the universal enter / leave. Every handler receives the exact node type.

import { parse } from "yuku-parser";
import { walk } from "yuku-ast";

const { program } = parse(source);

walk(program, {
  Identifier(node) {
    console.log(node.name);
  },
  CallExpression: {
    enter(node, ctx) {},
    leave(node, ctx) {},
  },
  Function(node) {
    // fires for function declarations, expressions, and arrows
  },
  enter(node) {},
});

Aliases: Expression, Statement, Declaration, ModuleDeclaration, Function, Class, Method, Loop, Pattern, JSX, TSType. Per node the order is universal enter, alias enters, the typed enter, children, then the mirror for leave.

The context exposes the position (ctx.parent, ctx.key, ctx.index, ctx.ancestors()), flow control (ctx.skip(), ctx.stop()), and in-place mutation: ctx.replace(node) continues into the replacement, ctx.remove() skips the removed subtree, ctx.insertBefore(node) inserts a sibling without visiting it, ctx.insertAfter(node) inserts one the walk visits. An optional third argument threads state to every handler as ctx.state.

walkAsync is the async counterpart: identical traversal and mutation semantics, every handler awaited before the walk moves on.

Builders

One constructor per node type, its fields derived from the node type itself, so a builder can never drift from the AST. Spans default to 0, which ctx.replace fills from the replaced node.

import { b } from "yuku-ast";

b.Identifier({ name: "x" });
b.CallExpression({ callee: b.Identifier({ name: "f" }), arguments: [], optional: false });

Guards

import { is } from "yuku-ast";

is.CallExpression(node);
is.Identifier(node, "require");
is.oneOf(node, ["FunctionDeclaration", "ClassDeclaration"]);
is.Expression(node);
is.StringLiteral(node);
is.StaticMemberExpression(node);
is.Directive(node);

One guard per concrete node type, per alias group, and for the common shapes ESTree folds into one type: literal kinds, member expression kinds, and directives. Every guard accepts null and undefined and narrows.

Modules

import { collectImports, collectExports } from "yuku-ast";

for (const record of collectImports(program)) {
  record.source;   // "./m"
  record.local;    // the local binding name
  record.imported; // "default", "*", or the export name
  record.typeOnly; // import type / import { type x }
  record.phase;    // "source" | "defer" | null
}

for (const record of collectExports(program)) {
  record.exported; // the exported name, null for bare export *
  record.local;    // the backing local name, when there is one
  record.source;   // the re-export specifier, when there is one
  record.typeOnly;
}

Declaration forms expand to one record per bound name, destructuring included. The per-declaration forms collectImportDeclaration and collectExportDeclaration return the records of a single statement, composing with a walk:

walk(program, {
  ImportDeclaration(node) {
    records.push(...collectImportDeclaration(node));
  },
});

Utilities

import {
  nameOf,          // Identifier name or string Literal value
  literalValue,    // string | number | boolean | bigint | RegExp | null
  unwrap,          // strips parens and erased TS assertion wrappers
  isWrapper,       // true for the wrappers unwrap strips
  isCallOf,        // isCallOf(node, "require")
  bindingIdentifiers, // every binding Identifier a pattern introduces
  findAll,         // findAll(program, "CallExpression")
} from "yuku-ast";

Identifiers

import { isValidIdentifier, isIdentifierName, isKeyword } from "yuku-ast";

isValidIdentifier("foo");   // true
isValidIdentifier("class"); // false, reserved
isIdentifierName("class");  // true, syntactically an IdentifierName

Plus isIdentifierStart, isIdentifierChar, isReservedWord, isStrictReservedWord, isStrictBindReservedWord, isStrictBindOnlyReservedWord.

Semantic analysis

yuku-analyzer builds on this walker and adds full semantics: scopes, symbols, resolved references, closure analysis, and cross-file module linking, computed natively. Its module.walk carries the semantic model in context (ctx.scope, ctx.symbol, ctx.reference).