@@ -169,7 +169,6 @@ export interface ResolutionWithFailedLookupLocations {
169169 failedLookupLocations ?: string [ ] ;
170170 affectingLocations ?: string [ ] ;
171171 isInvalidated ?: boolean ;
172- refCount ?: number ;
173172 // Files that have this resolution using
174173 files ?: Set < Path > ;
175174 alternateResult ?: string ;
@@ -1095,28 +1094,21 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
10951094 getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ,
10961095 deferWatchingNonRelativeResolution : boolean ,
10971096 ) {
1098- if ( resolution . refCount ) {
1099- resolution . refCount ++ ;
1100- Debug . assertIsDefined ( resolution . files ) ;
1097+ ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
1098+ if ( resolution . files . size !== 1 ) return ;
1099+ if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1100+ watchFailedLookupLocationOfResolution ( resolution ) ;
11011101 }
11021102 else {
1103- resolution . refCount = 1 ;
1104- Debug . assert ( ! resolution . files ?. size ) ; // This resolution shouldnt be referenced by any file yet
1105- if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1106- watchFailedLookupLocationOfResolution ( resolution ) ;
1107- }
1108- else {
1109- nonRelativeExternalModuleResolutions . add ( name , resolution ) ;
1110- }
1111- const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1112- if ( resolved && resolved . resolvedFileName ) {
1113- const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1114- let resolutions = resolvedFileToResolution . get ( key ) ;
1115- if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1116- resolutions . add ( resolution ) ;
1117- }
1103+ nonRelativeExternalModuleResolutions . add ( name , resolution ) ;
1104+ }
1105+ const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1106+ if ( resolved && resolved . resolvedFileName ) {
1107+ const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1108+ let resolutions = resolvedFileToResolution . get ( key ) ;
1109+ if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1110+ resolutions . add ( resolution ) ;
11181111 }
1119- ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
11201112 }
11211113
11221114 function watchFailedLookupLocation ( failedLookupLocation : string , setAtRoot : boolean ) {
@@ -1144,7 +1136,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
11441136 }
11451137
11461138 function watchFailedLookupLocationOfResolution ( resolution : ResolutionWithFailedLookupLocations ) {
1147- Debug . assert ( ! ! resolution . refCount ) ;
1139+ Debug . assert ( ! ! resolution . files ?. size ) ;
11481140
11491141 const { failedLookupLocations, affectingLocations, alternateResult } = resolution ;
11501142 if ( ! failedLookupLocations ?. length && ! affectingLocations ?. length && ! alternateResult ) return ;
@@ -1165,7 +1157,7 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
11651157 }
11661158
11671159 function watchAffectingLocationsOfResolution ( resolution : ResolutionWithFailedLookupLocations , addToResolutionsWithOnlyAffectingLocations : boolean ) {
1168- Debug . assert ( ! ! resolution . refCount ) ;
1160+ Debug . assert ( ! ! resolution . files ?. size ) ;
11691161 const { affectingLocations } = resolution ;
11701162 if ( ! affectingLocations ?. length ) return ;
11711163 if ( addToResolutionsWithOnlyAffectingLocations ) resolutionsWithOnlyAffectingLocations . add ( resolution ) ;
@@ -1381,10 +1373,8 @@ export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootD
13811373 syncDirWatcherRemove ?: boolean ,
13821374 ) {
13831375 Debug . checkDefined ( resolution . files ) . delete ( filePath ) ;
1384- resolution . refCount ! -- ;
1385- if ( resolution . refCount ) {
1386- return ;
1387- }
1376+ if ( resolution . files ! . size ) return ;
1377+ resolution . files = undefined ;
13881378 const resolved = getResolutionWithResolvedFileName ( resolution ) ;
13891379 if ( resolved && resolved . resolvedFileName ) {
13901380 const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
0 commit comments