@@ -5,7 +5,14 @@ namespace ts {
5
5
startRecordingFilesWithChangedResolutions ( ) : void ;
6
6
finishRecordingFilesWithChangedResolutions ( ) : Path [ ] | undefined ;
7
7
8
- resolveModuleNames ( moduleNames : string [ ] , containingFile : string , reusedNames : string [ ] | undefined , redirectedReference ?: ResolvedProjectReference , containingSourceFile ?: SourceFile ) : ( ResolvedModuleFull | undefined ) [ ] ;
8
+ resolveModuleNames (
9
+ moduleNames : string [ ] ,
10
+ containingFile : string ,
11
+ reusedNames : string [ ] | undefined ,
12
+ redirectedReference : ResolvedProjectReference | undefined ,
13
+ containingSourceFile : SourceFile | undefined ,
14
+ resolutionInfo : ModuleResolutionInfo | undefined
15
+ ) : ( ResolvedModuleFull | undefined ) [ ] ;
9
16
getResolvedModuleWithFailedLookupLocationsFromCache ( moduleName : string , containingFile : string , resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : CachedResolvedModuleWithFailedLookupLocations | undefined ;
10
17
resolveTypeReferenceDirectives ( typeDirectiveNames : string [ ] | readonly FileReference [ ] , containingFile : string , redirectedReference ?: ResolvedProjectReference , containingFileMode ?: SourceFile [ "impliedNodeFormat" ] ) : ( ResolvedTypeReferenceDirective | undefined ) [ ] ;
11
18
@@ -409,6 +416,7 @@ namespace ts {
409
416
getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ;
410
417
shouldRetryResolution : ( t : T ) => boolean ;
411
418
reusedNames ?: readonly string [ ] ;
419
+ resolutionInfo ?: ModuleResolutionInfo ;
412
420
logChanges ?: boolean ;
413
421
containingSourceFile ?: SourceFile ;
414
422
containingSourceFileMode ?: SourceFile [ "impliedNodeFormat" ] ;
@@ -417,7 +425,7 @@ namespace ts {
417
425
names, containingFile, redirectedReference,
418
426
cache, perDirectoryCacheWithRedirects,
419
427
loader, getResolutionWithResolvedFileName,
420
- shouldRetryResolution, reusedNames, logChanges, containingSourceFile, containingSourceFileMode
428
+ shouldRetryResolution, reusedNames, resolutionInfo , logChanges, containingSourceFile, containingSourceFileMode
421
429
} : ResolveNamesWithLocalCacheInput < T , R > ) : ( R | undefined ) [ ] {
422
430
const path = resolutionHost . toPath ( containingFile ) ;
423
431
const resolutionsInFile = cache . get ( path ) || cache . set ( path , createModeAwareCache ( ) ) . get ( path ) ! ;
@@ -441,15 +449,20 @@ namespace ts {
441
449
442
450
const seenNamesInFile = createModeAwareCache < true > ( ) ;
443
451
let i = 0 ;
444
- for ( const entry of names ) {
445
- const name = isString ( entry ) ? entry : entry . fileName . toLowerCase ( ) ;
452
+ for ( const entry of containingSourceFile && resolutionInfo ? resolutionInfo . names : names ) {
453
+ const name = ! isString ( entry ) ? getResolutionName ( entry ) : entry ;
446
454
// Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
447
455
// they require calculating the mode for a given import from it's position in the resolution table, since a given
448
456
// import's syntax may override the file's default mode.
449
457
// Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
450
458
// a default file mode override if applicable.
451
- const mode = ! isString ( entry ) ? getModeForFileReference ( entry , containingSourceFileMode ) :
452
- containingSourceFile ? getModeForResolutionAtIndex ( containingSourceFile , i ) : undefined ;
459
+ const mode = ! isString ( entry ) ?
460
+ isStringLiteralLike ( entry ) ?
461
+ getModeForUsageLocation ( containingSourceFile ! , entry ) :
462
+ getModeForFileReference ( entry , containingSourceFileMode ) :
463
+ containingSourceFile ?
464
+ getModeForResolutionAtIndex ( containingSourceFile , i ) :
465
+ undefined ;
453
466
i ++ ;
454
467
let resolution = resolutionsInFile . get ( name , mode ) ;
455
468
// Resolution is valid if it is present and not invalidated
@@ -533,13 +546,19 @@ namespace ts {
533
546
resolvedModules . push ( getResolutionWithResolvedFileName ( resolution ) ) ;
534
547
}
535
548
536
- // Stop watching and remove the unused name
537
- resolutionsInFile . forEach ( ( resolution , name , mode ) => {
538
- if ( ! seenNamesInFile . has ( name , mode ) && ! contains ( reusedNames , name ) ) {
539
- stopWatchFailedLookupLocationOfResolution ( resolution , path , getResolutionWithResolvedFileName ) ;
540
- resolutionsInFile . delete ( name , mode ) ;
541
- }
542
- } ) ;
549
+ if ( containingSourceFile && resolutionInfo ) {
550
+ resolutionInfo . reusedNames ?. forEach ( literal => seenNamesInFile . set ( literal . text , getModeForUsageLocation ( containingSourceFile , literal ) , true ) ) ;
551
+ reusedNames = undefined ;
552
+ }
553
+ if ( resolutionsInFile . size ( ) !== seenNamesInFile . size ( ) ) {
554
+ // Stop watching and remove the unused name
555
+ resolutionsInFile . forEach ( ( resolution , name , mode ) => {
556
+ if ( ! seenNamesInFile . has ( name , mode ) && ! contains ( reusedNames , name ) ) {
557
+ stopWatchFailedLookupLocationOfResolution ( resolution , path , getResolutionWithResolvedFileName ) ;
558
+ resolutionsInFile . delete ( name , mode ) ;
559
+ }
560
+ } ) ;
561
+ }
543
562
544
563
return resolvedModules ;
545
564
@@ -576,7 +595,14 @@ namespace ts {
576
595
} ) ;
577
596
}
578
597
579
- function resolveModuleNames ( moduleNames : string [ ] , containingFile : string , reusedNames : string [ ] | undefined , redirectedReference ?: ResolvedProjectReference , containingSourceFile ?: SourceFile ) : ( ResolvedModuleFull | undefined ) [ ] {
598
+ function resolveModuleNames (
599
+ moduleNames : string [ ] ,
600
+ containingFile : string ,
601
+ reusedNames : string [ ] | undefined ,
602
+ redirectedReference ?: ResolvedProjectReference ,
603
+ containingSourceFile ?: SourceFile ,
604
+ resolutionInfo ?: ModuleResolutionInfo
605
+ ) : ( ResolvedModuleFull | undefined ) [ ] {
580
606
return resolveNamesWithLocalCache < CachedResolvedModuleWithFailedLookupLocations , ResolvedModuleFull > ( {
581
607
names : moduleNames ,
582
608
containingFile,
@@ -587,6 +613,7 @@ namespace ts {
587
613
getResolutionWithResolvedFileName : getResolvedModule ,
588
614
shouldRetryResolution : resolution => ! resolution . resolvedModule || ! resolutionExtensionIsTSOrJson ( resolution . resolvedModule . extension ) ,
589
615
reusedNames,
616
+ resolutionInfo,
590
617
logChanges : logChangesWhenResolvingModule ,
591
618
containingSourceFile,
592
619
} ) ;
0 commit comments