@@ -279,10 +279,10 @@ export function getDirectoryToWatchFailedLookupLocation(
279
279
rootPathComponents : Readonly < PathPathComponents > ,
280
280
getCurrentDirectory : ( ) => string | undefined ,
281
281
) : DirectoryOfFailedLookupWatch | undefined {
282
- const failedLookupPathComponents = getPathComponents ( failedLookupLocationPath ) ;
282
+ const failedLookupPathComponents : Readonly < PathPathComponents > = getPathComponents ( failedLookupLocationPath ) ;
283
283
// Ensure failed look up is normalized path
284
284
failedLookupLocation = isRootedDiskPath ( failedLookupLocation ) ? normalizePath ( failedLookupLocation ) : getNormalizedAbsolutePath ( failedLookupLocation , getCurrentDirectory ( ) ) ;
285
- const failedLookupComponents = getPathComponents ( failedLookupLocation ) ;
285
+ const failedLookupComponents : readonly string [ ] = getPathComponents ( failedLookupLocation ) ;
286
286
const perceivedOsRootLength = perceivedOsRootLengthForWatching ( failedLookupPathComponents , failedLookupPathComponents . length ) ;
287
287
if ( failedLookupPathComponents . length <= perceivedOsRootLength + 1 ) return undefined ;
288
288
// If directory path contains node module, get the most parent node_modules directory for watching
@@ -303,11 +303,10 @@ export function getDirectoryToWatchFailedLookupLocation(
303
303
}
304
304
}
305
305
306
- failedLookupComponents . pop ( ) ;
307
- failedLookupPathComponents . pop ( ) ;
308
306
return getDirectoryToWatchFromFailedLookupLocationDirectory (
309
307
failedLookupComponents ,
310
308
failedLookupPathComponents ,
309
+ failedLookupPathComponents . length - 1 ,
311
310
perceivedOsRootLength ,
312
311
nodeModulesIndex ,
313
312
rootPathComponents ,
@@ -317,6 +316,7 @@ export function getDirectoryToWatchFailedLookupLocation(
317
316
function getDirectoryToWatchFromFailedLookupLocationDirectory (
318
317
dirComponents : readonly string [ ] ,
319
318
dirPathComponents : Readonly < PathPathComponents > ,
319
+ dirPathComponentsLength : number ,
320
320
perceivedOsRootLength : number ,
321
321
nodeModulesIndex : number ,
322
322
rootPathComponents : Readonly < PathPathComponents > ,
@@ -328,8 +328,8 @@ function getDirectoryToWatchFromFailedLookupLocationDirectory(
328
328
}
329
329
// Use some ancestor of the root directory
330
330
let nonRecursive = true ;
331
- let length : number | undefined ;
332
- for ( let i = 0 ; i < dirPathComponents . length ; i ++ ) {
331
+ let length = dirPathComponentsLength ;
332
+ for ( let i = 0 ; i < dirPathComponentsLength ; i ++ ) {
333
333
if ( dirPathComponents [ i ] !== rootPathComponents [ i ] ) {
334
334
nonRecursive = false ;
335
335
length = Math . max ( i + 1 , perceivedOsRootLength + 1 ) ;
@@ -342,7 +342,7 @@ function getDirectoryToWatchFromFailedLookupLocationDirectory(
342
342
function getDirectoryOfFailedLookupWatch (
343
343
dirComponents : readonly string [ ] ,
344
344
dirPathComponents : Readonly < PathPathComponents > ,
345
- length : number | undefined ,
345
+ length : number ,
346
346
nonRecursive ?: boolean
347
347
) : DirectoryOfFailedLookupWatch {
348
348
return {
@@ -370,6 +370,7 @@ export function getDirectoryToWatchFailedLookupLocationFromTypeRoot(
370
370
const toWatch = getDirectoryToWatchFromFailedLookupLocationDirectory (
371
371
getPathComponents ( typeRoot ) ,
372
372
typeRootPathComponents ,
373
+ typeRootPathComponents . length ,
373
374
perceivedOsRootLengthForWatching ( typeRootPathComponents , typeRootPathComponents . length ) ,
374
375
typeRootPathComponents . indexOf ( "node_modules" as Path ) ,
375
376
rootPathComponents ,
0 commit comments