True when the `)` at `code[close]` closes a function declarator's parameter list.
(code: string, close: number)
| 1008 | |
| 1009 | /** True when the `)` at `code[close]` closes a function declarator's parameter list. */ |
| 1010 | function closesParameterList(code: string, close: number): boolean { |
| 1011 | let depth = 0; |
| 1012 | let open = -1; |
| 1013 | for (let i = close; i >= 0 && close - i < 4000; i--) { |
| 1014 | const c = code[i]; |
| 1015 | if (c === ')') depth++; |
| 1016 | else if (c === '(') { |
| 1017 | if (--depth === 0) { open = i; break; } |
| 1018 | } else if (c === ';' || c === '{' || c === '}') return false; |
| 1019 | } |
| 1020 | if (open < 0) return false; |
| 1021 | const before = code.slice(Math.max(0, open - 200), open); |
| 1022 | // `operator()(…)`, `operator==(…)`, `operator bool(…)` |
| 1023 | if (/\boperator\s*(?:\(\s*\)|\[\s*\]|[^\s\w()[\]]{1,3}|\s+[A-Za-z_][\w\s:<>*&]*)\s*$/.test(before)) return true; |
| 1024 | const name = /([A-Za-z_]\w*)\s*$/.exec(before)?.[1]; |
| 1025 | return !!name && !CPP_PAREN_KEYWORDS.has(name) && !/^[A-Z][A-Z0-9_]*$/.test(name); |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Blank attribute macros that open a declaration, at the start of a line or |
no test coverage detected