import type * as t from "@babel/types";
import type { NodePath } from "./index";
import type { VirtualTypeAliases } from "./path/lib/virtual-types";
export type Visitor = VisitNodeObject & {
[Type in t.Node["type"]]?: VisitNode>;
} & {
[K in keyof t.Aliases]?: VisitNode;
} & {
[K in keyof VirtualTypeAliases]?: VisitNode;
} & {
[K in keyof InternalVisitorFlags]?: InternalVisitorFlags[K];
} & {
// Babel supports `NodeTypesWithoutComment | NodeTypesWithoutComment | ... ` but it is
// too complex for TS. So we type it as a general visitor only if the key contains `|`
// this is good enough for non-visitor traverse options e.g. `noScope`
[k: `${string}|${string}`]: VisitNode;
};
/** @internal */
type InternalVisitorFlags = {
_exploded?: boolean;
_verified?: boolean;
};
export type VisitNode =
| VisitNodeFunction
| VisitNodeObject;
export type VisitNodeFunction = (
this: S,
path: NodePath
,
state: S,
) => void;
export interface VisitNodeObject {
enter?: VisitNodeFunction;
exit?: VisitNodeFunction;
}