mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 14:05:47 -05:00
Make processDiagnosticMessages generate a module
This commit is contained in:
@@ -44,10 +44,7 @@ function main() {
|
||||
}
|
||||
}
|
||||
|
||||
const outputFilesDir = path.dirname(inputFilePath);
|
||||
const thisFilePathRel = path.relative(process.cwd(), outputFilesDir);
|
||||
|
||||
const infoFileOutput = buildInfoFileOutput(diagnosticMessages, `./${path.basename(inputFilePath)}`, thisFilePathRel);
|
||||
const infoFileOutput = buildInfoFileOutput(diagnosticMessages, inputFilePath);
|
||||
checkForUniqueCodes(diagnosticMessages);
|
||||
writeFile("diagnosticInformationMap.generated.ts", infoFileOutput);
|
||||
|
||||
@@ -72,31 +69,34 @@ function checkForUniqueCodes(diagnosticTable) {
|
||||
/**
|
||||
* @param {InputDiagnosticMessageTable} messageTable
|
||||
* @param {string} inputFilePathRel
|
||||
* @param {string} thisFilePathRel
|
||||
* @returns {string}
|
||||
*/
|
||||
function buildInfoFileOutput(messageTable, inputFilePathRel, thisFilePathRel) {
|
||||
let result =
|
||||
"// <auto-generated />\r\n" +
|
||||
"// generated from '" + inputFilePathRel + "' in '" + thisFilePathRel.replace(/\\/g, "/") + "'\r\n" +
|
||||
"/* @internal */\r\n" +
|
||||
"namespace ts {\r\n" +
|
||||
" function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {\r\n" +
|
||||
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };\r\n" +
|
||||
" }\r\n" +
|
||||
" export const Diagnostics = {\r\n";
|
||||
function buildInfoFileOutput(messageTable, inputFilePathRel) {
|
||||
const result = [
|
||||
"// <auto-generated />",
|
||||
`// generated from '${inputFilePathRel}'`,
|
||||
"",
|
||||
"import { DiagnosticCategory, DiagnosticMessage } from \"./types\";",
|
||||
"",
|
||||
"function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {",
|
||||
" return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };",
|
||||
"}",
|
||||
"",
|
||||
"/** @internal */",
|
||||
"export const Diagnostics = {",
|
||||
];
|
||||
messageTable.forEach(({ code, category, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated }, name) => {
|
||||
const propName = convertPropertyName(name);
|
||||
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${reportsUnnecessary}` : "";
|
||||
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${!reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : ""}, /*elidedInCompatabilityPyramid*/ ${elidedInCompatabilityPyramid}` : "";
|
||||
const argReportsDeprecated = reportsDeprecated ? `${!argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : ""}, /*reportsDeprecated*/ ${reportsDeprecated}` : "";
|
||||
|
||||
result += ` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),\r\n`;
|
||||
result.push(` ${propName}: diag(${code}, DiagnosticCategory.${category}, "${createKey(propName, code)}", ${JSON.stringify(name)}${argReportsUnnecessary}${argElidedInCompatabilityPyramid}${argReportsDeprecated}),`);
|
||||
});
|
||||
|
||||
result += " };\r\n}";
|
||||
result.push("};");
|
||||
|
||||
return result;
|
||||
return result.join("\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user