handle failed lookups

This commit is contained in:
Klaus Meinhardt
2018-08-08 20:45:31 +02:00
parent 95082e4743
commit 20442fe363
2 changed files with 15 additions and 6 deletions

View File

@@ -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;

View File

@@ -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", () => {