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

Function handlerCallNames

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

Source from the content-addressed store, hash-verified

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