Skip to content

Commit d2dc17d

Browse files
committed
fix handling if there is no commonPrefix
1 parent 20442fe commit d2dc17d

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/compiler/moduleNameResolver.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,8 @@ namespace ts {
407407
// directory: /a/b/c/d/e
408408
// resolvedFileName: /a/b/foo.d.ts
409409
// commonPrefix: /a/b
410-
// for failed lookups use the root directory as commonPrefix
411-
const commonPrefix = resolvedFileName ? getCommonPrefix(path, resolvedFileName) : path.substr(0, getRootLength(path));
412-
if (!commonPrefix) {
413-
return;
414-
}
410+
// for failed lookups cache the result for every directory up to root
411+
const commonPrefix = resolvedFileName && getCommonPrefix(path, resolvedFileName);
415412
let current = path;
416413
while (current !== commonPrefix) {
417414
const parent = getDirectoryPath(current);

src/testRunner/unittests/moduleResolution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ namespace ts {
262262
failedLookupLocations: [],
263263
});
264264
assert.isDefined(cache.get("c:/foo"));
265-
assert.isUndefined(cache.get("c:/"));
265+
assert.isDefined(cache.get("c:/"));
266266
assert.isUndefined(cache.get("d:/"));
267267

268268
cache = resolutionCache.getOrCreateCacheForModuleName("f");

0 commit comments

Comments
 (0)