@@ -38,10 +38,7 @@ function main(): void {
38
38
}
39
39
}
40
40
41
- const outputFilesDir = path . dirname ( inputFilePath ) ;
42
- const thisFilePathRel = path . relative ( process . cwd ( ) , outputFilesDir ) ;
43
-
44
- const infoFileOutput = buildInfoFileOutput ( diagnosticMessages , `./${ path . basename ( inputFilePath ) } ` , thisFilePathRel ) ;
41
+ const infoFileOutput = buildInfoFileOutput ( diagnosticMessages , inputFilePath ) ;
45
42
checkForUniqueCodes ( diagnosticMessages ) ;
46
43
writeFile ( "diagnosticInformationMap.generated.ts" , infoFileOutput ) ;
47
44
@@ -59,28 +56,32 @@ function checkForUniqueCodes(diagnosticTable: InputDiagnosticMessageTable) {
59
56
} ) ;
60
57
}
61
58
62
- function buildInfoFileOutput ( messageTable : InputDiagnosticMessageTable , inputFilePathRel : string , thisFilePathRel : string ) : string {
63
- let result =
64
- "// <auto-generated />\r\n" +
65
- "// generated from '" + inputFilePathRel + "' in '" + 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 \"./types\";" ,
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
+ "/** @internal */" ,
71
+ "export const Diagnostics = {" ,
72
+ ] ;
72
73
messageTable . forEach ( ( { code, category, reportsUnnecessary, elidedInCompatabilityPyramid, reportsDeprecated } , name ) => {
73
74
const propName = convertPropertyName ( name ) ;
74
75
const argReportsUnnecessary = reportsUnnecessary ? `, /*reportsUnnecessary*/ ${ reportsUnnecessary } ` : "" ;
75
76
const argElidedInCompatabilityPyramid = elidedInCompatabilityPyramid ? `${ ! reportsUnnecessary ? ", /*reportsUnnecessary*/ undefined" : "" } , /*elidedInCompatabilityPyramid*/ ${ elidedInCompatabilityPyramid } ` : "" ;
76
77
const argReportsDeprecated = reportsDeprecated ? `${ ! argElidedInCompatabilityPyramid ? ", /*reportsUnnecessary*/ undefined, /*elidedInCompatabilityPyramid*/ undefined" : "" } , /*reportsDeprecated*/ ${ reportsDeprecated } ` : "" ;
77
78
78
- result += ` ${ propName } : diag(${ code } , DiagnosticCategory.${ category } , "${ createKey ( propName , code ) } ", ${ JSON . stringify ( name ) } ${ argReportsUnnecessary } ${ argElidedInCompatabilityPyramid } ${ argReportsDeprecated } ),\r\n` ;
79
+ result . push ( ` ${ propName } : diag(${ code } , DiagnosticCategory.${ category } , "${ createKey ( propName , code ) } ", ${ JSON . stringify ( name ) } ${ argReportsUnnecessary } ${ argElidedInCompatabilityPyramid } ${ argReportsDeprecated } ),` ) ;
79
80
} ) ;
80
81
81
- result += " };\r\n}" ;
82
+ result . push ( "};" ) ;
82
83
83
- return result ;
84
+ return result . join ( "\r\n" ) ;
84
85
}
85
86
86
87
function buildDiagnosticMessageOutput ( messageTable : InputDiagnosticMessageTable ) : string {
0 commit comments