@@ -180,7 +180,6 @@ export interface ResolutionWithFailedLookupLocations {
180
180
failedLookupLocations ?: string [ ] ;
181
181
affectingLocations ?: string [ ] ;
182
182
isInvalidated ?: boolean ;
183
- refCount ?: number ;
184
183
// Files that have this resolution using
185
184
files ?: Set < Path > ;
186
185
node10Result ?: string ;
@@ -1123,30 +1122,25 @@ export function createResolutionCache(
1123
1122
getResolutionWithResolvedFileName : GetResolutionWithResolvedFileName < T , R > ,
1124
1123
deferWatchingNonRelativeResolution : boolean ,
1125
1124
) {
1126
- if ( resolution . refCount ) {
1127
- resolution . refCount ++ ;
1128
- Debug . assertIsDefined ( resolution . files ) ;
1125
+ ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
1126
+ if ( resolution . files . size !== 1 ) return ;
1127
+
1128
+ if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache ++ ;
1129
+ else if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache ++ ;
1130
+
1131
+ if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1132
+ watchFailedLookupLocationOfResolution ( resolution ) ;
1129
1133
}
1130
1134
else {
1131
- resolution . refCount = 1 ;
1132
- if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache ++ ;
1133
- else if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache ++ ;
1134
- Debug . assert ( ! resolution . files ?. size ) ; // This resolution shouldnt be referenced by any file yet
1135
- if ( ! deferWatchingNonRelativeResolution || isExternalModuleNameRelative ( name ) ) {
1136
- watchFailedLookupLocationOfResolution ( resolution ) ;
1137
- }
1138
- else {
1139
- nonRelativeExternalModuleResolutions . add ( resolution ) ;
1140
- }
1141
- const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1142
- if ( resolved && resolved . resolvedFileName ) {
1143
- const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1144
- let resolutions = resolvedFileToResolution . get ( key ) ;
1145
- if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1146
- resolutions . add ( resolution ) ;
1147
- }
1135
+ nonRelativeExternalModuleResolutions . add ( resolution ) ;
1136
+ }
1137
+ const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1138
+ if ( resolved && resolved . resolvedFileName ) {
1139
+ const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
1140
+ let resolutions = resolvedFileToResolution . get ( key ) ;
1141
+ if ( ! resolutions ) resolvedFileToResolution . set ( key , resolutions = new Set ( ) ) ;
1142
+ resolutions . add ( resolution ) ;
1148
1143
}
1149
- ( resolution . files ??= new Set ( ) ) . add ( filePath ) ;
1150
1144
}
1151
1145
1152
1146
function watchFailedLookupLocation ( failedLookupLocation : string , setAtRoot : boolean ) {
@@ -1173,7 +1167,7 @@ export function createResolutionCache(
1173
1167
}
1174
1168
1175
1169
function watchFailedLookupLocationOfResolution ( resolution : ResolutionWithFailedLookupLocations ) {
1176
- Debug . assert ( ! ! resolution . refCount ) ;
1170
+ Debug . assert ( ! ! resolution . files ?. size ) ;
1177
1171
1178
1172
const { failedLookupLocations, affectingLocations, node10Result } = resolution ;
1179
1173
if ( ! failedLookupLocations ?. length && ! affectingLocations ?. length && ! node10Result ) return ;
@@ -1194,7 +1188,7 @@ export function createResolutionCache(
1194
1188
}
1195
1189
1196
1190
function watchAffectingLocationsOfResolution ( resolution : ResolutionWithFailedLookupLocations , addToResolutionsWithOnlyAffectingLocations : boolean ) {
1197
- Debug . assert ( ! ! resolution . refCount ) ;
1191
+ Debug . assert ( ! ! resolution . files ?. size ) ;
1198
1192
const { affectingLocations } = resolution ;
1199
1193
if ( ! affectingLocations ?. length ) return ;
1200
1194
if ( addToResolutionsWithOnlyAffectingLocations ) resolutionsWithOnlyAffectingLocations . add ( resolution ) ;
@@ -1314,12 +1308,12 @@ export function createResolutionCache(
1314
1308
syncDirWatcherRemove ?: boolean ,
1315
1309
) {
1316
1310
Debug . checkDefined ( resolution . files ) . delete ( filePath ) ;
1317
- resolution . refCount ! -- ;
1318
- if ( resolution . refCount ) {
1319
- return ;
1320
- }
1311
+ if ( resolution . files ! . size ) return ;
1312
+ resolution . files = undefined ;
1313
+
1321
1314
if ( resolution . globalCacheResolution ) resolutionsResolvedWithGlobalCache -- ;
1322
1315
if ( resolution . globalCacheResolution === false ) resolutionsResolvedWithoutGlobalCache -- ;
1316
+
1323
1317
const resolved = getResolutionWithResolvedFileName ( resolution ) ;
1324
1318
if ( resolved && resolved . resolvedFileName ) {
1325
1319
const key = resolutionHost . toPath ( resolved . resolvedFileName ) ;
0 commit comments