diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 7f3d078b790..f125fab5a5e 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -44,6 +44,24 @@ namespace ts { } } + /** @internal */ + const screenStartingMessageCodes: number[] = [ + Diagnostics.Starting_compilation_in_watch_mode.code, + Diagnostics.File_change_detected_Starting_incremental_compilation.code, + ]; + + function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string): string { + return contains(screenStartingMessageCodes, diagnostic.code) + ? "" + : newLine; + } + + function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string { + return contains(screenStartingMessageCodes, diagnostic.code) + ? newLine + newLine + : newLine; + } + /** * Create a function that reports watch status by writing to the system and handles the formating of the diagnostic */ @@ -52,13 +70,13 @@ namespace ts { (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine}`; system.write(output); } : (diagnostic, newLine, options) => { clearScreenIfNotWatchingForFileChanges(system, diagnostic, options); - let output = new Date().toLocaleTimeString() + " - "; - output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`; + let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine)}${new Date().toLocaleTimeString()} - `; + output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`; system.write(output); }; }