Code refactoring for module resolution api (#51675)

* Refactoring so CacheWithRedirects has Key and Value type parameters

* ModuleResolutionCache or TypeRefDirectiveCache will look in directory before solving, so ResolutionCache doesnt need this check

* Test showing module resolution is not shared because resolution cache doesnt update own options

* Enable traceResolution on some of the project reference tests

* Simplify CacheWithRedirects and ensure the options are set in all common scenarios so cache can be shared between redirects
This commit is contained in:
Sheetal Nandi
2022-12-01 10:17:58 -08:00
committed by GitHub
parent 9089d5390a
commit 7b7f6a75ea
18 changed files with 1494 additions and 342 deletions
+8 -10
View File
@@ -814,17 +814,16 @@ export function loadWithTypeDirectiveCache<T>(names: string[] | readonly FileRef
return [];
}
const resolutions: T[] = [];
const cache = new Map<string, T>();
const cache = createModeAwareCache<T>();
for (const name of names) {
let result: T;
const mode = getModeForFileReference(name, containingFileMode);
const strName = getResolutionName(name);
const cacheKey = mode !== undefined ? `${mode}|${strName}` : strName;
if (cache.has(cacheKey)) {
result = cache.get(cacheKey)!;
if (cache.has(strName, mode)) {
result = cache.get(strName, mode)!;
}
else {
cache.set(cacheKey, result = loader(strName, containingFile, redirectedReference, mode));
cache.set(strName, mode, result = loader(strName, containingFile, redirectedReference, mode));
}
resolutions.push(result);
}
@@ -944,7 +943,7 @@ export function loadWithModeAwareCache<T>(names: readonly StringLiteralLike[] |
return [];
}
const resolutions: T[] = [];
const cache = new Map<string, T>();
const cache = createModeAwareCache<T>();
let i = 0;
for (const entry of resolutionInfo ? resolutionInfo.names : names) {
let result: T;
@@ -953,12 +952,11 @@ export function loadWithModeAwareCache<T>(names: readonly StringLiteralLike[] |
getModeForResolutionAtIndex(containingFile, i);
i++;
const name = isString(entry) ? entry : entry.text;
const cacheKey = mode !== undefined ? `${mode}|${name}` : name;
if (cache.has(cacheKey)) {
result = cache.get(cacheKey)!;
if (cache.has(name, mode)) {
result = cache.get(name, mode)!;
}
else {
cache.set(cacheKey, result = loader(name, mode, containingFileName, redirectedReference));
cache.set(name, mode, result = loader(name, mode, containingFileName, redirectedReference));
}
resolutions.push(result);
}