@@ -77,6 +77,7 @@ import {
77
77
Pattern ,
78
78
patternText ,
79
79
perfLogger ,
80
+ Program ,
80
81
Push ,
81
82
readJson ,
82
83
removeExtension ,
@@ -1184,6 +1185,49 @@ export function createPerDirectoryAndNonRelativeNameCache<T>(currentDirectory: s
1184
1185
}
1185
1186
}
1186
1187
1188
+ /** @internal */
1189
+ export function toPerDirectoryAndNonRelativeNameCache < T , U , V > (
1190
+ program : Program ,
1191
+ perDirectoryAndNonRelativeNameCache : PerDirectoryAndNonRelativeNameCache < T > | undefined ,
1192
+ getResolvedFileName : ( resolved : T ) => string | undefined ,
1193
+ cache : ModeAwareCache < T > | undefined ,
1194
+ fOrPath : SourceFile | Path ,
1195
+ withRedirects : ( redirectedReference : ResolvedProjectReference | undefined ) => U ,
1196
+ forEachResolution : ( r : T , name : string , mode : ResolutionMode , dirPath : Path , redirectedReference : ResolvedProjectReference | undefined , redirectsResult : U ) => V | undefined ,
1197
+ ancestoryWorker : ( ancestorPath : Path , mapOfRedirects : Map < Path , ModeAwareCache < T > > | undefined , name : string , mode : ResolutionMode ) => void ,
1198
+ ) {
1199
+ if ( ! cache ?. size ( ) ) return perDirectoryAndNonRelativeNameCache ;
1200
+ let dirPath : Path , redirectedReference : ResolvedProjectReference | undefined ;
1201
+ if ( ! isString ( fOrPath ) ) {
1202
+ redirectedReference = program . getRedirectReferenceForResolution ( fOrPath ) ;
1203
+ dirPath = getDirectoryPath ( fOrPath . path ) ;
1204
+ }
1205
+ else {
1206
+ dirPath = getDirectoryPath ( fOrPath ) ;
1207
+ }
1208
+ const redirectsResult = withRedirects ( redirectedReference ) ;
1209
+ const mapForRedirects = perDirectoryAndNonRelativeNameCache ?. perDirectory . perDirectoryMap . getMapOfCacheRedirects ( redirectedReference ) ;
1210
+ let dirCache = mapForRedirects ?. get ( dirPath ) ;
1211
+ cache . forEach ( ( resolution , name , mode ) => {
1212
+ if ( forEachResolution ( resolution , name , mode , dirPath , redirectedReference , redirectsResult ) ) return ;
1213
+ if ( dirCache ?. has ( name , mode ) ) return ;
1214
+ ( dirCache ??= ( perDirectoryAndNonRelativeNameCache ??= createPerDirectoryAndNonRelativeNameCache (
1215
+ program . getCurrentDirectory ( ) ,
1216
+ program . getCanonicalFileName ,
1217
+ program . getCompilerOptions ( ) ,
1218
+ getResolvedFileName ,
1219
+ ) ) . perDirectory . getOrCreateCacheForDirectoryWithPath ( dirPath , redirectedReference ) ) . set ( name , mode , resolution ) ;
1220
+ if ( ! isExternalModuleNameRelative ( name ) ) {
1221
+ perDirectoryAndNonRelativeNameCache ! . nonRelativeName . getOrCreateCacheForNonRelativeName ( name , mode , redirectedReference ) . setWithPath (
1222
+ dirPath ,
1223
+ resolution ,
1224
+ ancestoryWorker === noop ? noop : ancestorPath => ancestoryWorker ( ancestorPath , mapForRedirects , name , mode ) ,
1225
+ ) ;
1226
+ }
1227
+ } ) ;
1228
+
5592
return perDirectoryAndNonRelativeNameCache ;
1229
+ }
1230
+
1187
1231
interface ModuleOrTypeReferenceResolutionCache < T > extends PerDirectoryResolutionCache < T > , NonRelativeNameResolutionCache < T > , PackageJsonInfoCache {
1188
1232
getPackageJsonInfoCache ( ) : PackageJsonInfoCache ;
1189
1233
clearAllExceptPackageJsonInfoCache ( ) : void ;
0 commit comments