* The names a parameter list declares: `(Ref ref, {required this.create, * int count = 0})`, `([String? label])`, old-style `void cb(int x)` (`cb`), * untyped closure parameters `(create, {name})`, and a switch arm's pattern * `Foo(:final value) =>`.
(list: string)
| 251 | * `Foo(:final value) =>`. |
| 252 | */ |
| 253 | function parameterNames(list: string): string[] { |
| 254 | const names: string[] = []; |
| 255 | for (const raw of splitParameters(list)) { |
| 256 | let item = raw.replace(/@[\w$.]+(?:\s*\([^()]*\))?/g, ' '); |
| 257 | const eq = item.indexOf('='); |
| 258 | if (eq >= 0) item = item.slice(0, eq); |
| 259 | item = item.trimEnd(); |
| 260 | // `void cb(int x)`: the name is before its own parameter list. |
| 261 | if (item.endsWith(')')) { |
| 262 | let depth = 0; |
| 263 | let at = item.length - 1; |
| 264 | for (; at >= 0; at--) { |
| 265 | if (item[at] === ')') depth++; |
| 266 | else if (item[at] === '(' && --depth === 0) break; |
| 267 | } |
| 268 | item = item.slice(0, Math.max(0, at)).trimEnd(); |
| 269 | } |
| 270 | const name = /([A-Za-z_$][\w$]*)$/.exec(item)?.[1]; |
| 271 | if (name) names.push(name); |
| 272 | } |
| 273 | return names; |
| 274 | } |
| 275 | |
| 276 | /** A parameter list's items, the optional group's (`{…}` / `[…]`, always last) included. */ |
| 277 | function splitParameters(list: string): string[] { |
no test coverage detected