From ca93e3342ed4b4d10820e7b37ffd064c33e8e6b2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 31 Jul 2017 11:35:08 -0700 Subject: [PATCH 1/2] Generate diagnostics without a leading comma, reatain space --- scripts/processDiagnosticMessages.ts | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index a7f7cdf586bf6..b4f46fa7e778c 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -76,22 +76,13 @@ function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable): string function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable): string { let result = '{'; - let first = true; messageTable.forEach(({ code }, name) => { - if (!first) { - first = false; - } - else { - result += ','; - } - const propName = convertPropertyName(name); - result += `\r\n "${createKey(propName, code)}": "${name.replace(/[\"]/g, '\\"')}"`; + result += `\r\n "${createKey(propName, code)}" : "${name.replace(/[\"]/g, '\\"')}",`; }); - result += '\r\n}'; - - return result; + // Shave trailing comma, then add newline and ending brace + return result.slice(0, result.length - 1) + '\r\n}'; } function createKey(name: string, code: number) : string { From ac84941ce83bd98cecae8dc1f4c38ef78bdc5d78 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 31 Jul 2017 12:33:16 -0700 Subject: [PATCH 2/2] Add small assertion that we generate valid json --- scripts/processDiagnosticMessages.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scripts/processDiagnosticMessages.ts b/scripts/processDiagnosticMessages.ts index b4f46fa7e778c..ff4047d310d54 100644 --- a/scripts/processDiagnosticMessages.ts +++ b/scripts/processDiagnosticMessages.ts @@ -82,7 +82,12 @@ function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable) }); // Shave trailing comma, then add newline and ending brace - return result.slice(0, result.length - 1) + '\r\n}'; + result = result.slice(0, result.length - 1) + '\r\n}'; + + // Assert that we generated valid JSON + JSON.parse(result); + + return result; } function createKey(name: string, code: number) : string {