@@ -279,10 +279,10 @@ export function getDirectoryToWatchFailedLookupLocation(
279279 rootPathComponents : Readonly < PathPathComponents > ,
280280 getCurrentDirectory : ( ) => string | undefined ,
281281) : DirectoryOfFailedLookupWatch | undefined {
282- const failedLookupPathComponents = getPathComponents ( failedLookupLocationPath ) ;
282+ const failedLookupPathComponents : Readonly < PathPathComponents > = getPathComponents ( failedLookupLocationPath ) ;
283283 // Ensure failed look up is normalized path
284284 failedLookupLocation = isRootedDiskPath ( failedLookupLocation ) ? normalizePath ( failedLookupLocation ) : getNormalizedAbsolutePath ( failedLookupLocation , getCurrentDirectory ( ) ) ;
285- const failedLookupComponents = getPathComponents ( failedLookupLocation ) ;
285+ const failedLookupComponents : readonly string [ ] = getPathComponents ( failedLookupLocation ) ;
286286 const perceivedOsRootLength = perceivedOsRootLengthForWatching ( failedLookupPathComponents , failedLookupPathComponents . length ) ;
287287 if ( failedLookupPathComponents . length <= perceivedOsRootLength + 1 ) return undefined ;
288288 // If directory path contains node module, get the most parent node_modules directory for watching
@@ -303,11 +303,10 @@ export function getDirectoryToWatchFailedLookupLocation(
303303 }
304304 }
305305
306- failedLookupComponents . pop ( ) ;
307- failedLookupPathComponents . pop ( ) ;
308306 return getDirectoryToWatchFromFailedLookupLocationDirectory (
309307 failedLookupComponents ,
310308 failedLookupPathComponents ,
309+ failedLookupPathComponents . length - 1 ,
311310 perceivedOsRootLength ,
312311 nodeModulesIndex ,
313312 rootPathComponents ,
@@ -317,6 +316,7 @@ export function getDirectoryToWatchFailedLookupLocation(
317316function getDirectoryToWatchFromFailedLookupLocationDirectory (
318317 dirComponents : readonly string [ ] ,
319318 dirPathComponents : Readonly < PathPathComponents > ,
319+ dirPathComponentsLength : number ,
320320 perceivedOsRootLength : number ,
321321 nodeModulesIndex : number ,
322322 rootPathComponents : Readonly < PathPathComponents > ,
@@ -328,8 +328,8 @@ function getDirectoryToWatchFromFailedLookupLocationDirectory(
328328 }
329329 // Use some ancestor of the root directory
330330 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 ++ ) {
333333 if ( dirPathComponents [ i ] !== rootPathComponents [ i ] ) {
334334 nonRecursive = false ;
335335 length = Math . max ( i + 1 , perceivedOsRootLength + 1 ) ;
@@ -342,7 +342,7 @@ function getDirectoryToWatchFromFailedLookupLocationDirectory(
342342function getDirectoryOfFailedLookupWatch (
343343 dirComponents : readonly string [ ] ,
344344 dirPathComponents : Readonly < PathPathComponents > ,
345- length : number | undefined ,
345+ length : number ,
346346 nonRecursive ?: boolean
347347) : DirectoryOfFailedLookupWatch {
348348 return {
@@ -370,6 +370,7 @@ export function getDirectoryToWatchFailedLookupLocationFromTypeRoot(
370370 const toWatch = getDirectoryToWatchFromFailedLookupLocationDirectory (
371371 getPathComponents ( typeRoot ) ,
372372 typeRootPathComponents ,
373+ typeRootPathComponents . length ,
373374 perceivedOsRootLengthForWatching ( typeRootPathComponents , typeRootPathComponents . length ) ,
374375 typeRootPathComponents . indexOf ( "node_modules" as Path ) ,
375376 rootPathComponents ,
0 commit comments