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)
| 386 | |
| 387 | /** The component class a lazily loaded file provides: the member named, else its default export, else its only component. */ |
| 388 | function 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. */ |
| 407 | function resolvedSegments(pathText: string, file: string, context: ResolutionContext): string[] { |
no test coverage detected