Reuse map if module resolution is same for redirected and own files
This commit is contained in:
parent
4b81e37941
commit
3264b64f08
|
@ -436,10 +436,10 @@ namespace ts {
|
|||
set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void;
|
||||
}
|
||||
|
||||
export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache {
|
||||
export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string, options?: CompilerOptions): ModuleResolutionCache {
|
||||
return createModuleResolutionCacheWithMaps(
|
||||
createCacheWithRedirects(),
|
||||
createCacheWithRedirects(),
|
||||
createCacheWithRedirects(options),
|
||||
createCacheWithRedirects(options),
|
||||
currentDirectory,
|
||||
getCanonicalFileName
|
||||
);
|
||||
|
@ -454,7 +454,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
/*@internal*/
|
||||
export function createCacheWithRedirects<T>(): CacheWithRedirects<T> {
|
||||
export function createCacheWithRedirects<T>(options?: CompilerOptions): CacheWithRedirects<T> {
|
||||
const ownMap: Map<T> = createMap();
|
||||
const redirectsMap: Map<Map<T>> = createMap();
|
||||
return {
|
||||
|
@ -471,7 +471,8 @@ namespace ts {
|
|||
const path = redirectedReference.sourceFile.path;
|
||||
let redirects = redirectsMap.get(path);
|
||||
if (!redirects) {
|
||||
redirects = createMap();
|
||||
// Reuse map if redirected reference map uses same resolution
|
||||
redirects = !options || optionsHaveModuleResolutionChanges(options, redirectedReference.commandLine.options) ? createMap() : ownMap;
|
||||
redirectsMap.set(path, redirects);
|
||||
}
|
||||
return redirects;
|
||||
|
|
|
@ -773,7 +773,7 @@ namespace ts {
|
|||
});
|
||||
}
|
||||
else {
|
||||
moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x));
|
||||
moduleResolutionCache = createModuleResolutionCache(currentDirectory, x => host.getCanonicalFileName(x), options);
|
||||
const loader = (moduleName: string, containingFile: string, redirectedReference: ResolvedProjectReference | undefined) => resolveModuleName(moduleName, containingFile, options, host, moduleResolutionCache, redirectedReference).resolvedModule!; // TODO: GH#18217
|
||||
resolveModuleNamesWorker = (moduleNames, containingFile, _reusedNames, redirectedReference) => loadWithLocalCache<ResolvedModuleFull>(Debug.assertEachDefined(moduleNames), containingFile, redirectedReference, loader);
|
||||
}
|
||||
|
|
|
@ -101,7 +101,12 @@ namespace ts {
|
|||
}
|
||||
|
||||
export function changesAffectModuleResolution(oldOptions: CompilerOptions, newOptions: CompilerOptions): boolean {
|
||||
return oldOptions.configFilePath !== newOptions.configFilePath || moduleResolutionOptionDeclarations.some(o =>
|
||||
return oldOptions.configFilePath !== newOptions.configFilePath ||
|
||||
optionsHaveModuleResolutionChanges(oldOptions, newOptions);
|
||||
}
|
||||
|
||||
export function optionsHaveModuleResolutionChanges(oldOptions: CompilerOptions, newOptions: CompilerOptions) {
|
||||
return moduleResolutionOptionDeclarations.some(o =>
|
||||
!isJsonEqual(getCompilerOptionValue(oldOptions, o), getCompilerOptionValue(newOptions, o)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue