@@ -5,7 +5,14 @@ namespace ts {
55 startRecordingFilesWithChangedResolutions ( ) : void ;
66 finishRecordingFilesWithChangedResolutions ( ) : Path [ ] | undefined ;
77
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 ) [ ] ;
916 getResolvedModuleWithFailedLookupLocationsFromCache ( moduleName : string , containingFile : string , resolutionMode ?: ModuleKind . CommonJS | ModuleKind . ESNext ) : CachedResolvedModuleWithFailedLookupLocations | undefined ;
1017 resolveTypeReferenceDirectives ( typeDirectiveNames : string [ ] | readonly FileReference [ ] , containingFile : string , redirectedReference ?: ResolvedProjectReference , containingFileMode ?: SourceFile [ "impliedNodeFormat" ] ) : ( ResolvedTypeReferenceDirective | undefined ) [ ] ;
1118
@@ -409,6 +416,7 @@ namespace ts {
409416 getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ;
410417 shouldRetryResolution : ( t : T ) => boolean ;
411418 reusedNames ?: readonly string [ ] ;
419+ resolutionInfo ?: ModuleResolutionInfo ;
412420 logChanges ?: boolean ;
413421 containingSourceFile ?: SourceFile ;
414422 containingSourceFileMode ?: SourceFile [ "impliedNodeFormat" ] ;
@@ -417,7 +425,7 @@ namespace ts {
417425 names, containingFile, redirectedReference,
418426 cache, perDirectoryCacheWithRedirects,
419427 loader, getResolutionWithResolvedFileName,
420- shouldRetryResolution, reusedNames, logChanges, containingSourceFile, containingSourceFileMode
428+ shouldRetryResolution, reusedNames, resolutionInfo , logChanges, containingSourceFile, containingSourceFileMode
421429 } : ResolveNamesWithLocalCacheInput < T , R > ) : ( R | undefined ) [ ] {
422430 const path = resolutionHost . toPath ( containingFile ) ;
423431 const resolutionsInFile = cache . get ( path ) || cache . set ( path , createModeAwareCache ( ) ) . get ( path ) ! ;
@@ -441,15 +449,20 @@ namespace ts {
441449
442450 const seenNamesInFile = createModeAwareCache < true > ( ) ;
443451 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 ;
446454 // Imports supply a `containingSourceFile` but no `containingSourceFileMode` - it would be redundant
447455 // they require calculating the mode for a given import from it's position in the resolution table, since a given
448456 // import's syntax may override the file's default mode.
449457 // Type references instead supply a `containingSourceFileMode` and a non-string entry which contains
450458 // 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 ;
453466 i ++ ;
454467 let resolution = resolutionsInFile . get ( name , mode ) ;
455468 // Resolution is valid if it is present and not invalidated
@@ -533,13 +546,19 @@ namespace ts {
533546 resolvedModules . push ( getResolutionWithResolvedFileName ( resolution ) ) ;
534547 }
535548
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+ }
543562
544563 return resolvedModules ;
545564
@@ -576,7 +595,14 @@ namespace ts {
576595 } ) ;
577596 }
578597
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 ) [ ] {
580606 return resolveNamesWithLocalCache < CachedResolvedModuleWithFailedLookupLocations , ResolvedModuleFull > ( {
581607 names : moduleNames ,
582608 containingFile,
@@ -587,6 +613,7 @@ namespace ts {
587613 getResolutionWithResolvedFileName : getResolvedModule ,
588614 shouldRetryResolution : resolution => ! resolution . resolvedModule || ! resolutionExtensionIsTSOrJson ( resolution . resolvedModule . extension ) ,
589615 reusedNames,
616+ resolutionInfo,
590617 logChanges : logChangesWhenResolvingModule ,
591618 containingSourceFile,
592619 } ) ;
0 commit comments