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

Function angularMounts

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

* Where every routes file is mounted — the `loadChildren` chain from the app * down, settled from the top. Shared by the cross-file pass, which names the * routes, and the route table, which reads the redirects in files that only * mount others (jira-clone's `app.routes.ts` holds nothing but two

(context: ResolutionContext, routes: readonly Node[])

Source from the content-addressed store, hash-verified

624 * `'' → 'project'`).
625 */
626function angularMounts(context: ResolutionContext, routes: readonly Node[]): AngularMounts {
627 const source = context.getNodesByKind('route');
628 const cached = mountMemo.get(context);
629 if (cached && cached.source === source) return cached.mounts;
630 const routeFiles = new Set(routes.map((r) => r.filePath));
631 const mountsByFile = new Map<string, AngularMount[]>();
632 for (const file of context.getAllFiles()) {
633 if (!/\.[cm]?ts$/.test(file) || !(context.fileContains?.(file, 'loadChildren') ?? context.readFile(file)?.includes('loadChildren'))) continue;
634 const content = context.readFile(file);
635 if (!content) continue;
636 const { mounts } = parseAngularRoutes(content);
637 if (mounts.length > 0) mountsByFile.set(file, mounts);
638 }
639 const mountFiles = new Set(mountsByFile.keys());
640 const loadedBy = new Map<string, { parent: string; prefix: string }>();
641 for (const [file, mounts] of mountsByFile) {
642 for (const mount of mounts) {
643 for (const target of routeFilesLoadedBy(mount.spec, file, context, routeFiles, mountFiles)) {
644 // A file mounted from two places keeps its first mount.
645 if (target !== file && !loadedBy.has(target)) loadedBy.set(target, { parent: file, prefix: mount.prefix });
646 }
647 }
648 }
649 const memo = new Map<string, string[]>();
650 const prefixOf = (file: string, seen: Set<string> = new Set()): string[] => {
651 const hit = memo.get(file);
652 if (hit !== undefined) return hit;
653 const mount = loadedBy.get(file);
654 let prefix: string[] = [];
655 if (mount && !seen.has(file)) {
656 seen.add(file);
657 prefix = [...prefixOf(mount.parent, seen), ...resolvedSegments(mount.prefix, mount.parent, context)];
658 }
659 memo.set(file, prefix);
660 return prefix;
661 };
662 const mounts: AngularMounts = { mountFiles, prefixOf: (file) => prefixOf(file) };
663 mountMemo.set(context, { source, mounts });
664 return mounts;
665}
666
667/** Per context, renewed with the route list. */
668const workspaceRoots = new WeakMap<ResolutionContext, { source: readonly Node[]; memo: Map<string, string | null> }>();

Callers 2

angularRouteTableFunction · 0.85
postExtractFunction · 0.85

Calls 11

parseAngularRoutesFunction · 0.85
routeFilesLoadedByFunction · 0.85
prefixOfFunction · 0.85
mapMethod · 0.80
hasMethod · 0.80
getNodesByKindMethod · 0.65
getMethod · 0.65
getAllFilesMethod · 0.65
fileContainsMethod · 0.65
readFileMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected