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

Function heldTable

src/resolution/frameworks/react.ts:2192–2208  ·  view source on GitHub ↗

* The tables a value written at `at` gives: the literal there, or the * function a call there names — `getRouteMap({ … })`, `await loadRoutes()` — * whose returned table it is, and through `useMemo` what its callback * returns: `useMemo(() => getRoutes(user), [user])`, `useMemo(getRoutes, [])`.

(safe: string, at: number)

Source from the content-addressed store, hash-verified

2190 * returns: `useMemo(() => getRoutes(user), [user])`, `useMemo(getRoutes, [])`.
2191 */
2192function heldTable(safe: string, at: number): TableSite[] {
2193 // Parentheses around the value change nothing: `return ([ … ])`.
2194 while (safe[at] === '(') at = skipSpace(safe, at + 1);
2195 if (safe[at] === '[' || safe[at] === '{') return [at];
2196 const memo = /(?:React\s*\.\s*)?useMemo\s*(?:<[^()]*>)?\s*\(\s*/y;
2197 memo.lastIndex = at;
2198 if (memo.test(safe)) {
2199 const handed = /([A-Za-z_$][\w$]*)\s*,/y;
2200 handed.lastIndex = memo.lastIndex;
2201 const fn = handed.exec(safe);
2202 return fn ? [{ name: fn[1]!, call: true, at: memo.lastIndex }] : returnedTables(safe, memo.lastIndex);
2203 }
2204 const call = /(await\s+)?([A-Za-z_$][\w$]*)\s*\(/y;
2205 call.lastIndex = at;
2206 const m = call.exec(safe);
2207 return m ? [{ name: m[2]!, call: true, at: at + (m[1]?.length ?? 0) }] : [];
2208}
2209
2210/**
2211 * Picks, of a name's declarations in `file` (where each keyword sits), the

Callers 3

exportedTableFunction · 0.85
declaredTableFunction · 0.85
returnedTablesFunction · 0.85

Calls 3

returnedTablesFunction · 0.85
skipSpaceFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected