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

Function topLevelPatterns

src/resolution/callback-synthesizer.ts:2403–2419  ·  view source on GitHub ↗

* The patterns `code` destructures at its top, as [opener, closer] pairs: a * declaration's outside every brace, so in no function, class or block, and * never a top-level callback's parameter. Braces alone are counted: JSX text * may hold a stray `(` or `[`, never a `{` that opens no expression,

(code: string)

Source from the content-addressed store, hash-verified

2401 * `code` (`jsxCode`) balances them.
2402 */
2403function topLevelPatterns(code: string): Array<[number, number]> {
2404 const patterns: Array<[number, number]> = [];
2405 let depth = 0;
2406 let at = 0;
2407 DESTRUCTURING_DECLARATION.lastIndex = 0;
2408 for (let m = DESTRUCTURING_DECLARATION.exec(code); m; m = DESTRUCTURING_DECLARATION.exec(code)) {
2409 for (; at < m.index; at++) {
2410 if (code[at] === '{') depth++;
2411 else if (code[at] === '}') depth--;
2412 }
2413 if (depth !== 0) continue;
2414 const open = m.index + m[0].length - 1;
2415 const close = matchingCloser(code, open);
2416 if (close > open) patterns.push([open, close]);
2417 }
2418 return patterns;
2419}
2420
2421/**
2422 * Whether one of `patterns` in `code` binds `name` (`bindingElementAt`), so

Callers 1

destructuredAtTopFunction · 0.85

Calls 3

matchingCloserFunction · 0.85
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected