Fix top-level enter and exit visitor types (#18129)

This commit is contained in:
Rayan Salhab
2026-07-21 21:45:45 +02:00
committed by GitHub
parent 26ff333af8
commit 3233a2a622
2 changed files with 19 additions and 1 deletions
+5 -1
View File
@@ -84,9 +84,13 @@ type ToNode<S extends string, N = Split<S>> = N extends keyof t.Aliases
type OptionKeys = keyof TraverseOptions;
type VisitNodeObjectKeys = keyof VisitNodeObject<unknown, t.Node>;
export type VisitorProp<S, K extends string> = K extends OptionKeys
? TraverseOptions[K]
: VisitNode<S, ToNode<K>>;
: K extends VisitNodeObjectKeys
? VisitNodeObject<S, t.Node>[K]
: VisitNode<S, ToNode<K>>;
export type TraverseOptions = {
scope?: Scope;
+14
View File
@@ -95,6 +95,20 @@ describe("traverse", () => {
});
describe("Visitor", () => {
it("top-level enter and exit", () => {
traverse({} as t.Node, {
enter(path) {
expect(path).type.toBe<NodePath<t.Node>>();
expect(path.type).type.toBe<t.Node["type"]>();
},
exit(path) {
expect(path).type.toBe<NodePath<t.Node>>();
expect(path.type).type.toBe<t.Node["type"]>();
},
noScope: true,
});
});
describe("Union types", () => {
it("traverse", () => {
traverse({} as t.Node, {