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

Function localAlias

src/resolution/frameworks/angular-router.ts:568–583  ·  view source on GitHub ↗

`create.path` as the chain its root was destructured from in `fromFile`, or null when the root is no local alias.

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

Source from the content-addressed store, hash-verified

566
567/** `create.path` as the chain its root was destructured from in `fromFile`, or null when the root is no local alias. */
568function localAlias(expr: string, fromFile: string, context: ResolutionContext): string | null {
569 const content = context.readFile(fromFile);
570 if (!content) return null;
571 const [root, ...rest] = expr.split('.');
572 if (!root) return null;
573 const destructure = /\b(?:const|let)\s*\{([^}]*)\}\s*=\s*([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*)\s*;?/g;
574 let m: RegExpExecArray | null;
575 while ((m = destructure.exec(content)) !== null) {
576 for (const binding of m[1]!.split(',')) {
577 const [prop, local] = binding.split(':').map((part) => part.trim());
578 if ((local ?? prop) === root && prop) return [`${m[2]!.replace(/\s+/g, '')}.${prop}`, ...rest].join('.');
579 }
580 }
581 const simple = new RegExp(String.raw`\b(?:const|let)\s+${escapeRegExp(root)}\s*=\s*([A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)+)\s*;`).exec(content);
582 return simple ? [simple[1]!.replace(/\s+/g, ''), ...rest].join('.') : null;
583}
584
585/** A constant path's value: `internalRoutes.account.path` → `account`. */
586function constantValue(expr: string, fromFile: string, context: ResolutionContext): string | null {

Callers 1

constantTextFunction · 0.85

Calls 5

escapeRegExpFunction · 0.90
mapMethod · 0.80
readFileMethod · 0.65
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected