mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Reshape SymbolWalker API
1. Expose visited types and symbols 2. Automatically reset before each walk
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user