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