Skip to content

Commit 4e23f51

Browse files
authored
Protect watcher from double close (#49990)
1 parent 455ea9b commit 4e23f51

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/compiler/sys.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,14 +1088,16 @@ namespace ts {
10881088
lastDirectoryPart = lastDirectoryPartWithDirectorySeparator.slice(directorySeparator.length);
10891089
}
10901090
/** Watcher for the file system entry depending on whether it is missing or present */
1091-
let watcher = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
1091+
let watcher: FileWatcher | undefined = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
10921092
watchMissingFileSystemEntry() :
10931093
watchPresentFileSystemEntry();
10941094
return {
10951095
close: () => {
10961096
// Close the watcher (either existing file system entry watcher or missing file system entry watcher)
1097-
watcher.close();
1098-
watcher = undefined!;
1097+
if (watcher) {
1098+
watcher.close();
1099+
watcher = undefined;
1100+
}
10991101
}
11001102
};
11011103

0 commit comments

Comments
 (0)