From 3f1e00097cf442f56050d86bf3c8c9f88ccb7849 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 20 Jun 2018 17:25:33 -0700 Subject: [PATCH 1/2] Cache specifier resolutions for speed when emitting many types from the same place --- src/compiler/checker.ts | 26 ++++++++++++++++++-------- src/compiler/types.ts | 1 + 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ff1da5db91102..236f88bff3e3e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4091,15 +4091,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]; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index b1e52d68bc01e..268fa50154f96 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3492,6 +3492,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; // For symbols corresponding to external modules, a cache of incoming path -> module specifier name mappings } /* @internal */ From 392a9b016e62df0743516c0753b4ca652d67e2b1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 20 Jun 2018 19:07:08 -0700 Subject: [PATCH 2/2] I swear I accepted this once already --- tests/baselines/reference/api/tsserverlibrary.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 114b2341fa95e..e60d6865fc345 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3048,6 +3048,7 @@ declare namespace ts { enumKind?: EnumKind; originatingImport?: ImportDeclaration | ImportCall; lateSymbol?: Symbol; + specifierCache?: Map; } enum EnumKind { Numeric = 0,