diff --git a/src/compiler/tsc.ts b/src/compiler/tsc.ts index 393e00f35f2..21e4a7d2693 100644 --- a/src/compiler/tsc.ts +++ b/src/compiler/tsc.ts @@ -239,6 +239,11 @@ namespace ts { function isJSONSupported() { return typeof JSON === "object" && typeof JSON.parse === "function"; } + + function isWatchSet(options: CompilerOptions) { + // Firefox has Object.prototype.watch + return options.watch && options.hasOwnProperty("watch"); + } export function executeCommandLine(args: string[]): void { const commandLine = parseCommandLine(args); @@ -327,8 +332,7 @@ namespace ts { return sys.exit(ExitStatus.Success); } - // Firefox has Object.prototype.watch - if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) { + if (isWatchSet(commandLine.options)) { if (!sys.watchFile) { reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined); return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped); @@ -415,8 +419,7 @@ namespace ts { const compileResult = compile(rootFileNames, compilerOptions, compilerHost); - // Firefox has Object.prototype.watch - if (!compilerOptions.watch || !compilerOptions.hasOwnProperty("watch")) { + if (!isWatchSet(compilerOptions)) { return sys.exit(compileResult.exitStatus); } @@ -442,8 +445,7 @@ namespace ts { } // Use default host function const sourceFile = hostGetSourceFile(fileName, languageVersion, onError); - // Firefox has Object.prototype.watch - if (sourceFile && compilerOptions.watch && compilerOptions.hasOwnProperty("watch")) { + if (sourceFile && isWatchSet(compilerOptions)) { // Attach a file watcher const filePath = toPath(sourceFile.fileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames)); sourceFile.fileWatcher = sys.watchFile(filePath, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed));