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

Function lazyComponent

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

The component class a lazily loaded file provides: the member named, else its default export, else its only component.

(spec: string, member: string | null, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

386
387/** The component class a lazily loaded file provides: the member named, else its default export, else its only component. */
388function lazyComponent(spec: string, member: string | null, fromFile: string, context: ResolutionContext): Node | null {
389 const file = resolveImportPath(spec, fromFile, 'typescript', context);
390 if (!file) return null;
391 let name = member;
392 if (!name) {
393 const content = context.readFile(file);
394 if (!content) return null;
395 const classes = componentClassesIn(content);
396 name = (classes.find((c) => c.isDefault) ?? (classes.length === 1 ? classes[0] : undefined))?.name ?? null;
397 if (!name) {
398 const plain = /\bexport\s+default\s+class\s+([A-Za-z_$][\w$]*)/.exec(content);
399 name = plain ? plain[1]! : null;
400 }
401 }
402 if (!name) return null;
403 return context.getNodesInFile(file).find((n) => n.kind === 'class' && n.name === name) ?? null;
404}
405
406/** A path's segments with each `{expr}` read from the constant it names, as seen from `file` — where the route (or the mount) is written. */
407function resolvedSegments(pathText: string, file: string, context: ResolutionContext): string[] {

Callers 2

routeComponentFunction · 0.85
resolveFunction · 0.85

Calls 5

resolveImportPathFunction · 0.90
componentClassesInFunction · 0.85
readFileMethod · 0.65
execMethod · 0.65
getNodesInFileMethod · 0.65

Tested by

no test coverage detected