@@ -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
8686function buildDiagnosticMessageOutput ( messageTable : InputDiagnosticMessageTable ) : string {
0 commit comments