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

Function routeFilesLoadedBy

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

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

Tested by

no test coverage detected