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

Function declare

src/resolution/frameworks/react.ts:1742–1761  ·  view source on GitHub ↗

Bind each declarator of a `const`, `let` or `var` whose first pattern starts at `at`; where the declaration ends.

(body: string, at: number, scope: Map<string, Loaded | null>)

Source from the content-addressed store, hash-verified

1740
1741/** Bind each declarator of a `const`, `let` or `var` whose first pattern starts at `at`; where the declaration ends. */
1742function declare(body: string, at: number, scope: Map<string, Loaded | null>): number {
1743 for (let i = at; ;) {
1744 while (/\s/.test(body[i] ?? '')) i++;
1745 let end: number;
1746 if (body[i] === '{' || body[i] === '[') end = matchBracket(body, i) + 1;
1747 else end = i + (/^[A-Za-z_$][\w$]*/.exec(body.slice(i, i + 128))?.[0].length ?? 0);
1748 if (end <= i) return Math.max(end, i + 1);
1749 const pattern = body.slice(i, end);
1750 const init = initializerAt(body, end);
1751 let stop = end;
1752 if (init < 0) bindPattern(scope, pattern, null);
1753 else {
1754 stop = statementEnd(body, init, true);
1755 bindPattern(scope, pattern, valueOf(body.slice(init, stop), scope));
1756 }
1757 while (/\s/.test(body[stop] ?? '')) stop++;
1758 if (body[stop] !== ',') return stop;
1759 i = stop + 1;
1760 }
1761}
1762
1763/** Where a declarator's initializer starts, past its `: Type` and `=`; -1 when it has none. */
1764export function initializerAt(body: string, at: number): number {

Callers 2

declarePascalInlineMethod · 0.85
blockValueFunction · 0.85

Calls 6

matchBracketFunction · 0.90
initializerAtFunction · 0.85
bindPatternFunction · 0.70
statementEndFunction · 0.70
valueOfFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected