import type { Node, NodeOfType, NodeType } from "@yuku-toolchain/types"; import { type AliasMap, type AliasName } from "./aliases.js"; import { WalkContext } from "./context.js"; /** A visitor function for one node type or alias. */ export type WalkHandler = (node: T, ctx: WalkContext) => void; /** Enter and leave hooks for one node type or alias. */ export interface WalkHooks { enter?: WalkHandler; leave?: WalkHandler; } type Visitor = WalkHandler | WalkHooks; /** * Handlers keyed by node `type`, by alias (`Expression`, `Function`, * ...), or the universal `enter` / `leave`. A bare function is an enter * handler. Per node the order is universal `enter`, alias enters in * visitor key order, the typed enter, children, then the mirror for * leave. */ export type Visitors = { [K in NodeType]?: Visitor, S>; } & { [A in AliasName]?: Visitor; } & { enter?: WalkHandler; leave?: WalkHandler; }; /** * Walk an AST depth-first, dispatching to typed visitors and mutating * in place. Traversal order is driven by tables generated from the * parser's AST definition, so it can never drift. Returns the root. */ export declare function walk(root: T, visitors: Visitors, state?: S): T; /** * The async counterpart of {@link walk}: identical traversal order and * mutation semantics, with every handler awaited before the walk moves * on. Resolves to the root. */ export declare function walkAsync(root: T, visitors: AsyncVisitors, state?: S): Promise; /** An async visitor function for one node type or alias. */ export type AsyncWalkHandler = (node: T, ctx: WalkContext) => void | Promise; /** Enter and leave hooks for one node type or alias in an async walk. */ export interface AsyncWalkHooks { enter?: AsyncWalkHandler; leave?: AsyncWalkHandler; } /** {@link Visitors} whose handlers may return promises. */ export type AsyncVisitors = { [K in NodeType]?: AsyncWalkHandler, S> | AsyncWalkHooks, S>; } & { [A in AliasName]?: AsyncWalkHandler | AsyncWalkHooks; } & { enter?: AsyncWalkHandler; leave?: AsyncWalkHandler; }; export declare function _walk(root: Node, visitors: Visitors | AsyncVisitors, state: unknown, ctx: WalkContext): void; export declare function _walkAsync(root: Node, visitors: AsyncVisitors, state: unknown, ctx: WalkContext): Promise; export {};