diff --git a/src/compiler/symbolWalker.ts b/src/compiler/symbolWalker.ts index 0ae1e32ea9a..784ee840363 100644 --- a/src/compiler/symbolWalker.ts +++ b/src/compiler/symbolWalker.ts @@ -13,27 +13,34 @@ namespace ts { return getSymbolWalker; function getSymbolWalker(accept: (symbol: Symbol) => boolean = () => true): SymbolWalker { - let visited: Type[] = []; + let visitedTypes: Type[] = []; let visitedSymbols: Symbol[] = []; return { - visitType, - visitSymbol, - reset: (newCallback: (symbol: Symbol) => boolean = () => true) => { - accept = newCallback; - visited = []; + walkType: type => + { + visitedTypes = []; visitedSymbols = []; - } + visitType(type); + return { visitedTypes, visitedSymbols }; + }, + walkSymbol: symbol => + { + visitedTypes = []; + visitedSymbols = []; + visitSymbol(symbol); + return { visitedTypes, visitedSymbols }; + }, }; function visitType(type: Type): void { if (!type) { return; } - if (contains(visited, type)) { + if (contains(visitedTypes, type)) { return; } - visited.push(type); + visitedTypes.push(type); // Reuse visitSymbol to visit the type's symbol, // but be sure to bail on recuring into the type if accept declines the symbol. diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 76922ab98e6..34ae124d636 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2673,9 +2673,8 @@ namespace ts { /* @internal */ export interface SymbolWalker { - visitType(type: Type): void; - visitSymbol(symbol: Symbol): void; - reset(accept?: (symbol: Symbol) => boolean): void; + walkType(root: Type) : { visitedTypes: Type[], visitedSymbols: Symbol[] }; + walkSymbol(root: Symbol) : { visitedTypes: Type[], visitedSymbols: Symbol[] }; } export interface SymbolDisplayBuilder {