import type * as swc from '@swc/types'; type AggregatedNode = { ClassMember: swc.ClassMember; Declaration: swc.Declaration; DefaultDecl: swc.DefaultDecl; ExportSpecifier: swc.ExportSpecifier; Expression: swc.Expression; ImportSpecifier: swc.ImportSpecifier; JSXAttrValue: swc.JSXAttrValue; JSXElementChild: swc.JSXElementChild; JSXElementName: swc.JSXElementName; Literal: swc.Literal; ModuleDeclaration: swc.ModuleDeclaration; ObjectPatternProperty: swc.ObjectPatternProperty; Pattern: swc.Pattern; Property: swc.Property; PropertyName: swc.PropertyName; Statement: swc.Statement; TsFnParameter: swc.TsFnParameter; TsParameterPropertyParameter: swc.TsParameterPropertyParameter; TsType: swc.TsType; TsTypeElement: swc.TsTypeElement; }; export type AnyNode = AggregatedNode[keyof AggregatedNode] | swc.CatchClause | swc.Decorator | swc.Import | swc.JSXAttribute | swc.JSXClosingElement | swc.JSXClosingFragment | swc.JSXOpeningElement | swc.JSXOpeningFragment | swc.Module | swc.Param | swc.Script | swc.SpreadElement | swc.Super | swc.SwitchCase | swc.TemplateElement | swc.TsConstructorType | swc.TsEnumMember | swc.TsExpressionWithTypeArguments | swc.TsExternalModuleReference | swc.TsFunctionType | swc.TsInterfaceBody | swc.TsIntersectionType | swc.TsLiteral | swc.TsModuleBlock | swc.TsNamespaceDeclaration | swc.TsParameterProperty | swc.TsQualifiedName | swc.TsTupleElement | swc.TsTypeAnnotation | swc.TsTypeParameter | swc.TsTypeParameterDeclaration | swc.TsTypeParameterInstantiation | swc.TsUnionType | swc.VariableDeclarator; type OptionalSpan = T extends { span: swc.Span; } ? Omit & { span: swc.Span | undefined; } : T & { span?: swc.Span; }; /** * Not all SWC nodes with a `type` have a `span` in practice. * This wrapper mirrors runtime behavior without forcing consumers * to defensively narrow `span` before accessing it. */ export type Node = OptionalSpan; export type NodeType = AnyNode['type']; export type NodeByType = Extract; export type Callback = (node: Node, state: State) => void; export type RecursiveVisitors = { [Type in NodeType]?: (node: NodeByType, state: State, callback: Callback) => void; }; export type SimpleVisitors = { [Type in NodeType]?: (node: NodeByType, state: State) => void; } & { [type in keyof AggregatedNode as `Aggregated${type}`]?: never; }; export type AncestorVisitors = { [Type in NodeType]?: (node: NodeByType, state: State, ancestors: Node[]) => void; } & { [type in keyof AggregatedNode as `Aggregated${type}`]?: never; }; export type Ancestor = (node: Node, visitors: AncestorVisitors, base?: RecursiveVisitors, state?: State) => void; /** * does a 'simple' walk over a tree * @param node the AST node to walk * @param visitors an object with properties whose names correspond to node types in the {@link https://github.com/swc-project/swc/tree/main/packages/types | SWC spec}. The properties should contain functions that will be called with the node object and, if applicable the state at that point. * @param base a walker algorithm * @param state a start state. The default walker will simply visit all statements and expressions and not produce a meaningful state. (An example of a use of state is to track scope at each point in the tree.) */ export type Simple = (node: Node, visitors: SimpleVisitors, base?: RecursiveVisitors, state?: State) => void; export declare function isNodeOfType(node: swc.Node | undefined, type: T): node is NodeByType; export declare function assertNodeType(node: swc.Node, type: T): asserts node is NodeByType; export {};