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

Function scanCall

src/resolution/frameworks/express.ts:391–433  ·  view source on GitHub ↗
(safe: string, open: number)

Source from the content-addressed store, hash-verified

389 * way (a function body, for the Elysia resolver).
390 */
391export function scanCall(safe: string, open: number): { close: number; structure: string } | null {
392 const oc = safe[open];
393 const cc = oc === '{' ? '}' : oc === '[' ? ']' : ')';
394 const out: string[] = [];
395 let depth = 0;
396 for (let i = open; i < safe.length; i++) {
397 const c = safe[i]!;
398 if ((c === '"' || c === "'") && !closesOnLine(safe, i)) {
399 // JSX text (`<p>Don't</p>`), not a string: an apostrophe with no
400 // closing quote on its line must not blank the `)` after it.
401 out.push(c);
402 continue;
403 }
404 if (c === '"' || c === "'" || c === '`') {
405 out.push(c);
406 for (i++; i < safe.length && safe[i] !== c; i++) {
407 if (c !== '`' && safe[i] === '\n') break;
408 if (safe[i] === '\\' && i + 1 < safe.length) {
409 out.push(' ');
410 i++;
411 }
412 out.push(safe[i] === '\n' ? '\n' : ' ');
413 }
414 if (i < safe.length) out.push(safe[i]!);
415 continue;
416 }
417 if (c === '/' && safe[i + 1] !== '/' && safe[i + 1] !== '*') {
418 const end = regexLiteralEndAt(safe, i);
419 if (end > i) {
420 out.push('/', ...' '.repeat(end - i - 1), '/');
421 i = end;
422 continue;
423 }
424 }
425 out.push(c);
426 if (c === oc) depth++;
427 else if (c === cc) {
428 depth--;
429 if (depth === 0) return { close: i, structure: out.join('') };
430 }
431 }
432 return null;
433}
434
435/** Whether the quote at `i` has an unescaped closing quote on the same line. */
436export function closesOnLine(s: string, i: number): boolean {

Callers 8

walkRangeFunction · 0.90
typedParameterFunction · 0.90
walkBodyFunction · 0.90
walkChainFunction · 0.90
useSiteFunction · 0.90
routeRefsFunction · 0.90
extractFunction · 0.85
postExtractFunction · 0.85

Calls 4

closesOnLineFunction · 0.85
regexLiteralEndAtFunction · 0.85
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected