Skip to content

Commit 32d9292

Browse files
authored
Generate diagnostics without a leading comma, retain old spaces (#17534)
* Generate diagnostics without a leading comma, reatain space * Add small assertion that we generate valid json
1 parent f945b26 commit 32d9292

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,16 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string
7676

7777
function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable): string {
7878
let result = '{';
79-
let first = true;
8079
messageTable.forEach(({ code }, name) => {
81-
if (!first) {
82-
first = false;
83-
}
84-
else {
85-
result += ',';
86-
}
87-
8880
const propName = convertPropertyName(name);
89-
result += `\r\n "${createKey(propName, code)}": "${name.replace(/[\"]/g, '\\"')}"`;
81+
result += `\r\n "${createKey(propName, code)}" : "${name.replace(/[\"]/g, '\\"')}",`;
9082
});
9183

92-
result += '\r\n}';
84+
// Shave trailing comma, then add newline and ending brace
85+
result = result.slice(0, result.length - 1) + '\r\n}';
86+
87+
// Assert that we generated valid JSON
88+
JSON.parse(result);
9389

9490
return result;
9591
}

0 commit comments

Comments
 (0)