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

Function scanCall

src/resolution/frameworks/express.ts:379–419  ·  view source on GitHub ↗

* The call whose `(` is at `open`, scanned from there to its matching `)`: * its close, and its text with string contents and regex-literal bodies * blanked (offsets kept) so `/[^]]/`, `/}/`, `'a, b)'` or a backtick in a regex * can't end an argument or a body early. Scanned per call, from the ca

(safe: string, open: number)

Source from the content-addressed store, hash-verified

377 * throw it off.
378 */
379function scanCall(safe: string, open: number): { close: number; structure: string } | null {
380 const out: string[] = [];
381 let depth = 0;
382 for (let i = open; i < safe.length; i++) {
383 const c = safe[i]!;
384 if ((c === '"' || c === "'") && !closesOnLine(safe, i)) {
385 // JSX text (`<p>Don't</p>`), not a string: an apostrophe with no
386 // closing quote on its line must not blank the `)` after it.
387 out.push(c);
388 continue;
389 }
390 if (c === '"' || c === "'" || c === '`') {
391 out.push(c);
392 for (i++; i < safe.length && safe[i] !== c; i++) {
393 if (c !== '`' && safe[i] === '\n') break;
394 if (safe[i] === '\\' && i + 1 < safe.length) {
395 out.push(' ');
396 i++;
397 }
398 out.push(safe[i] === '\n' ? '\n' : ' ');
399 }
400 if (i < safe.length) out.push(safe[i]!);
401 continue;
402 }
403 if (c === '/' && safe[i + 1] !== '/' && safe[i + 1] !== '*') {
404 const end = regexLiteralEndAt(safe, i);
405 if (end > i) {
406 out.push('/', ...' '.repeat(end - i - 1), '/');
407 i = end;
408 continue;
409 }
410 }
411 out.push(c);
412 if (c === '(') depth++;
413 else if (c === ')') {
414 depth--;
415 if (depth === 0) return { close: i, structure: out.join('') };
416 }
417 }
418 return null;
419}
420
421/** Whether the quote at `i` has an unescaped closing quote on the same line. */
422function closesOnLine(s: string, i: number): boolean {

Callers 2

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