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

Function constantPathValue

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

303 * import of its root name, or in the file itself.
304 */
305function constantPathValue(expr: string, fromFile: string, context: ResolutionContext): string | null {
306 const [root, ...keys] = expr.split('.');
307 if (!root || keys.length === 0) return null;
308 let file = fromFile;
309 let name = root;
310 const mapping = context.getImportMappings(fromFile, 'tsx').find((m) => m.localName === root) ??
311 context.getImportMappings(fromFile, 'typescript').find((m) => m.localName === root);
312 if (mapping) {
313 const resolved = resolveImportPath(mapping.source, fromFile, 'typescript', context);
314 if (!resolved) return null;
315 file = resolved;
316 if (mapping.exportedName && mapping.exportedName !== 'default' && mapping.exportedName !== '*') name = mapping.exportedName;
317 }
318 const decl = nodesNamed(context, file, name).find((n) => n.name === name && (n.kind === 'constant' || n.kind === 'variable'));
319 if (!decl) return null;
320 const lines = context.readFile(file)?.split('\n') ?? [];
321 const text = lines.slice(decl.startLine - 1, decl.endLine).join('\n');
322 const open = text.indexOf('{', Math.max(0, text.search(new RegExp(`\\b${escapeRegExp(name)}\\b`))));
323 return open < 0 ? null : readObjectPath(text, open, keys);
324}
325
326/**
327 * 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
nodesNamedFunction · 0.90
escapeRegExpFunction · 0.90
readObjectPathFunction · 0.85
getImportMappingsMethod · 0.80
searchMethod · 0.80
readFileMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected