* Process the given typescript source. * * For details, see the inlined comments. * * @param {string} definitionsPath The path of the defintions file * @param {string} source The source * @returns The new source
(definitionsPath, source)
| 1090 | * @returns The new source |
| 1091 | */ |
| 1092 | function processTypescriptSource(definitionsPath, source) { |
| 1093 | // All of our enum assignments that alias to WebGLConstants, such as PixelDatatype.js |
| 1094 | // end up as enum strings instead of actually mapping values to WebGLConstants. |
| 1095 | // We fix this with a simple regex replace later on, but it means the |
| 1096 | // WebGLConstants constants enum needs to be defined in the file before it can |
| 1097 | // be used. This block of code reads in the TS file, finds the WebGLConstants |
| 1098 | // declaration, and then writes the file back out (in memory to source) with |
| 1099 | // WebGLConstants being the first module. |
| 1100 | const node = typeScript.createSourceFile( |
| 1101 | definitionsPath, |
| 1102 | source, |
| 1103 | typeScript.ScriptTarget.Latest, |
| 1104 | ); |
| 1105 | let firstNode; |
| 1106 | node.forEachChild((child) => { |
| 1107 | if ( |
| 1108 | typeScript.SyntaxKind[child.kind] === "EnumDeclaration" && |
| 1109 | child.name.escapedText === "WebGLConstants" |
| 1110 | ) { |
| 1111 | firstNode = child; |
| 1112 | } |
| 1113 | }); |
| 1114 | |
| 1115 | const printer = typeScript.createPrinter({ |
| 1116 | removeComments: false, |
| 1117 | newLine: typeScript.NewLineKind.LineFeed, |
| 1118 | }); |
| 1119 | |
| 1120 | let newSource = ""; |
| 1121 | newSource += printer.printNode( |
| 1122 | typeScript.EmitHint.Unspecified, |
| 1123 | firstNode, |
| 1124 | node, |
| 1125 | ); |
| 1126 | newSource += "\n\n"; |
| 1127 | node.forEachChild((child) => { |
| 1128 | if ( |
| 1129 | typeScript.SyntaxKind[child.kind] !== "EnumDeclaration" || |
| 1130 | child.name.escapedText !== "WebGLConstants" |
| 1131 | ) { |
| 1132 | newSource += printer.printNode( |
| 1133 | typeScript.EmitHint.Unspecified, |
| 1134 | child, |
| 1135 | node, |
| 1136 | ); |
| 1137 | newSource += "\n\n"; |
| 1138 | } |
| 1139 | }); |
| 1140 | return newSource; |
| 1141 | } |
| 1142 | |
| 1143 | function processEngineSource(definitionsPath, source) { |
| 1144 | let newSource = processTypescriptSource(definitionsPath, source); |
no outgoing calls
no test coverage detected
searching dependent graphs…