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

Function heldTable

src/resolution/frameworks/react.ts:2170–2186  ·  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

2168 * returns: `useMemo(() => getRoutes(user), [user])`, `useMemo(getRoutes, [])`.
2169 */
2170function heldTable(safe: string, at: number): TableSite[] {
2171 // Parentheses around the value change nothing: `return ([ … ])`.
2172 while (safe[at] === '(') at = skipSpace(safe, at + 1);
2173 if (safe[at] === '[' || safe[at] === '{') return [at];
2174 const memo = /(?:React\s*\.\s*)?useMemo\s*(?:<[^()]*>)?\s*\(\s*/y;
2175 memo.lastIndex = at;
2176 if (memo.test(safe)) {
2177 const handed = /([A-Za-z_$][\w$]*)\s*,/y;
2178 handed.lastIndex = memo.lastIndex;
2179 const fn = handed.exec(safe);
2180 return fn ? [{ name: fn[1]!, call: true, at: memo.lastIndex }] : returnedTables(safe, memo.lastIndex);
2181 }
2182 const call = /(await\s+)?([A-Za-z_$][\w$]*)\s*\(/y;
2183 call.lastIndex = at;
2184 const m = call.exec(safe);
2185 return m ? [{ name: m[2]!, call: true, at: at + (m[1]?.length ?? 0) }] : [];
2186}
2187
2188/**
2189 * 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