UNPKG

@knighted/walk

Version:

Walk an oxc-parser AST with nodes typed correctly.

29 lines (28 loc) 1.79 kB
import type { SyncHandler, AsyncHandler } from 'estree-walker'; import type { Program, Node } from 'oxc-parser'; import type { Node as ESTreeNode } from 'estree'; type WalkerCallback = (this: ThisParameterType<SyncHandler>, node: Node, parent: Node | null, key: Parameters<SyncHandler>['2'], index: Parameters<SyncHandler>['3']) => void; type AsyncWalkerCallback = (this: ThisParameterType<AsyncHandler>, node: Node, parent: Node | null, key: Parameters<AsyncHandler>['2'], index: Parameters<AsyncHandler>['3']) => Promise<void>; type AncestorWalkerCallback = (this: ThisParameterType<SyncHandler>, node: Node, ancestors: Node[], key: Parameters<SyncHandler>['2'], index: Parameters<SyncHandler>['3']) => void; type AsyncAncestorWalkerCallback = (this: ThisParameterType<AsyncHandler>, node: Node, ancestors: Node[], key: Parameters<AsyncHandler>['2'], index: Parameters<AsyncHandler>['3']) => Promise<void>; type AsyncWalkOptions = { enter?: AsyncWalkerCallback; leave?: AsyncWalkerCallback; }; type AsyncAncestorWalkOptions = { enter?: AsyncAncestorWalkerCallback; leave?: AsyncAncestorWalkerCallback; }; type AncestorWalkOptions = { enter?: AncestorWalkerCallback; leave?: AncestorWalkerCallback; }; type WalkOptions = { enter?: WalkerCallback; leave?: WalkerCallback; }; declare const walk: (ast: Program | Node, opts: WalkOptions) => Promise<ESTreeNode | null>; declare const ancestorWalk: (ast: Program | Node, opts: AncestorWalkOptions) => Promise<ESTreeNode | null>; declare const asyncWalk: (ast: Program | Node, opts: AsyncWalkOptions) => Promise<ESTreeNode | null>; declare const asyncAncestorWalk: (ast: Program | Node, opts: AsyncAncestorWalkOptions) => Promise<ESTreeNode | null>; export { walk, asyncWalk, ancestorWalk, asyncAncestorWalk };