mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 02:15:10 -05:00
handle failed lookups
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user