MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / parameterNames

Function parameterNames

src/resolution/dart-local-scope.ts:253–274  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

251 * `Foo(:final value) =>`.
252 */
253function 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. */
277function splitParameters(list: string): string[] {

Callers 1

bindParametersFunction · 0.70

Calls 3

pushMethod · 0.80
splitParametersFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected