Protect watcher from double close (#49990)

This commit is contained in:
Jake Bailey 2022-07-22 13:32:16 -07:00 committed by GitHub
parent 455ea9b41f
commit 4e23f515e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1088,14 +1088,16 @@ namespace ts {
lastDirectoryPart = lastDirectoryPartWithDirectorySeparator.slice(directorySeparator.length);
}
/** Watcher for the file system entry depending on whether it is missing or present */
let watcher = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
let watcher: FileWatcher | undefined = !fileSystemEntryExists(fileOrDirectory, entryKind) ?
watchMissingFileSystemEntry() :
watchPresentFileSystemEntry();
return {
close: () => {
// Close the watcher (either existing file system entry watcher or missing file system entry watcher)
watcher.close();
watcher = undefined!;
if (watcher) {
watcher.close();
watcher = undefined;
}
}
};