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

Function topLevelArgs

src/resolution/frameworks/express.ts:484–516  ·  view source on GitHub ↗
(args: string)

Source from the content-addressed store, hash-verified

482
483/** `args` split at its top-level commas, each piece with its offset into `args`. */
484export function topLevelArgs(args: string): Array<{ text: string; start: number }> {
485 const out: Array<{ text: string; start: number }> = [];
486 let depth = 0;
487 let start = 0;
488 for (let i = 0; i < args.length; i++) {
489 const ch = args[i];
490 if (ch === '"' || ch === "'" || ch === '`') {
491 const q = ch;
492 i++;
493 while (i < args.length && args[i] !== q) {
494 if (args[i] === '\\') i++;
495 i++;
496 }
497 continue;
498 }
499 if (ch === '<' && i > 0 && /[\w$]/.test(args[i - 1]!)) {
500 // A type-argument list (`asyncHandler<Req, Res>(`): its commas split nothing.
501 const generic = /^<[^()<>]*(?:<[^()<>]*>[^()<>]*)*>\s*\(/.exec(args.slice(i));
502 if (generic) {
503 i += generic[0].length - 2;
504 continue;
505 }
506 }
507 if (ch === '(' || ch === '[' || ch === '{') depth++;
508 else if (ch === ')' || ch === ']' || ch === '}') depth--;
509 else if (ch === ',' && depth === 0) {
510 out.push({ text: args.slice(start, i), start });
511 start = i + 1;
512 }
513 }
514 out.push({ text: args.slice(start), start });
515 return out;
516}
517
518/**
519 * What a route call's handler contributes. The handler is the LAST argument —

Callers 5

onLinkFunction · 0.90
useSiteFunction · 0.90
routeRefsFunction · 0.90
postExtractFunction · 0.85
handlerRefsFunction · 0.85

Calls 2

pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected