@@ -311,12 +311,15 @@ namespace ts {
311
311
const fileWatcherCallbacks = createFileMap < FileWatcherCallback [ ] > ( ) ;
312
312
return { addFile, removeFile } ;
313
313
314
- function reduceDirWatcherRefCount ( dirPath : Path ) {
315
- const watcher = dirWatchers . get ( dirPath ) ;
316
- watcher . referenceCount -= 1 ;
317
- if ( watcher . referenceCount <= 0 ) {
318
- watcher . close ( ) ;
319
- dirWatchers . remove ( dirPath ) ;
314
+ function reduceDirWatcherRefCountForFile ( filePath : Path ) {
315
+ const dirPath = getDirectoryPath ( filePath ) ;
316
+ if ( dirWatchers . contains ( dirPath ) ) {
317
+ const watcher = dirWatchers . get ( dirPath ) ;
318
+ watcher . referenceCount -= 1 ;
319
+ if ( watcher . referenceCount <= 0 ) {
320
+ watcher . close ( ) ;
321
+ dirWatchers . remove ( dirPath ) ;
322
+ }
320
323
}
321
324
}
322
325
@@ -346,14 +349,6 @@ namespace ts {
346
349
}
347
350
}
348
351
349
- function findWatchedDirForFile ( filePath : Path ) : Path {
350
- const dirPath = getDirectoryPath ( filePath ) ;
351
- if ( dirWatchers . contains ( dirPath ) ) {
352
- return dirPath ;
353
- }
354
- return undefined ;
355
- }
356
-
357
352
function addFile ( filePath : Path , callback : FileWatcherCallback ) : WatchedFile {
358
353
addFileWatcherCallback ( filePath , callback ) ;
359
354
addDirWatcher ( getDirectoryPath ( filePath ) ) ;
@@ -362,15 +357,15 @@ namespace ts {
362
357
}
363
358
364
359
function removeFile ( watchedFile : WatchedFile ) {
365
- const filePath = watchedFile . filePath ;
360
+ removeFileWatcherCallback ( watchedFile . filePath , watchedFile . callback ) ;
361
+ reduceDirWatcherRefCountForFile ( watchedFile . filePath ) ;
362
+ }
363
+
364
+ function removeFileWatcherCallback ( filePath : Path , callback : FileWatcherCallback ) {
366
365
if ( fileWatcherCallbacks . contains ( filePath ) ) {
367
- const newCallbacks = copyListRemovingItem ( watchedFile . callback , fileWatcherCallbacks . get ( filePath ) ) ;
366
+ const newCallbacks = copyListRemovingItem ( callback , fileWatcherCallbacks . get ( filePath ) ) ;
368
367
if ( newCallbacks . length === 0 ) {
369
368
fileWatcherCallbacks . remove ( filePath ) ;
370
- const watchedDir = findWatchedDirForFile ( filePath ) ;
371
- if ( watchedDir ) {
372
- reduceDirWatcherRefCount ( watchedDir ) ;
373
- }
374
369
}
375
370
else {
376
371
fileWatcherCallbacks . set ( filePath , newCallbacks ) ;
0 commit comments