@@ -96,9 +96,14 @@ namespace ts {
9696 } ;
9797 }
9898
99+ function tryParsePatterns ( paths : MapLike < string [ ] > ) : ( string | Pattern ) [ ] {
100+ return mapDefined ( getOwnKeys ( paths ) , path => tryParsePattern ( path ) ) ;
101+ }
102+
99103 interface ModuleResolutionState {
100104 host : ModuleResolutionHost ;
101105 compilerOptions : CompilerOptions ;
106+ compilerPathPatterns ?: ( string | Pattern ) [ ] ;
102107 traceEnabled : boolean ;
103108 failedLookupLocations : Push < string > ;
104109 resultFromCache ?: ResolvedModuleWithFailedLookupLocations ;
@@ -961,7 +966,10 @@ namespace ts {
961966 trace ( state . host , Diagnostics . paths_option_is_specified_looking_for_a_pattern_to_match_module_name_0 , moduleName ) ;
962967 }
963968 const baseDirectory = getPathsBasePath ( state . compilerOptions , state . host ) ! ; // Always defined when 'paths' is defined
964- return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , loader , /*onlyRecordFailures*/ false , state ) ;
969+ if ( ! state . compilerPathPatterns ) {
970+ state . compilerPathPatterns = tryParsePatterns ( paths ) ;
971+ }
972+ return tryLoadModuleUsingPaths ( extensions , moduleName , baseDirectory , paths , state . compilerPathPatterns , loader , /*onlyRecordFailures*/ false , state ) ;
965973 }
966974 }
967975
@@ -1400,7 +1408,8 @@ namespace ts {
14001408 if ( state . traceEnabled ) {
14011409 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 ) ;
14021410 }
1403- const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , versionPaths . paths , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
1411+ const paths = versionPaths . paths ;
1412+ const result = tryLoadModuleUsingPaths ( extensions , moduleName , candidate , paths , tryParsePatterns ( paths ) , loader , onlyRecordFailuresForPackageFile || onlyRecordFailuresForIndex , state ) ;
14041413 if ( result ) {
14051414 return removeIgnoredPackageId ( result . value ) ;
14061415 }
@@ -1536,7 +1545,8 @@ namespace ts {
15361545 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 , packageInfo . versionPaths . version , version , rest ) ;
15371546 }
15381547 const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists ( packageDirectory , state . host ) ;
1539- const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , packageInfo . versionPaths . paths , loader , ! packageDirectoryExists , state ) ;
1548+ const paths = packageInfo . versionPaths . paths ;
1549+ const fromPaths = tryLoadModuleUsingPaths ( extensions , rest , packageDirectory , paths , tryParsePatterns ( paths ) , loader , ! packageDirectoryExists , state ) ;
15401550 if ( fromPaths ) {
15411551 return fromPaths . value ;
15421552 }
@@ -1546,8 +1556,8 @@ namespace ts {
15461556 return loader ( extensions , candidate , ! nodeModulesDirectoryExists , state ) ;
15471557 }
15481558
1549- function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1550- const matchedPattern = matchPatternOrExact ( getOwnKeys ( paths ) , moduleName ) ;
1559+ function tryLoadModuleUsingPaths ( extensions : Extensions , moduleName : string , baseDirectory : string , paths : MapLike < string [ ] > , pathPatterns : ( string | Pattern ) [ ] , loader : ResolutionKindSpecificLoader , onlyRecordFailures : boolean , state : ModuleResolutionState ) : SearchResult < Resolved > {
1560+ const matchedPattern = matchPatternOrExact ( pathPatterns , moduleName ) ;
15511561 if ( matchedPattern ) {
15521562 const matchedStar = isString ( matchedPattern ) ? undefined : matchedText ( matchedPattern , moduleName ) ;
15531563 const matchedPatternText = isString ( matchedPattern ) ? matchedPattern : patternText ( matchedPattern ) ;
0 commit comments