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

Function constantPathValue

src/resolution/frameworks/react.ts:304–323  ·  view source on GitHub ↗

* The string a member expression like `paths.app.root.path` reads from a * constant object literal — the constant found through the route file's * import of its root name, or in the file itself.

(expr: string, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

302 * import of its root name, or in the file itself.
303 */
304function constantPathValue(expr: string, fromFile: string, context: ResolutionContext): string | null {
305 const [root, ...keys] = expr.split('.');
306 if (!root || keys.length === 0) return null;
307 let file = fromFile;
308 let name = root;
309 const mapping = context.getImportMappings(fromFile, 'tsx').find((m) => m.localName === root) ??
310 context.getImportMappings(fromFile, 'typescript').find((m) => m.localName === root);
311 if (mapping) {
312 const resolved = resolveImportPath(mapping.source, fromFile, 'typescript', context);
313 if (!resolved) return null;
314 file = resolved;
315 if (mapping.exportedName && mapping.exportedName !== 'default' && mapping.exportedName !== '*') name = mapping.exportedName;
316 }
317 const decl = context.getNodesInFile(file).find((n) => n.name === name && (n.kind === 'constant' || n.kind === 'variable'));
318 if (!decl) return null;
319 const lines = context.readFile(file)?.split('\n') ?? [];
320 const text = lines.slice(decl.startLine - 1, decl.endLine).join('\n');
321 const open = text.indexOf('{', Math.max(0, text.search(new RegExp(`\\b${escapeRegExp(name)}\\b`))));
322 return open < 0 ? null : readObjectPath(text, open, keys);
323}
324
325/**
326 * The href a route-config object names — `paths.app.discussion.getHref(id)`

Callers 3

postExtractFunction · 0.85
tableRoutesFunction · 0.85
pathValuesFunction · 0.85

Calls 8

resolveImportPathFunction · 0.90
escapeRegExpFunction · 0.90
readObjectPathFunction · 0.85
getImportMappingsMethod · 0.80
searchMethod · 0.80
getNodesInFileMethod · 0.65
readFileMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected