Cache specifier resolutions for speed when emitting many types from the same place (#25112)

* Cache specifier resolutions for speed when emitting many types from the same place

* I swear I accepted this once already
This commit is contained in:
Wesley Wigham 2018-06-22 14:05:07 -07:00 committed by GitHub
parent 38a60ac59b
commit c441451f83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View file

@ -4062,15 +4062,25 @@ namespace ts {
// ambient module, just use declaration/symbol name (fallthrough)
}
else {
if (file.moduleName) {
return `"${file.moduleName}"`;
}
const contextFile = getSourceFileOfNode(getOriginalNode(context!.enclosingDeclaration))!;
return `"${file.moduleName || moduleSpecifiers.getModuleSpecifiers(
symbol,
compilerOptions,
contextFile,
context!.tracker.moduleResolverHost!,
context!.tracker.moduleResolverHost!.getSourceFiles!(),
{ importModuleSpecifierPreference: "non-relative" }
)[0]}"`;
const links = getSymbolLinks(symbol);
let specifier = links.specifierCache && links.specifierCache.get(contextFile.path);
if (!specifier) {
specifier = flatten(moduleSpecifiers.getModuleSpecifiers(
symbol,
compilerOptions,
contextFile,
context!.tracker.moduleResolverHost!,
context!.tracker.moduleResolverHost!.getSourceFiles!(),
{ importModuleSpecifierPreference: "non-relative" }
))[0];
links.specifierCache = links.specifierCache || createMap();
links.specifierCache.set(contextFile.path, specifier);
}
return `"${specifier}"`;
}
}
const declaration = symbol.declarations[0];

View file

@ -3499,6 +3499,7 @@ namespace ts {
enumKind?: EnumKind; // Enum declaration classification
originatingImport?: ImportDeclaration | ImportCall; // Import declaration which produced the symbol, present if the symbol is marked as uncallable but had call signatures in `resolveESModuleSymbol`
lateSymbol?: Symbol; // Late-bound symbol for a computed property
specifierCache?: Map<string>; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings
}
/* @internal */

View file

@ -3056,6 +3056,7 @@ declare namespace ts {
enumKind?: EnumKind;
originatingImport?: ImportDeclaration | ImportCall;
lateSymbol?: Symbol;
specifierCache?: Map<string>;
}
enum EnumKind {
Numeric = 0,