Skip to content

Commit bc9ad90

Browse files
author
Josh Goldberg
committed
Adjusted newlines in non-pretty output for consistency
Fixes microsoft#23469
1 parent 40fd6ae commit bc9ad90

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/compiler/watch.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ namespace ts {
4444
}
4545
}
4646

47+
/** @internal */
48+
const screenStartingMessageCodes: number[] = [
49+
Diagnostics.Starting_compilation_in_watch_mode.code,
50+
Diagnostics.File_change_detected_Starting_incremental_compilation.code,
51+
];
52+
53+
function getPlainDiagnosticPrecedingNewLines(diagnostic: Diagnostic, newLine: string): string {
54+
return contains(screenStartingMessageCodes, diagnostic.code)
55+
? ""
56+
: newLine;
57+
}
58+
59+
function getPlainDiagnosticFollowingNewLines(diagnostic: Diagnostic, newLine: string): string {
60+
return contains(screenStartingMessageCodes, diagnostic.code)
61+
? newLine + newLine
62+
: newLine;
63+
}
64+
4765
/**
4866
* Create a function that reports watch status by writing to the system and handles the formating of the diagnostic
4967
*/
@@ -52,13 +70,13 @@ namespace ts {
5270
(diagnostic, newLine, options) => {
5371
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
5472
let output = `[${formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey)}] `;
55-
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
73+
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine}`;
5674
system.write(output);
5775
} :
5876
(diagnostic, newLine, options) => {
5977
clearScreenIfNotWatchingForFileChanges(system, diagnostic, options);
60-
let output = new Date().toLocaleTimeString() + " - ";
61-
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${newLine + newLine + newLine}`;
78+
let output = `${getPlainDiagnosticPrecedingNewLines(diagnostic, newLine)}${new Date().toLocaleTimeString()} - `;
79+
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${getPlainDiagnosticFollowingNewLines(diagnostic, newLine)}`;
6280
system.write(output);
6381
};
6482
}

0 commit comments

Comments
 (0)