From 95506858d83c3096ce4eaa9bfa354a97002a8a4c Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 21 Jul 2022 13:27:28 -0700 Subject: [PATCH] Protect watcher from double close --- src/compiler/sys.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 701276b9da920..e293932b0b463 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -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; + } } };