@@ -210,7 +210,7 @@ export function verifyResolutionCache(
210
210
const expected = ts . createResolutionCache ( resolutionHostCacheHost , actual . rootDirForResolution ) ;
211
211
expected . startCachingPerDirectoryResolution ( ) ;
212
212
213
- type ExpectedResolution = ts . CachedResolvedModuleWithFailedLookupLocations & ts . CachedResolvedTypeReferenceDirectiveWithFailedLookupLocations ;
213
+ type ExpectedResolution = ts . ResolvedModuleWithFailedLookupLocations & ts . ResolvedTypeReferenceDirectiveWithFailedLookupLocations ;
214
214
215
215
const expectedToResolution = new Map < ExpectedResolution , ts . ResolutionWithFailedLookupLocations > ( ) ;
216
216
const resolutionToExpected = new Map < ts . ResolutionWithFailedLookupLocations , ExpectedResolution > ( ) ;
@@ -228,6 +228,8 @@ export function verifyResolutionCache(
228
228
resolutions ,
229
229
getResolvedModuleFileName ,
230
230
expected . resolvedModuleNames ,
231
+ expected . moduleResolutionCache ,
232
+ ( ) => actualProgram . getRedirectReferenceForResolution ( actualProgram . getSourceFileByPath ( path ) ! ) ,
231
233
( name , mode ) => actualProgram . getResolvedModule ( actualProgram . getSourceFileByPath ( path ) ! , name , mode ) ,
232
234
)
233
235
) ;
@@ -238,24 +240,36 @@ export function verifyResolutionCache(
238
240
resolutions ,
239
241
getResolvedTypeRefFileName ,
240
242
expected . resolvedTypeReferenceDirectives ,
243
+ expected . typeReferenceDirectiveResolutionCache ,
244
+ ( ) =>
245
+ path !== inferredTypesPath ?
246
+ actualProgram . getRedirectReferenceForResolution ( actualProgram . getSourceFileByPath ( path ) ! ) :
247
+ undefined ,
241
248
( name , mode ) =>
242
249
path !== inferredTypesPath ?
243
250
actualProgram . getResolvedTypeReferenceDirective ( actualProgram . getSourceFileByPath ( path ) ! , name , mode ) :
244
251
actualProgram . getAutomaticTypeDirectiveResolutions ( ) . get ( name , mode ) ,
245
252
)
246
253
) ;
247
254
actual . resolvedLibraries . forEach ( ( resolved , libFileName ) => {
255
+ const libResolvedFrom = ts . getInferredLibraryNameResolveFrom ( actualProgram . getCompilerOptions ( ) , currentDirectory , libFileName ) ;
248
256
const expectedResolution = collectResolution (
249
257
"Libs" ,
250
- resolutionHostCacheHost . toPath (
251
- ts . getInferredLibraryNameResolveFrom ( actualProgram . getCompilerOptions ( ) , currentDirectory , libFileName ) ,
252
- ) ,
258
+ resolutionHostCacheHost . toPath ( libResolvedFrom ) ,
253
259
resolved ,
254
260
getResolvedModuleFileName ( resolved ) ,
255
261
ts . getLibraryNameFromLibFileName ( libFileName ) ,
256
262
/*mode*/ undefined ,
257
263
) ;
258
264
expected . resolvedLibraries . set ( libFileName , expectedResolution ) ;
265
+ ts . setPerDirectoryAndNonRelativeNameCacheResult (
266
+ expected . libraryResolutionCache ,
267
+ libFileName ,
268
+ undefined ,
269
+ ts . getDirectoryPath ( libResolvedFrom ) ,
270
+ undefined ,
271
+ expectedResolution ,
272
+ ) ;
259
273
} ) ;
260
274
// Check for resolutions in program but not in cache to empty resolutions
261
275
if ( ! userResolvedModuleNames ) {
@@ -337,6 +351,11 @@ export function verifyResolutionCache(
337
351
`${ projectName } :: Expected ResolutionsResolvedWithoutGlobalCache count ${ expected . countResolutionsResolvedWithoutGlobalCache ( ) } but got ${ actual . countResolutionsResolvedWithoutGlobalCache ( ) } ` ,
338
352
) ;
339
353
354
+ // Verify that caches are same:
355
+ verifyModuleOrTypeResolutionCache ( expected . moduleResolutionCache , actual . moduleResolutionCache , "moduleResolutionCache" ) ;
356
+ verifyModuleOrTypeResolutionCache ( expected . typeReferenceDirectiveResolutionCache , actual . typeReferenceDirectiveResolutionCache , "typeReferenceDirectiveResolutionCache" ) ;
357
+ verifyModuleOrTypeResolutionCache ( expected . libraryResolutionCache , actual . libraryResolutionCache , "libraryResolutionCache" ) ;
358
+
340
359
// Stop watching resolutions to verify everything gets closed.
341
360
expected . startCachingPerDirectoryResolution ( ) ;
342
361
actual . resolvedModuleNames . forEach ( ( _resolutions , path ) => expected . removeResolutionsOfFile ( path ) ) ;
@@ -353,6 +372,9 @@ export function verifyResolutionCache(
353
372
ts . Debug . assert ( expected . fileWatchesOfAffectingLocations . size === 0 , `${ projectName } :: fileWatchesOfAffectingLocations should be released` ) ;
354
373
ts . Debug . assert ( expected . countResolutionsResolvedWithGlobalCache ( ) === 0 , `${ projectName } :: ResolutionsResolvedWithGlobalCache should be cleared` ) ;
355
374
ts . Debug . assert ( expected . countResolutionsResolvedWithoutGlobalCache ( ) === 0 , `${ projectName } :: ResolutionsResolvedWithoutGlobalCache should be cleared` ) ;
375
+ verifyModuleOrTypeResolutionCacheIsEmpty ( expected . moduleResolutionCache , "moduleResolutionCache" ) ;
376
+ verifyModuleOrTypeResolutionCacheIsEmpty ( expected . typeReferenceDirectiveResolutionCache , "typeReferenceDirectiveResolutionCache" ) ;
377
+ verifyModuleOrTypeResolutionCacheIsEmpty ( expected . libraryResolutionCache , "libraryResolutionCache" ) ;
356
378
357
379
function verifyResolutionIsInCache < T extends ts . ResolutionWithFailedLookupLocations > (
358
380
cacheType : string ,
@@ -384,6 +406,8 @@ export function verifyResolutionCache(
384
406
cache : ts . ModeAwareCache < T > | undefined ,
385
407
getResolvedFileName : ( resolution : T ) => string | undefined ,
386
408
storeExpected : Map < ts . Path , ts . ModeAwareCache < ts . ResolutionWithFailedLookupLocations > > ,
409
+ moduleOrTypeRefCache : ts . ModuleOrTypeReferenceResolutionCache < T > ,
410
+ getRedirectReferenceForResolution : ( ) => ts . ResolvedProjectReference | undefined ,
387
411
getProgramResolutions : ( name : string , mode : ts . ResolutionMode ) => T | undefined ,
388
412
) {
389
413
ts . Debug . assert (
@@ -396,6 +420,14 @@ export function verifyResolutionCache(
396
420
const expected = collectResolution ( cacheType , fileName , resolved , resolvedFileName , name , mode ) ;
397
421
if ( ! expectedCache ) storeExpected . set ( fileName , expectedCache = ts . createModeAwareCache ( ) ) ;
398
422
expectedCache . set ( name , mode , expected ) ;
423
+ ts . setPerDirectoryAndNonRelativeNameCacheResult (
424
+ moduleOrTypeRefCache ,
425
+ name ,
426
+ mode ,
427
+ ts . getDirectoryPath ( fileName ) ,
428
+ getRedirectReferenceForResolution ( ) ,
429
+ expected as unknown as T ,
430
+ ) ;
399
431
// Resolution in cache should be same as that is in program
400
432
ts . Debug . assert (
401
433
resolved === getProgramResolutions ( name , mode ) ,
@@ -526,6 +558,90 @@ export function verifyResolutionCache(
526
558
ts . Debug . assert ( expected === actual , `${ projectName } :: ${ caption } ` ) ;
527
559
} , "dirPathToSymlinkPackageRefCount" ) ;
528
560
}
561
+
562
+ function verifyModuleOrTypeResolutionCache (
563
+ expected : ts . ModuleOrTypeReferenceResolutionCache < ts . ResolutionWithFailedLookupLocations > ,
564
+ actual : ts . ModuleOrTypeReferenceResolutionCache < ts . ResolutionWithFailedLookupLocations > ,
565
+ cacheType : string ,
566
+ ) {
567
+ verfiyCacheWithRedirects (
568
+ expected . directoryToModuleNameMap ,
569
+ actual . directoryToModuleNameMap ,
570
+ verifyDirectoryToModuleNameMap ,
571
+ `${ cacheType } :: directoryToModuleNameMap` ,
572
+ ) ;
573
+ verfiyCacheWithRedirects (
574
+ expected . moduleNameToDirectoryMap ,
575
+ actual . moduleNameToDirectoryMap ,
576
+ verifyModuleNameToDirectoryMap ,
577
+ `${ cacheType } :: moduleNameToDirectoryMap` ,
578
+ ) ;
579
+ }
580
+
581
+ function verifyDirectoryToModuleNameMap (
582
+ expected : ts . ModeAwareCache < ts . ResolutionWithFailedLookupLocations > | undefined ,
583
+ actual : ts . ModeAwareCache < ts . ResolutionWithFailedLookupLocations > | undefined ,
584
+ caption : string ,
585
+ ) {
586
+ verifyModeAwareCache (
587
+ expected ,
588
+ actual ,
589
+ verfiyResolution ,
590
+ caption ,
591
+ ) ;
592
+ }
593
+
594
+ function verifyModuleNameToDirectoryMap (
595
+ expected : ts . PerNonRelativeNameCache < ts . ResolutionWithFailedLookupLocations > | undefined ,
596
+ actual : ts . PerNonRelativeNameCache < ts . ResolutionWithFailedLookupLocations > | undefined ,
597
+ caption : string ,
598
+ ) {
599
+ verifyMap (
600
+ expected ?. directoryPathMap ,
601
+ actual ?. directoryPathMap ,
602
+ verfiyResolution ,
603
+ caption ,
604
+ ) ;
605
+ }
606
+
607
+ function verfiyResolution (
608
+ expected : ts . ResolutionWithFailedLookupLocations | undefined ,
609
+ actual : ts . ResolutionWithFailedLookupLocations | undefined ,
610
+ caption : string ,
611
+ ) {
612
+ ts . Debug . assert (
613
+ expectedToResolution . get ( expected as ExpectedResolution ) === actual ,
614
+ `${ projectName } :: ${ caption } Expected resolution need to match in actual` ,
615
+ ) ;
616
+ }
617
+
618
+ function verifyModuleOrTypeResolutionCacheIsEmpty (
619
+ cache : ts . ModuleOrTypeReferenceResolutionCache < ts . ResolutionWithFailedLookupLocations > ,
620
+ cacheType : string ,
621
+ ) {
622
+ verifyCacheWithRedirectsIsEmpty (
623
+ cache . directoryToModuleNameMap ,
624
+ `${ cacheType } :: directoryToModuleNameMap` ,
625
+ ) ;
626
+ verifyCacheWithRedirectsIsEmpty (
627
+ cache . moduleNameToDirectoryMap ,
628
+ `${ cacheType } :: moduleNameToDirectoryMap` ,
629
+ ) ;
630
+ }
631
+
632
+ function verifyCacheWithRedirectsIsEmpty < K , V > (
633
+ cache : ts . CacheWithRedirects < K , V > ,
634
+ cacheType : string ,
635
+ ) {
636
+ ts . Debug . assert (
637
+ cache . getOwnMap ( ) . size === 0 ,
638
+ `${ projectName } :: ${ cacheType } :: ownMap should be empty` ,
639
+ ) ;
640
+ ts . Debug . assert (
641
+ cache . redirectsKeyToMap . size === 0 ,
642
+ `${ projectName } :: ${ cacheType } :: redirectsKeyToMap should be empty` ,
643
+ ) ;
644
+ }
529
645
}
530
646
531
647
function verifyMap < Key extends string , Expected , Actual > (
@@ -565,6 +681,31 @@ function verifyArray(
565
681
return verifySet ( expected && new Set ( expected ) , actual && new Set ( actual ) , caption ) ;
566
682
}
567
683
684
+ function verifyModeAwareCache < T > (
685
+ expected : ts . ModeAwareCache < T > | undefined ,
686
+ actual : ts . ModeAwareCache < T > | undefined ,
687
+ verifyValue : ( expected : T | undefined , actual : T | undefined , caption : string ) => void ,
688
+ caption : string ,
689
+ ) {
690
+ expected ?. forEach ( ( expected , key , mode ) => verifyValue ( expected , actual ?. get ( key , mode ) , `${ caption } :: ${ key } :: ${ mode } ` ) ) ;
691
+ actual ?. forEach ( ( actual , key , mode ) => verifyValue ( expected ?. get ( key , mode ) , actual , `${ caption } :: ${ key } :: ${ mode } ` ) ) ;
692
+ }
693
+
694
+ function verfiyCacheWithRedirects < K extends string , V > (
695
+ expected : ts . CacheWithRedirects < K , V > ,
696
+ actual : ts . CacheWithRedirects < K , V > ,
697
+ verifyValue : ( expected : V | undefined , actual : V | undefined , caption : string ) => void ,
698
+ cacheType : string ,
699
+ ) {
700
+ verifyMap ( expected . getOwnMap ( ) , actual . getOwnMap ( ) , verifyValue , `${ cacheType } :: ownMap` ) ;
701
+ verifyMap (
702
+ expected . redirectsKeyToMap ,
703
+ actual . redirectsKeyToMap ,
704
+ ( expected , actual , key ) => verifyMap ( expected , actual , verifyValue , key ) ,
705
+ `${ cacheType } :: redirectsKeyToMap` ,
706
+ ) ;
707
+ }
708
+
568
709
function verifyProgram ( service : ts . server . ProjectService , project : ts . server . Project ) {
569
710
if ( service . serverMode === ts . LanguageServiceMode . Syntactic ) return ;
570
711
const options = project . getCompilerOptions ( ) ;
0 commit comments