Skip to content

Commit

Permalink
Reuse map if module resolution is same for redirected and own files
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat committed Apr 24, 2019
1 parent 4b81e37 commit 3264b64
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/compiler/moduleNameResolver.ts
Expand Up @@ -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
);
Expand All @@ -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 {
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Expand Up @@ -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);
}
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/utilities.ts
Expand Up @@ -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)));
}

Expand Down

0 comments on commit 3264b64

Please sign in to comment.