@@ -11,6 +11,7 @@ namespace ts {
11
11
12
12
invalidateResolutionsOfFailedLookupLocations ( ) : boolean ;
13
13
invalidateResolutionOfFile ( filePath : Path ) : void ;
14
+ removeRelativeNoResolveResolutionsOfFile ( filePath : Path ) : boolean ;
14
15
removeResolutionsOfFile ( filePath : Path ) : void ;
15
16
removeResolutionsFromProjectReferenceRedirects ( filePath : Path ) : void ;
16
17
setFilesWithInvalidatedNonRelativeUnresolvedImports ( filesWithUnresolvedImports : ESMap < Path , readonly string [ ] > ) : void ;
@@ -141,7 +142,21 @@ namespace ts {
141
142
type GetResolutionWithResolvedFileName < T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations , R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName > =
142
143
( resolution : T ) => R | undefined ;
143
144
144
- export function createResolutionCache ( resolutionHost : ResolutionCacheHost , rootDirForResolution : string | undefined , logChangesWhenResolvingModule : boolean ) : ResolutionCache {
145
+ export enum ResolutionKind {
146
+ All ,
147
+ RelativeReferencesInOpenFileOnly
148
+ }
149
+
150
+ const noResolveResolvedModule : ResolvedModuleWithFailedLookupLocations = {
151
+ resolvedModule : undefined ,
152
+ failedLookupLocations : [ ]
153
+ } ;
154
+ const noResolveResolvedTypeReferenceDirective : ResolvedTypeReferenceDirectiveWithFailedLookupLocations = {
155
+ resolvedTypeReferenceDirective : undefined ,
156
+ failedLookupLocations : [ ]
157
+ } ;
158
+
159
+ export function createResolutionCache ( resolutionHost : ResolutionCacheHost , rootDirForResolution : string | undefined , resolutionKind : ResolutionKind , logChangesWhenResolvingModule : boolean ) : ResolutionCache {
145
160
let filesWithChangedSetOfUnresolvedImports : Path [ ] | undefined ;
146
161
let filesWithInvalidatedResolutions : Set < Path > | undefined ;
147
162
let filesWithInvalidatedNonRelativeUnresolvedImports : ReadonlyESMap < Path , readonly string [ ] > | undefined ;
@@ -206,6 +221,7 @@ namespace ts {
206
221
hasChangedAutomaticTypeDirectiveNames : ( ) => hasChangedAutomaticTypeDirectiveNames ,
207
222
invalidateResolutionOfFile,
208
223
invalidateResolutionsOfFailedLookupLocations,
224
+ removeRelativeNoResolveResolutionsOfFile,
209
225
setFilesWithInvalidatedNonRelativeUnresolvedImports,
210
226
createHasInvalidatedResolution,
211
227
updateTypeRootsWatch,
@@ -341,11 +357,12 @@ namespace ts {
341
357
shouldRetryResolution : ( t : T ) => boolean ;
342
358
reusedNames ?: readonly string [ ] ;
343
359
logChanges ?: boolean ;
360
+ noResolveResolution : T ;
344
361
}
345
362
function resolveNamesWithLocalCache < T extends ResolutionWithFailedLookupLocations , R extends ResolutionWithResolvedFileName > ( {
346
363
names, containingFile, redirectedReference,
347
364
cache, perDirectoryCacheWithRedirects,
348
- loader, getResolutionWithResolvedFileName,
365
+ loader, getResolutionWithResolvedFileName, noResolveResolution ,
349
366
shouldRetryResolution, reusedNames, logChanges
350
367
} : ResolveNamesWithLocalCacheInput < T , R > ) : ( R | undefined ) [ ] {
351
368
const path = resolutionHost . toPath ( containingFile ) ;
@@ -382,7 +399,10 @@ namespace ts {
382
399
resolution = resolutionInDirectory ;
383
400
}
384
401
else {
385
- resolution = loader ( name , containingFile , compilerOptions , resolutionHost . getCompilerHost ?.( ) || resolutionHost , redirectedReference ) ;
402
+ resolution = resolutionKind === ResolutionKind . All ||
403
+ ( isExternalModuleNameRelative ( name ) && resolutionHost . fileIsOpen ( path ) ) ?
404
+ loader ( name , containingFile , compilerOptions , resolutionHost . getCompilerHost ?.( ) || resolutionHost , redirectedReference ) :
405
+ noResolveResolution ;
386
406
perDirectoryResolution . set ( name , resolution ) ;
387
407
}
388
408
resolutionsInFile . set ( name , resolution ) ;
@@ -441,6 +461,7 @@ namespace ts {
441
461
loader : resolveTypeReferenceDirective ,
442
462
getResolutionWithResolvedFileName : getResolvedTypeReferenceDirective ,
443
463
shouldRetryResolution : resolution => resolution . resolvedTypeReferenceDirective === undefined ,
464
+ noResolveResolution : noResolveResolvedTypeReferenceDirective ,
444
465
} ) ;
445
466
}
446
467
@@ -455,7 +476,8 @@ namespace ts {
455
476
getResolutionWithResolvedFileName : getResolvedModule ,
456
477
shouldRetryResolution : resolution => ! resolution . resolvedModule || ! resolutionExtensionIsTSOrJson ( resolution . resolvedModule . extension ) ,
457
478
reusedNames,
458
- logChanges : logChangesWhenResolvingModule
479
+ logChanges : logChangesWhenResolvingModule ,
480
+ noResolveResolution : noResolveResolvedModule ,
459
481
} ) ;
460
482
}
461
483
@@ -741,6 +763,32 @@ namespace ts {
741
763
}
742
764
}
743
765
766
+ function removeRelativeNoResolveResolutionsOfFileFromCache < T extends ResolutionWithFailedLookupLocations > (
767
+ cache : ESMap < string , ESMap < string , T > > ,
768
+ filePath : Path ,
769
+ noResolveResolution : T ,
770
+ ) {
771
+ Debug . assert ( resolutionKind === ResolutionKind . RelativeReferencesInOpenFileOnly ) ;
772
+ // Deleted file, stop watching failed lookups for all the resolutions in the file
773
+ const resolutions = cache . get ( filePath ) ;
774
+ if ( ! resolutions ) return false ;
775
+ let invalidated = false ;
776
+ resolutions . forEach ( ( resolution , name ) => {
777
+ if ( resolution === noResolveResolution && isExternalModuleNameRelative ( name ) ) {
778
+ resolutions . delete ( name ) ;
779
+ invalidated = true ;
780
+ }
781
+ } ) ;
782
+ return invalidated ;
783
+ }
784
+
785
+ function removeRelativeNoResolveResolutionsOfFile ( filePath : Path ) {
786
+ let invalidated = removeRelativeNoResolveResolutionsOfFileFromCache ( resolvedModuleNames , filePath , noResolveResolvedModule ) ;
787
+ invalidated = removeRelativeNoResolveResolutionsOfFileFromCache ( resolvedTypeReferenceDirectives , filePath , noResolveResolvedTypeReferenceDirective ) || invalidated ;
788
+ return invalidated ;
789
+
790
+ }
791
+
744
792
function setFilesWithInvalidatedNonRelativeUnresolvedImports ( filesMap : ReadonlyESMap < Path , readonly string [ ] > ) {
745
793
Debug . assert ( filesWithInvalidatedNonRelativeUnresolvedImports === filesMap || filesWithInvalidatedNonRelativeUnresolvedImports === undefined ) ;
746
794
filesWithInvalidatedNonRelativeUnresolvedImports = filesMap ;
0 commit comments