Skip to content

Commit 801c1f7

Browse files
committed
Reshape SymbolWalker API
1. Expose visited types and symbols 2. Automatically reset before each walk
1 parent 2c8a5c4 commit 801c1f7

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/compiler/symbolWalker.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@ namespace ts {
1313
return getSymbolWalker;
1414

1515
function getSymbolWalker(accept: (symbol: Symbol) => boolean = () => true): SymbolWalker {
16-
let visited: Type[] = [];
16+
let visitedTypes: Type[] = [];
1717
let visitedSymbols: Symbol[] = [];
1818

1919
return {
20-
visitType,
21-
visitSymbol,
22-
reset: (newCallback: (symbol: Symbol) => boolean = () => true) => {
23-
accept = newCallback;
24-
visited = [];
20+
walkType: type =>
21+
{
22+
visitedTypes = [];
2523
visitedSymbols = [];
26-
}
24+
visitType(type);
25+
return { visitedTypes, visitedSymbols };
26+
},
27+
walkSymbol: symbol =>
28+
{
29+
visitedTypes = [];
30+
visitedSymbols = [];
31+
visitSymbol(symbol);
32+
return { visitedTypes, visitedSymbols };
33+
},
2734
};
2835

2936
function visitType(type: Type): void {
3037
if (!type) {
3138
return;
3239
}
33-
if (contains(visited, type)) {
40+
if (contains(visitedTypes, type)) {
3441
return;
3542
}
36-
visited.push(type);
43+
visitedTypes.push(type);
3744

3845
// Reuse visitSymbol to visit the type's symbol,
3946
// but be sure to bail on recuring into the type if accept declines the symbol.

src/compiler/types.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,9 +2673,8 @@ namespace ts {
26732673

26742674
/* @internal */
26752675
export interface SymbolWalker {
2676-
visitType(type: Type): void;
2677-
visitSymbol(symbol: Symbol): void;
2678-
reset(accept?: (symbol: Symbol) => boolean): void;
2676+
walkType(root: Type) : { visitedTypes: Type[], visitedSymbols: Symbol[] };
2677+
walkSymbol(root: Symbol) : { visitedTypes: Type[], visitedSymbols: Symbol[] };
26792678
}
26802679

26812680
export interface SymbolDisplayBuilder {

0 commit comments

Comments
 (0)