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

Function topLevelArgs

src/resolution/frameworks/express.ts:470–502  ·  view source on GitHub ↗

`args` split at its top-level commas, each piece with its offset into `args`.

(args: string)

Source from the content-addressed store, hash-verified

468
469/** `args` split at its top-level commas, each piece with its offset into `args`. */
470function topLevelArgs(args: string): Array<{ text: string; start: number }> {
471 const out: Array<{ text: string; start: number }> = [];
472 let depth = 0;
473 let start = 0;
474 for (let i = 0; i < args.length; i++) {
475 const ch = args[i];
476 if (ch === '"' || ch === "'" || ch === '`') {
477 const q = ch;
478 i++;
479 while (i < args.length && args[i] !== q) {
480 if (args[i] === '\\') i++;
481 i++;
482 }
483 continue;
484 }
485 if (ch === '<' && i > 0 && /[\w$]/.test(args[i - 1]!)) {
486 // A type-argument list (`asyncHandler<Req, Res>(`): its commas split nothing.
487 const generic = /^<[^()<>]*(?:<[^()<>]*>[^()<>]*)*>\s*\(/.exec(args.slice(i));
488 if (generic) {
489 i += generic[0].length - 2;
490 continue;
491 }
492 }
493 if (ch === '(' || ch === '[' || ch === '{') depth++;
494 else if (ch === ')' || ch === ']' || ch === '}') depth--;
495 else if (ch === ',' && depth === 0) {
496 out.push({ text: args.slice(start, i), start });
497 start = i + 1;
498 }
499 }
500 out.push({ text: args.slice(start), start });
501 return out;
502}
503
504/**
505 * What a route call's handler contributes. The handler is the LAST argument —

Callers 2

postExtractFunction · 0.85
handlerRefsFunction · 0.85

Calls 2

pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected