mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
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:
+8
-10
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user