Skip to content

Commit 809349d

Browse files
committed
Make processDiagnosticMessages.ts generate a module
(Also improve the generated comment at the top.)
1 parent 548a326 commit 809349d

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

scripts/processDiagnosticMessages.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ function main(): void {
3838
}
3939
}
4040

41-
const outputFilesDir = path.dirname(inputFilePath);
42-
const thisFilePathRel = path.relative(process.cwd(), outputFilesDir);
43-
44-
const infoFileOutput = buildInfoFileOutput(diagnosticMessages, "./diagnosticInformationMap.generated.ts", thisFilePathRel);
41+
const infoFileOutput = buildInfoFileOutput(diagnosticMessages, inputFilePath);
4542
checkForUniqueCodes(diagnosticMessages);
4643
writeFile("diagnosticInformationMap.generated.ts", infoFileOutput);
4744

@@ -59,28 +56,31 @@ function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
5956
});
6057
}
6158

62-
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string, thisFilePathRel: string): string {
63-
let result =
64-
"// <auto-generated />\r\n" +
65-
"// generated from '" + inputFilePathRel + "' by '" + thisFilePathRel.replace(/\\/g, "/") + "'\r\n" +
66-
"/* @internal */\r\n" +
67-
"namespace ts {\r\n" +
68-
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {\r\n" +
69-
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };\r\n" +
70-
" }\r\n" +
71-
" export const Diagnostics = {\r\n";
59+
function buildInfoFileOutput(messageTable: InputDiagnosticMessageTable, inputFilePathRel: string): string {
60+
const result = [
61+
"// <auto-generated />",
62+
`// generated from '${inputFilePathRel}'`,
63+
"",
64+
"import { DiagnosticCategory, DiagnosticMessage } from \"./ts\";",
65+
"",
66+
"function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {",
67+
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };",
68+
"}",
69+
"",
70+
"export const Diagnostics = {",
71+
];
7272
messageTable.forEach(({ code, category, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated }, name) => {
7373
const propName = convertPropertyName(name);
7474
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${reportsUnnecessary}` : "";
7575
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : "";
7676
const argReportsDeprecated = reportsDeprecated ? `${!argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : ""}, /*reportsDeprecated*/ ${reportsDeprecated}` : "";
7777

78-
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),\r\n`;
78+
result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),`);
7979
});
8080

81-
result += " };\r\n}";
81+
result.push("};");
8282

83-
return result;
83+
return result.join("\r\n");
8484
}
8585

8686
function buildDiagnosticMessageOutput(messageTable: InputDiagnosticMessageTable): string {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy