* Find every `@Name(...)` decorator whose name is in `names`. Uses a * string-aware balanced-paren reader for the argument list so type thunks * like `@Query(() => [User])` are captured whole rather than truncated at the * inner `()`.
(safe: string, names: string[])
| 306 | * inner `()`. |
| 307 | */ |
| 308 | function findDecorators(safe: string, names: string[]): DecoratorHit[] { |
| 309 | const hits: DecoratorHit[] = []; |
| 310 | const re = new RegExp(`@(${names.join('|')})\\s*\\(`, 'g'); |
| 311 | let m: RegExpExecArray | null; |
| 312 | while ((m = re.exec(safe)) !== null) { |
| 313 | const openIndex = m.index + m[0].length - 1; // position of '(' |
| 314 | const parsed = readArgs(safe, openIndex); |
| 315 | if (!parsed) continue; |
| 316 | hits.push({ |
| 317 | name: m[1]!, |
| 318 | args: parsed.args, |
| 319 | index: m.index, |
| 320 | end: parsed.end, |
| 321 | length: parsed.end - m.index, |
| 322 | }); |
| 323 | re.lastIndex = parsed.end; // resume past the args so nested text isn't re-scanned |
| 324 | } |
| 325 | return hits; |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Read a balanced `(...)` starting at `openIndex` (which must point at `(`). |
no test coverage detected