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

Function declarationSource

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

* The source that declares `root`: `file` itself, or — when `file` is a * barrel (an Nx library's `src/index.ts`) — the module it re-exports it from.

(root: string, file: string, context: ResolutionContext, hops: number)

Source from the content-addressed store, hash-verified

549 * barrel (an Nx library's `src/index.ts`) — the module it re-exports it from.
550 */
551function declarationSource(root: string, file: string, context: ResolutionContext, hops: number): string | null {
552 const content = context.readFile(file);
553 if (!content) return null;
554 if (new RegExp(String.raw`\b(?:const|let|class|enum)\s+${escapeRegExp(root)}\b`).test(content)) return content;
555 if (hops >= 3) return null;
556 const reexports = /\bexport\s+(\*|\{[^}]*\})\s*from\s+(['"])([^'"]+)\2/g;
557 let m: RegExpExecArray | null;
558 while ((m = reexports.exec(content)) !== null) {
559 if (m[1] !== '*' && !new RegExp(String.raw`\b${escapeRegExp(root)}\b`).test(m[1]!)) continue;
560 const target = resolveImportPath(m[3]!, file, 'typescript', context);
561 const found = target ? declarationSource(root, target, context, hops + 1) : null;
562 if (found) return found;
563 }
564 return null;
565}
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 {

Callers 1

constantTextFunction · 0.85

Calls 4

escapeRegExpFunction · 0.90
resolveImportPathFunction · 0.90
readFileMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected