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

Function declaredTable

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

2162 * declarations of the name, the one `visible` picks.
2163 */
2164function declaredTable(
2165 safe: string,
2166 name: string,
2167 call: boolean,
2168 visible: (keywords: number[]) => number | undefined
2169): TableSite[] {
2170 const id = escapeRegExp(name);
2171 const decls = [...safe.matchAll(new RegExp(`(?:^|[^\\w$.])((?:const|let|var)\\s+${id}\\s*(?::[^=;]*)?=\\s*)`, 'g'))];
2172 const chosen = decls.length > 0 ? visible(decls.map((d) => d.index + d[0].length - d[1]!.length)) : undefined;
2173 const decl = chosen === undefined ? undefined : decls[chosen];
2174 if (decl) {
2175 const after = decl.index + decl[0].length;
2176 return call ? returnedTables(safe, after) : heldTable(safe, after);
2177 }
2178 if (!call) return [];
2179 const fn = new RegExp(`(?:^|[^\\w$.])function\\s+${id}\\s*\\(`).exec(safe);
2180 return fn ? returnedTables(safe, fn.index + fn[0].indexOf('function')) : [];
2181}
2182
2183/** A table to read: where its literal opens in the file at hand, or a function whose returned tables to read. */
2184type 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