@@ -181,7 +181,6 @@ export interface ResolutionWithFailedLookupLocations {
181
181
failedLookupLocations ?: string [ ] ;
182
182
affectingLocations ?: string [ ] ;
183
183
isInvalidated ?: boolean ;
184
- refCount ?: number ;
185
184
// Files that have this resolution using
186
185
files ?: Set < Path > ;
187
186
node10Result ?: string ;
@@ -1124,30 +1123,25 @@ export function createResolutionCache(
1124
1123
getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ,
1125
1124
deferWatchingNonRelativeResolution : boolean ,
1126
1125
) {
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 ) ;
1130
1134
}
1131
1135
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 ) ;
1149
1144
}
1150
- ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
1151
1145
}
1152
1146
1153
1147
function watchFailedLookupLocation ( failedLookupLocation : string , setAtRoot : boolean ) {
@@ -1174,7 +1168,7 @@ export function createResolutionCache(
1174
1168
}
1175
1169
1176
1170
function watchFailedLookupLocationOfResolution ( resolution : ResolutionWithFailedLookupLocations ) {
1177
- Debug . assert ( ! ! resolution . refCount ) ;
1171
+ Debug . assert ( ! ! resolution . files ?. size ) ;
1178
1172
1179
1173
const { failedLookupLocations, affectingLocations, node10Result } = resolution ;
1180
1174
if ( ! failedLookupLocations ?. length && ! affectingLocations ?. length && ! node10Result ) return ;
@@ -1195,7 +1189,7 @@ export function createResolutionCache(
1195
1189
}
1196
1190
1197
1191
function watchAffectingLocationsOfResolution ( resolution : ResolutionWithFailedLookupLocations , addToResolutionsWithOnlyAffectingLocations : boolean ) {
1198
- Debug . assert ( ! ! resolution . refCount ) ;
1192
+ Debug . assert ( ! ! resolution . files ?. size ) ;
1199
1193
const { affectingLocations } = resolution ;
1200
1194
if ( ! affectingLocations ?. length ) return ;
1201
1195
if ( addToResolutionsWithOnlyAffectingLocations ) resolutionsWithOnlyAffectingLocations . add ( resolution ) ;
@@ -1315,12 +1309,12 @@ export function createResolutionCache(
1315
1309
syncDirWatcherRemove ?: boolean ,
1316
1310
) {
1317
1311
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
+
1322
1315
if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache -- ;
1323
1316
if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache -- ;
1317
+
1324
1318
const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1325
1319
if ( resolved && resolved . resolvedFileName ) {
1326
1320
const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
0 commit comments