* The names a function argument's parameters bind, read from its parameter * list (`({ body, cookie: { auth } }, extra) =>` gives body, cookie, auth, * extra): every identifier in it, which can only over-read a destructured * key or a type. Empty for anything but an arrow or a `function`.
(text: string)
| 551 | * key or a type. Empty for anything but an arrow or a `function`. |
| 552 | */ |
| 553 | function parameterNames(text: string): Set<string> { |
| 554 | const single = /^\s*(?:async\s+)?([A-Za-z_$][\w$]*)\s*=>/.exec(text); |
| 555 | if (single) return new Set([single[1]!]); |
| 556 | const head = /^\s*(?:async\s*)?(?:function\b\s*\*?\s*[\w$]*\s*)?\(/.exec(text); |
| 557 | if (!head) return new Set(); |
| 558 | let depth = 0; |
| 559 | let end = head[0].length - 1; |
| 560 | for (; end < text.length; end++) { |
| 561 | if (text[end] === '(') depth++; |
| 562 | else if (text[end] === ')' && --depth === 0) break; |
| 563 | } |
| 564 | return new Set(text.slice(head[0].length, end).match(/[A-Za-z_$][\w$]*/g) ?? []); |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * The references a route's handler makes. A named one (`getUser`, |