diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 3140d975a3d..0dfe3968826 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -34,14 +34,20 @@ namespace ts { Diagnostics.Found_0_errors.code ]; - function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions) { + /** + * @returns Whether the screen was cleared. + */ + function clearScreenIfNotWatchingForFileChanges(system: System, diagnostic: Diagnostic, options: CompilerOptions): boolean { if (system.clearScreen && !options.preserveWatchOutput && !options.extendedDiagnostics && !options.diagnostics && !contains(nonClearingMessageCodes, diagnostic.code)) { system.clearScreen(); + return true; } + + return false; } /** @internal */ @@ -50,12 +56,6 @@ namespace ts { Diagnostics.File_change_detected_Starting_incremental_compilation.code, ]; - function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string, preserveWatchOutput?: boolean): string { - return !preserveWatchOutput && contains(screenStartingMessageCodes, diagnostic.code) - ? "" - : newLine; - } - function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string { return contains(screenStartingMessageCodes, diagnostic.code) ? newLine + newLine @@ -74,8 +74,10 @@ namespace ts { system.write(output); } : (diagnostic, newLine, options) => { - clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine, options.preserveWatchOutput)}${new Date().toLocaleTimeString()} - `; + if (!clearScreenIfNotWatchingForFileChanges(system, diagnostic, options)) { + system.write(newLine); + } + let output = `${new Date().toLocaleTimeString()} - `; output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; system.write(output); };