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

Function handlerCallNames

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

Source from the content-addressed store, hash-verified

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