Skip to content

Commit

Permalink
moduleNameResolver: fix invalid assertion and avoid unnecessary work
Browse files Browse the repository at this point in the history
  • Loading branch information
ajafff committed Aug 9, 2018
1 parent a36a53b commit ab9e0f8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ namespace ts {
}

function getOrCreateCacheForModuleName(nonRelativeModuleName: string): PerModuleNameCache {
if (isExternalModuleNameRelative(nonRelativeModuleName)) {
return undefined!; // TODO: GH#18217
}
let perModuleNameCache = moduleNameToDirectoryMap.get(nonRelativeModuleName);
if (!perModuleNameCache) {
perModuleNameCache = createPerModuleNameCache();
Expand Down Expand Up @@ -492,10 +489,9 @@ namespace ts {

if (perFolderCache) {
perFolderCache.set(moduleName, result);
// put result in per-module name cache
const perModuleNameCache = cache!.getOrCreateCacheForModuleName(moduleName);
if (perModuleNameCache) {
perModuleNameCache.set(containingDirectory, result);
if (!isExternalModuleNameRelative(moduleName)) {
// put result in per-module name cache
cache!.getOrCreateCacheForModuleName(moduleName).set(containingDirectory, result);
}
}
}
Expand Down Expand Up @@ -1252,9 +1248,9 @@ namespace ts {
if (resolvedUsingSettings) {
return { value: resolvedUsingSettings };
}
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);

if (!isExternalModuleNameRelative(moduleName)) {
const perModuleNameCache = cache && cache.getOrCreateCacheForModuleName(moduleName);
// Climb up parent directories looking for a module.
const resolved = forEachAncestorDirectory(containingDirectory, directory => {
const resolutionFromCache = tryFindNonRelativeModuleNameInCache(perModuleNameCache, moduleName, directory, traceEnabled, host, failedLookupLocations);
Expand Down

0 comments on commit ab9e0f8

Please sign in to comment.