Skip to content

Commit 54ae270

Browse files
committed
Consolidate watch checks in one place
1 parent 555edcd commit 54ae270

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/compiler/tsc.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ namespace ts {
239239
function isJSONSupported() {
240240
return typeof JSON === "object" && typeof JSON.parse === "function";
241241
}
242+
243+
function isWatchSet(options: CompilerOptions) {
244+
// Firefox has Object.prototype.watch
245+
return options.watch && options.hasOwnProperty("watch");
246+
}
242247

243248
export function executeCommandLine(args: string[]): void {
244249
const commandLine = parseCommandLine(args);
@@ -327,8 +332,7 @@ namespace ts {
327332
return sys.exit(ExitStatus.Success);
328333
}
329334

330-
// Firefox has Object.prototype.watch
331-
if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) {
335+
if (isWatchSet(commandLine.options)) {
332336
if (!sys.watchFile) {
333337
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"), /* compilerHost */ undefined);
334338
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
@@ -415,8 +419,7 @@ namespace ts {
415419

416420
const compileResult = compile(rootFileNames, compilerOptions, compilerHost);
417421

418-
// Firefox has Object.prototype.watch
419-
if (!compilerOptions.watch || !compilerOptions.hasOwnProperty("watch")) {
422+
if (!isWatchSet(compilerOptions)) {
420423
return sys.exit(compileResult.exitStatus);
421424
}
422425

@@ -442,8 +445,7 @@ namespace ts {
442445
}
443446
// Use default host function
444447
const sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
445-
// Firefox has Object.prototype.watch
446-
if (sourceFile && compilerOptions.watch && compilerOptions.hasOwnProperty("watch")) {
448+
if (sourceFile && isWatchSet(compilerOptions)) {
447449
// Attach a file watcher
448450
const filePath = toPath(sourceFile.fileName, sys.getCurrentDirectory(), createGetCanonicalFileName(sys.useCaseSensitiveFileNames));
449451
sourceFile.fileWatcher = sys.watchFile(filePath, (fileName: string, removed?: boolean) => sourceFileChanged(sourceFile, removed));

0 commit comments

Comments
 (0)