@@ -44,10 +44,7 @@ function main() {
44
44
}
45
45
}
46
46
47
- const outputFilesDir = path . dirname ( inputFilePath ) ;
48
- const thisFilePathRel = path . relative ( process . cwd ( ) , outputFilesDir ) ;
49
-
50
- const infoFileOutput = buildInfoFileOutput ( diagnosticMessages , `./${ path . basename ( inputFilePath ) } ` , thisFilePathRel ) ;
47
+ const infoFileOutput = buildInfoFileOutput ( diagnosticMessages , inputFilePath ) ;
51
48
checkForUniqueCodes ( diagnosticMessages ) ;
52
49
writeFile ( "diagnosticInformationMap.generated.ts" , infoFileOutput ) ;
53
50
@@ -72,31 +69,34 @@ function checkForUniqueCodes(diagnosticTable) {
72
69
/**
73
70
* @param {InputDiagnosticMessageTable } messageTable
74
71
* @param {string } inputFilePathRel
75
- * @param {string } thisFilePathRel
76
72
* @returns {string }
77
73
*/
78
- function buildInfoFileOutput ( messageTable , inputFilePathRel , thisFilePathRel ) {
79
- let result =
80
- "// <auto-generated />\r\n" +
81
- "// generated from '" + inputFilePathRel + "' in '" + thisFilePathRel . replace ( / \\ / g, "/" ) + "'\r\n" +
82
- "/* @internal */\r\n" +
83
- "namespace ts {\r\n" +
84
- " function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {\r\n" +
85
- " return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };\r\n" +
86
- " }\r\n" +
87
- " export const Diagnostics = {\r\n" ;
74
+ function buildInfoFileOutput ( messageTable , inputFilePathRel ) {
75
+ const result = [
76
+ "// <auto-generated />" ,
77
+ `// generated from '${ inputFilePathRel } '` ,
78
+ "" ,
79
+ "import { DiagnosticCategory, DiagnosticMessage } from \"./types\";" ,
80
+ "" ,
81
+ "function diag(code: number, category: DiagnosticCategory, key: string, message: string, reportsUnnecessary?: {}, elidedInCompatabilityPyramid?: boolean, reportsDeprecated?: {}): DiagnosticMessage {" ,
82
+ " return { code, category, key, message, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated };" ,
83
+ "}" ,
84
+ "" ,
85
+ "/** @internal */" ,
86
+ "export const Diagnostics = {" ,
87
+ ] ;
88
88
messageTable . forEach ( ( { code, category, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated } , name ) => {
89
89
const propName = convertPropertyName ( name ) ;
90
90
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${ reportsUnnecessary } ` : "" ;
91
91
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${ ! reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : "" } , /*elidedInCompatabilityPyramid*/ ${ elidedInCompatabilityPyramid } ` : "" ;
92
92
const argReportsDeprecated = reportsDeprecated ? `${ ! argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : "" } , /*reportsDeprecated*/ ${ reportsDeprecated } ` : "" ;
93
93
94
- result += ` ${ propName } : diag(${ code } , DiagnosticCategory.${ category } , "${ createKey ( propName , code ) } ", ${ JSON . stringify ( name ) } ${ argReportsUnnecessary } ${ argElidedInCompatabilityPyramid } ${ argReportsDeprecated } ),\r\n` ;
94
+ result . push ( ` ${ propName } : diag(${ code } , DiagnosticCategory.${ category } , "${ createKey ( propName , code ) } ", ${ JSON . stringify ( name ) } ${ argReportsUnnecessary } ${ argElidedInCompatabilityPyramid } ${ argReportsDeprecated } ),` ) ;
95
95
} ) ;
96
96
97
- result += " };\r\n}" ;
97
+ result . push ( "};" ) ;
98
98
99
- return result ;
99
+ return result . join ( "\r\n" ) ;
100
100
}
101
101
102
102
/**
0 commit comments