Skip to content

Commit 00b9ccd

Browse files
committed
Move cache to ConfigFileSpecs
1 parent b945b9b commit 00b9ccd

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,7 @@ namespace ts {
25332533
validatedFilesSpec: filter(filesSpecs, isString),
25342534
validatedIncludeSpecs,
25352535
validatedExcludeSpecs,
2536+
pathPatterns: undefined, // Initialized on first use
25362537
};
25372538
}
25382539

src/compiler/moduleNameResolver.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ namespace ts {
9696
};
9797
}
9898

99-
function tryParsePatterns(paths: MapLike<string[]>): (string | Pattern)[] {
100-
return mapDefined(getOwnKeys(paths), path => tryParsePattern(path));
101-
}
102-
10399
interface ModuleResolutionState {
104100
host: ModuleResolutionHost;
105101
compilerOptions: CompilerOptions;
106-
compilerPathPatterns?: (string | Pattern)[];
107102
traceEnabled: boolean;
108103
failedLookupLocations: Push<string>;
109104
resultFromCache?: ResolvedModuleWithFailedLookupLocations;
@@ -957,7 +952,7 @@ namespace ts {
957952
}
958953

959954
function tryLoadModuleUsingPathsIfEligible(extensions: Extensions, moduleName: string, loader: ResolutionKindSpecificLoader, state: ModuleResolutionState) {
960-
const { baseUrl, paths } = state.compilerOptions;
955+
const { baseUrl, paths, configFile } = state.compilerOptions;
961956
if (paths && !pathIsRelative(moduleName)) {
962957
if (state.traceEnabled) {
963958
if (baseUrl) {
@@ -966,10 +961,14 @@ namespace ts {
966961
trace(state.host, Diagnostics.paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0, moduleName);
967962
}
968963
const baseDirectory = getPathsBasePath(state.compilerOptions, state.host)!; // Always defined when 'paths' is defined
969-
if (!state.compilerPathPatterns) {
970-
state.compilerPathPatterns = tryParsePatterns(paths);
964+
let pathPatterns: readonly (string | Pattern)[] | undefined;
965+
if (configFile?.configFileSpecs) {
966+
pathPatterns = configFile.configFileSpecs.pathPatterns;
967+
if (!pathPatterns) {
968+
configFile.configFileSpecs.pathPatterns = pathPatterns = tryParsePatterns(paths);
969+
}
971970
}
972-
return tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, state.compilerPathPatterns, loader, /*onlyRecordFailures*/ false, state);
971+
return tryLoadModuleUsingPaths(extensions, moduleName, baseDirectory, paths, pathPatterns, loader, /*onlyRecordFailures*/ false, state);
973972
}
974973
}
975974

@@ -1409,7 +1408,7 @@ namespace ts {
14091408
trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, versionPaths.version, version, moduleName);
14101409
}
14111410
const paths = versionPaths.paths;
1412-
const result = tryLoadModuleUsingPaths(extensions, moduleName, candidate, paths, tryParsePatterns(paths), loader, onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex, state);
1411+
const result = tryLoadModuleUsingPaths(extensions, moduleName, candidate, paths, /*pathPatterns*/ undefined, loader, onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex, state);
14131412
if (result) {
14141413
return removeIgnoredPackageId(result.value);
14151414
}
@@ -1546,7 +1545,7 @@ namespace ts {
15461545
}
15471546
const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host);
15481547
const paths = packageInfo.versionPaths.paths;
1549-
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, paths, tryParsePatterns(paths), loader, !packageDirectoryExists, state);
1548+
const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, paths, /*pathPatterns*/ undefined, loader, !packageDirectoryExists, state);
15501549
if (fromPaths) {
15511550
return fromPaths.value;
15521551
}
@@ -1556,7 +1555,8 @@ namespace ts {
15561555
return loader(extensions, candidate, !nodeModulesDirectoryExists, state);
15571556
}
15581557

1559-
function tryLoadModuleUsingPaths(extensions: Extensions, moduleName: string, baseDirectory: string, paths: MapLike<string[]>, pathPatterns: (string | Pattern)[], loader: ResolutionKindSpecificLoader, onlyRecordFailures: boolean, state: ModuleResolutionState): SearchResult<Resolved> {
1558+
function tryLoadModuleUsingPaths(extensions: Extensions, moduleName: string, baseDirectory: string, paths: MapLike<string[]>, pathPatterns: readonly (string | Pattern)[] | undefined, loader: ResolutionKindSpecificLoader, onlyRecordFailures: boolean, state: ModuleResolutionState): SearchResult<Resolved> {
1559+
pathPatterns ||= tryParsePatterns(paths);
15601560
const matchedPattern = matchPatternOrExact(pathPatterns, moduleName);
15611561
if (matchedPattern) {
15621562
const matchedStar = isString(matchedPattern) ? undefined : matchedText(matchedPattern, moduleName);

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6195,6 +6195,7 @@ namespace ts {
61956195
validatedFilesSpec: readonly string[] | undefined;
61966196
validatedIncludeSpecs: readonly string[] | undefined;
61976197
validatedExcludeSpecs: readonly string[] | undefined;
6198+
pathPatterns: readonly (string | Pattern)[] | undefined;
61986199
}
61996200

62006201
/* @internal */

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6786,6 +6786,10 @@ namespace ts {
67866786
};
67876787
}
67886788

6789+
export function tryParsePatterns(paths: MapLike<string[]>): (string | Pattern)[] {
6790+
return mapDefined(getOwnKeys(paths), path => tryParsePattern(path));
6791+
}
6792+
67896793
export function positionIsSynthesized(pos: number): boolean {
67906794
// This is a fast way of testing the following conditions:
67916795
// pos === undefined || pos === null || isNaN(pos) || pos < 0;

0 commit comments

Comments
 (0)