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

Function declarationSource

src/resolution/frameworks/angular-router.ts:553–567  ·  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

551 * barrel (an Nx library's `src/index.ts`) — the module it re-exports it from.
552 */
553function declarationSource(root: string, file: string, context: ResolutionContext, hops: number): string | null {
554 const content = context.readFile(file);
555 if (!content) return null;
556 if (new RegExp(String.raw`\b(?:const|let|class|enum)\s+${escapeRegExp(root)}\b`).test(content)) return content;
557 if (hops >= 3) return null;
558 const reexports = /\bexport\s+(\*|\{[^}]*\})\s*from\s+(['"])([^'"]+)\2/g;
559 let m: RegExpExecArray | null;
560 while ((m = reexports.exec(content)) !== null) {
561 if (m[1] !== '*' && !new RegExp(String.raw`\b${escapeRegExp(root)}\b`).test(m[1]!)) continue;
562 const target = resolveImportPath(m[3]!, file, 'typescript', context);
563 const found = target ? declarationSource(root, target, context, hops + 1) : null;
564 if (found) return found;
565 }
566 return null;
567}
568
569/** `create.path` as the chain its root was destructured from in `fromFile`, or null when the root is no local alias. */
570function localAlias(expr: string, fromFile: string, context: ResolutionContext): string | null {

Callers 1

constantTextFunction · 0.85

Calls 4

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

Tested by

no test coverage detected