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

Function blockValue

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

* The value a function body hands back from its first top-level `return`, * its declarations bound on the way there. Nested blocks and functions are * stepped over: what is declared or returned in there is theirs.

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

Source from the content-addressed store, hash-verified

1731 * stepped over: what is declared or returned in there is theirs.
1732 */
1733function blockValue(body: string, scope: Map<string, Loaded | null>): Loaded | null {
1734 const word = /[A-Za-z_$][\w$]*/y;
1735 for (let i = 0; i < body.length;) {
1736 const ch = body[i]!;
1737 if (ch === '"' || ch === "'" || ch === '`' || ch === '{' || ch === '(' || ch === '[') {
1738 const end = ch === '{' || ch === '(' || ch === '[' ? matchBracket(body, i) : skipString(body, i);
1739 if (end < 0) return null;
1740 i = end + 1;
1741 continue;
1742 }
1743 word.lastIndex = i;
1744 const w = word.exec(body)?.[0];
1745 if (!w) {
1746 i++;
1747 continue;
1748 }
1749 const after = i + w.length;
1750 const statement = i === 0 || !/[\w$.]/.test(body[i - 1]!);
1751 i = after;
1752 if (!statement) continue;
1753 if (w === 'return') return valueOf(body.slice(after, statementEnd(body, after)), scope);
1754 if (w === 'const' || w === 'let' || w === 'var') i = declare(body, after, scope);
1755 else if (w === 'function' || w === 'class') {
1756 const name = /^\s*\*?\s*([A-Za-z_$][\w$]*)/.exec(body.slice(after, after + 128));
1757 if (name) scope.set(name[1]!, null);
1758 }
1759 }
1760 return null;
1761}
1762
1763/** Bind each declarator of a `const`, `let` or `var` whose first pattern starts at `at`; where the declaration ends. */
1764function declare(body: string, at: number, scope: Map<string, Loaded | null>): number {

Callers 1

loaderValueFunction · 0.85

Calls 7

matchBracketFunction · 0.90
skipStringFunction · 0.90
declareFunction · 0.85
valueOfFunction · 0.70
statementEndFunction · 0.70
execMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected