@@ -181,7 +181,6 @@ export interface ResolutionWithFailedLookupLocations {
181181 failedLookupLocations ?: string [ ] ;
182182 affectingLocations ?: string [ ] ;
183183 isInvalidated ?: boolean ;
184- refCount ?: number ;
185184 // Files that have this resolution using
186185 files ?: Set < Path > ;
187186 node10Result ?: string ;
@@ -1124,30 +1123,25 @@ export function createResolutionCache(
11241123 getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ,
11251124 deferWatchingNonRelativeResolution : boolean ,
11261125 ) {
1127- if ( resolution . refCount ) {
1128- resolution . refCount ++ ;
1129- Debug . assertIsDefined ( resolution . files ) ;
1126+ ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
1127+ if ( resolution . files . size !== 1 ) return ;
1128+
1129+ if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache ++ ;
1130+ else if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache ++ ;
1131+
1132+ if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1133+ watchFailedLookupLocationOfResolution ( resolution ) ;
11301134 }
11311135 else {
1132- resolution . refCount = 1 ;
1133- if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache ++ ;
1134- else if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache ++ ;
1135- Debug . assert ( ! resolution . files ?. size ) ; // This resolution shouldnt be referenced by any file yet
1136- if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1137- watchFailedLookupLocationOfResolution ( resolution ) ;
1138- }
1139- else {
1140- nonRelativeExternalModuleResolutions . add ( resolution ) ;
1141- }
1142- const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1143- if ( resolved && resolved . resolvedFileName ) {
1144- const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1145- let resolutions = resolvedFileToResolution . get ( key ) ;
1146- if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1147- resolutions . add ( resolution ) ;
1148- }
1136+ nonRelativeExternalModuleResolutions . add ( resolution ) ;
1137+ }
1138+ const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1139+ if ( resolved && resolved . resolvedFileName ) {
1140+ const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1141+ let resolutions = resolvedFileToResolution . get ( key ) ;
1142+ if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1143+ resolutions . add ( resolution ) ;
11491144 }
1150- ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
11511145 }
11521146
11531147 function watchFailedLookupLocation ( failedLookupLocation : string , setAtRoot : boolean ) {
@@ -1174,7 +1168,7 @@ export function createResolutionCache(
11741168 }
11751169
11761170 function watchFailedLookupLocationOfResolution ( resolution : ResolutionWithFailedLookupLocations ) {
1177- Debug . assert ( ! ! resolution . refCount ) ;
1171+ Debug . assert ( ! ! resolution . files ?. size ) ;
11781172
11791173 const { failedLookupLocations, affectingLocations, node10Result } = resolution ;
11801174 if ( ! failedLookupLocations ?. length && ! affectingLocations ?. length && ! node10Result ) return ;
@@ -1195,7 +1189,7 @@ export function createResolutionCache(
11951189 }
11961190
11971191 function watchAffectingLocationsOfResolution ( resolution : ResolutionWithFailedLookupLocations , addToResolutionsWithOnlyAffectingLocations : boolean ) {
1198- Debug . assert ( ! ! resolution . refCount ) ;
1192+ Debug . assert ( ! ! resolution . files ?. size ) ;
11991193 const { affectingLocations } = resolution ;
12001194 if ( ! affectingLocations ?. length ) return ;
12011195 if ( addToResolutionsWithOnlyAffectingLocations ) resolutionsWithOnlyAffectingLocations . add ( resolution ) ;
@@ -1315,12 +1309,12 @@ export function createResolutionCache(
13151309 syncDirWatcherRemove ?: boolean ,
13161310 ) {
13171311 Debug . checkDefined ( resolution . files ) . delete ( filePath ) ;
1318- resolution . refCount ! -- ;
1319- if ( resolution . refCount ) {
1320- return ;
1321- }
1312+ if ( resolution . files ! . size ) return ;
1313+ resolution . files = undefined ;
1314+
13221315 if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache -- ;
13231316 if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache -- ;
1317+
13241318 const resolved = getResolutionWithResolvedFileName ( resolution ) ;
13251319 if ( resolved && resolved . resolvedFileName ) {
13261320 const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
0 commit comments