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

Function bindsPattern

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

* Whether the `{` or `[` at `opener` opens a pattern that binds its names: a * declaration's, unless it declares an import, or a parameter's — itself or * through the patterns it nests in.

(code: string, opener: number, depth: number)

Source from the content-addressed store, hash-verified

2403 * through the patterns it nests in.
2404 */
2405function bindsPattern(code: string, opener: number, depth: number): boolean {
2406 if (depth > 8) return false;
2407 const p = skipSpace(code, opener - 1, -1);
2408 const c = code[p];
2409 if (c === '(') return opensParameters(code, p);
2410 if (c === '[') return bindsPattern(code, p, depth + 1);
2411 if (c === ',') {
2412 const q = enclosingOpener(code, p - 1);
2413 if (code[q] === '(') return opensParameters(code, q);
2414 return code[q] === '[' && bindsPattern(code, q, depth + 1);
2415 }
2416 if (c === ':') {
2417 // `{ key: { … } }` nests a pattern; `props: {` and `}: {` annotate a type.
2418 if (!keyOpensElement(code, p)) return false;
2419 const q = enclosingOpener(code, p - 1);
2420 return code[q] === '{' && bindsPattern(code, q, depth + 1);
2421 }
2422 if (!ID_CHAR.test(c ?? '')) return false;
2423 const word = wordEndingAt(code, p);
2424 if (word !== 'const' && word !== 'let' && word !== 'var') return false;
2425 const close = matchingCloser(code, opener);
2426 if (close < 0) return false;
2427 IMPORTED_VALUE.lastIndex = close + 1;
2428 return !IMPORTED_VALUE.test(code);
2429}
2430
2431/**
2432 * Whether the `(` at `paren` opens a parameter list: an arrow or a body

Callers 1

bindingElementAtFunction · 0.85

Calls 6

opensParametersFunction · 0.85
enclosingOpenerFunction · 0.85
keyOpensElementFunction · 0.85
wordEndingAtFunction · 0.85
matchingCloserFunction · 0.85
skipSpaceFunction · 0.70

Tested by

no test coverage detected