From 20442fe3632fad65631df7e8f6a38f21734f3f29 Mon Sep 17 00:00:00 2001 From: Klaus Meinhardt Date: Wed, 8 Aug 2018 20:45:31 +0200 Subject: [PATCH] handle failed lookups --- src/compiler/moduleNameResolver.ts | 11 +++++------ src/testRunner/unittests/moduleResolution.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 5a288090e2f..f75e800e474 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -403,10 +403,12 @@ namespace ts { const resolvedFileName = result.resolvedModule && result.resolvedModule.resolvedFileName; // find common prefix between directory and resolved file name - // this common prefix should be the shorted path that has the same resolution + // this common prefix should be the shortest path that has the same resolution // directory: /a/b/c/d/e // resolvedFileName: /a/b/foo.d.ts - const commonPrefix = getCommonPrefix(path, resolvedFileName); + // commonPrefix: /a/b + // for failed lookups use the root directory as commonPrefix + const commonPrefix = resolvedFileName ? getCommonPrefix(path, resolvedFileName) : path.substr(0, getRootLength(path)); if (!commonPrefix) { return; } @@ -421,10 +423,7 @@ namespace ts { } } - function getCommonPrefix(directory: Path, resolution: string | undefined) { - if (resolution === undefined) { - return undefined; - } + function getCommonPrefix(directory: Path, resolution: string) { const resolutionDirectory = toPath(getDirectoryPath(resolution), currentDirectory, getCanonicalFileName); let current = directory; diff --git a/src/testRunner/unittests/moduleResolution.ts b/src/testRunner/unittests/moduleResolution.ts index a027f7215ed..3c5ab7682ac 100644 --- a/src/testRunner/unittests/moduleResolution.ts +++ b/src/testRunner/unittests/moduleResolution.ts @@ -264,6 +264,16 @@ namespace ts { assert.isDefined(cache.get("c:/foo")); assert.isUndefined(cache.get("c:/")); assert.isUndefined(cache.get("d:/")); + + cache = resolutionCache.getOrCreateCacheForModuleName("f"); + cache.set("/foo/bar/baz", { + resolvedModule: undefined, + failedLookupLocations: [], + }); + assert.isDefined(cache.get("/foo/bar/baz")); + assert.isDefined(cache.get("/foo/bar")); + assert.isDefined(cache.get("/foo")); + assert.isDefined(cache.get("/")); }); it("load module as file - ts files not loaded", () => {