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

Function handlerCallNames

src/resolution/frameworks/express.ts:74–93  ·  view source on GitHub ↗
(body: string)

Source from the content-addressed store, hash-verified

72 * names nothing this can follow.
73 */
74export function handlerCallNames(body: string): string[] {
75 const out: string[] = [];
76 const seen = new Set<string>();
77 const callRe = /((?:[A-Za-z_$][\w$]*\s*\??\.\s*)*)([A-Za-z_$][\w$]*)\s*\(/g;
78 let cm: RegExpExecArray | null;
79 while ((cm = callRe.exec(body)) !== null) {
80 const method = cm[2]!;
81 const receiver = cm[1]!.replace(/\s|\?/g, '').replace(/\.$/, '');
82 if (!receiver && /\.\s*$/.test(body.slice(0, cm.index))) continue;
83 // A keyword is only a keyword when it isn't a member: `if (` is not a
84 // call, `userService.delete(` is. `function helper(` declares helper.
85 if (!receiver && JS_KEYWORDS.has(method)) continue;
86 if (!receiver && /\bfunction\s*\*?\s*$/.test(body.slice(Math.max(0, cm.index - 12), cm.index))) continue;
87 const name = receiver ? `${receiver}.${method}` : method;
88 if (seen.has(name) || RESERVED_CALLS.has(method)) continue;
89 seen.add(name);
90 out.push(name);
91 }
92 return out;
93}
94
95/**
96 * The replies an inline handler makes — `res.status(404).json({…})`,

Callers 2

routeRefsFunction · 0.90
handlerRefsFunction · 0.85

Calls 4

hasMethod · 0.80
pushMethod · 0.80
execMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected