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

Function declaredTable

src/resolution/frameworks/react.ts:2142–2159  ·  view source on GitHub ↗

* Where `name`'s table literal opens, for `const name = [ … ]` (or the tables * a function returns when `call`) — or, for `const name = getRouteMap({ … * })`, the function whose returned table the value holds. Of several * declarations of the name, the one `visible` picks.

(
  safe: string,
  name: string,
  call: boolean,
  visible: (keywords: number[]) => number | undefined
)

Source from the content-addressed store, hash-verified

2140 * declarations of the name, the one `visible` picks.
2141 */
2142function declaredTable(
2143 safe: string,
2144 name: string,
2145 call: boolean,
2146 visible: (keywords: number[]) => number | undefined
2147): TableSite[] {
2148 const id = escapeRegExp(name);
2149 const decls = [...safe.matchAll(new RegExp(`(?:^|[^\\w$.])((?:const|let|var)\\s+${id}\\s*(?::[^=;]*)?=\\s*)`, 'g'))];
2150 const chosen = decls.length > 0 ? visible(decls.map((d) => d.index + d[0].length - d[1]!.length)) : undefined;
2151 const decl = chosen === undefined ? undefined : decls[chosen];
2152 if (decl) {
2153 const after = decl.index + decl[0].length;
2154 return call ? returnedTables(safe, after) : heldTable(safe, after);
2155 }
2156 if (!call) return [];
2157 const fn = new RegExp(`(?:^|[^\\w$.])function\\s+${id}\\s*\\(`).exec(safe);
2158 return fn ? returnedTables(safe, fn.index + fn[0].indexOf('function')) : [];
2159}
2160
2161/** A table to read: where its literal opens in the file at hand, or a function whose returned tables to read. */
2162type TableSite = number | TableName;

Callers 2

tableNamedFunction · 0.85
exportedTableFunction · 0.85

Calls 6

escapeRegExpFunction · 0.90
visibleFunction · 0.85
returnedTablesFunction · 0.85
heldTableFunction · 0.85
mapMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected