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

Function routeFilesLoadedBy

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

* The file a routes import names, and — for an NgModule — the routing modules * it imports. A barrel is looked through first: an Nx library is imported by * its alias (`@angular-spotify/web/home/feature`), which names the library's * `src/index.ts`, whose `export * from './lib/home.module'` names

(spec: string, fromFile: string, context: ResolutionContext, routeFiles: ReadonlySet<string>, mountFiles: ReadonlySet<string>)

Source from the content-addressed store, hash-verified

437 * `src/index.ts`, whose `export * from './lib/home.module'` names the module.
438 */
439function routeFilesLoadedBy(spec: string, fromFile: string, context: ResolutionContext, routeFiles: ReadonlySet<string>, mountFiles: ReadonlySet<string>): string[] {
440 const target = resolveImportPath(spec, fromFile, 'typescript', context);
441 const seen = new Set<string>();
442 const out: string[] = [];
443 // A barrel can re-export another barrel; a few hops settle it.
444 let barrels = target ? [target] : [];
445 for (let hop = 0; hop < 4 && barrels.length > 0; hop++) {
446 const next: string[] = [];
447 for (const file of barrels) {
448 if (seen.has(file)) continue;
449 seen.add(file);
450 if (routeFiles.has(file) || mountFiles.has(file)) {
451 out.push(file);
452 continue;
453 }
454 const content = context.readFile(file);
455 if (!content) continue;
456 // `loadChildren: () => import('./layout/layout.module').then(m => m.LayoutModule)`:
457 // the module holds no routes; the routing module it imports does.
458 if (/@NgModule\s*\(/.test(content)) {
459 const imports = /\bimport\s+[^'"]*?from\s+(['"])([^'"]+)\1/g;
460 let m: RegExpExecArray | null;
461 while ((m = imports.exec(content)) !== null) {
462 const imported = resolveImportPath(m[2]!, file, 'typescript', context);
463 if (imported && (routeFiles.has(imported) || mountFiles.has(imported)) && !out.includes(imported)) out.push(imported);
464 }
465 continue;
466 }
467 const reexports = /\bexport\s+(?:\*|\{[^}]*\})\s*(?:as\s+[\w$]+\s*)?from\s+(['"])([^'"]+)\1/g;
468 let m: RegExpExecArray | null;
469 while ((m = reexports.exec(content)) !== null) {
470 const reexported = resolveImportPath(m[2]!, file, 'typescript', context);
471 if (reexported && !seen.has(reexported)) next.push(reexported);
472 }
473 }
474 barrels = next;
475 }
476 return out;
477}
478
479/** Per context, renewed with the route list (whose identity changes when the resolver's caches do). */
480const constantTexts = new WeakMap<ResolutionContext, { source: readonly Node[]; memo: Map<string, string | null> }>();

Callers 1

angularMountsFunction · 0.85

Calls 6

resolveImportPathFunction · 0.90
hasMethod · 0.80
pushMethod · 0.80
readFileMethod · 0.80
execMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected