(input: string[])
| 164 | } |
| 165 | |
| 166 | removeUnusedLabels(input: string[]): string[] { |
| 167 | const output: string[] = []; |
| 168 | |
| 169 | const lineRe = /^.*main__.*$/; |
| 170 | const mainFunctionCall = '\tmain__main();'; |
| 171 | |
| 172 | let scopeDepth = 0; |
| 173 | let insertNewLine = false; |
| 174 | |
| 175 | for (const lineNo in input) { |
| 176 | const line = input[lineNo]; |
| 177 | if (!line) continue; |
| 178 | |
| 179 | if (insertNewLine) { |
| 180 | output.push(''); |
| 181 | insertNewLine = false; |
| 182 | } |
| 183 | |
| 184 | if ((scopeDepth === 0 && lineRe.test(line) && line !== mainFunctionCall) || scopeDepth > 0) { |
| 185 | const opening = (line.match(/{/g) || []).length - 1; |
| 186 | const closing = (line.match(/}/g) || []).length - 1; |
| 187 | scopeDepth += opening - closing; |
| 188 | |
| 189 | output.push(line); |
| 190 | |
| 191 | insertNewLine = scopeDepth === 0; |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | return output; |
| 196 | } |
| 197 | |
| 198 | removeWhitespaceLines = (input: string[]) => input.map(line => line.trimStart()).filter(line => line !== ''); |
| 199 | removeComments = (input: string[]) => |
no test coverage detected