( parser: Parser, query: Query, sourceCode: string, )
| 352 | } |
| 353 | |
| 354 | function parseFile( |
| 355 | parser: Parser, |
| 356 | query: Query, |
| 357 | sourceCode: string, |
| 358 | ): { [key: string]: string[] } { |
| 359 | const tree = parser.parse(sourceCode) |
| 360 | if (!tree) { |
| 361 | return {} |
| 362 | } |
| 363 | try { |
| 364 | const captures = query.captures(tree.rootNode) |
| 365 | const result: { [key: string]: string[] } = {} |
| 366 | |
| 367 | for (const capture of captures) { |
| 368 | const { name, node } = capture |
| 369 | if (!result[name]) { |
| 370 | result[name] = [] |
| 371 | } |
| 372 | result[name].push(node.text) |
| 373 | } |
| 374 | |
| 375 | return result |
| 376 | } finally { |
| 377 | ;(tree as { delete?: () => void }).delete?.() |
| 378 | } |
| 379 | } |
no test coverage detected