* The component a route's `layout:` reference names, found the way the * route's own component is: through the route file's import of it, else * declared in reach — or a lazily loaded layout module's component, or the * export its loader picks.
(spec: string, ref: UnresolvedRef, context: ResolutionContext)
| 913 | * export its loader picks. |
| 914 | */ |
| 915 | function layoutComponent(spec: string, ref: UnresolvedRef, context: ResolutionContext): string | null { |
| 916 | if (spec.startsWith(LAZY_ROUTE_PREFIX)) return lazyRouteComponent(spec.slice(LAZY_ROUTE_PREFIX.length), ref.filePath, context); |
| 917 | const picked = isReactRouteRef(ref) ? PICKED_EXPORT.exec(spec) : null; |
| 918 | if (picked) return pickedExport(picked[1]!, picked[2]!, ref.filePath, context); |
| 919 | const mapping = context.getImportMappings(ref.filePath, ref.language).find((m) => m.localName === spec); |
| 920 | if (!mapping) { |
| 921 | // A layout the route file declares itself (`const MainLayout = |
| 922 | // Loadable(lazy(…))`): no name match follows a `layout:` reference, so |
| 923 | // the declaration binds here when there is no component to find. |
| 924 | const own = declaredComponent(spec, ref.filePath, context); |
| 925 | if (own) return (own.component ?? own.declaration).id; |
| 926 | return resolveComponent(spec, ref.filePath, context); |
| 927 | } |
| 928 | const viaImport = context.resolveImport?.({ ...ref, referenceName: spec })?.targetNodeId; |
| 929 | if (viaImport) return viaImport; |
| 930 | // `import { default as AppRoot } from './routes/app/root'`: read the module the |
| 931 | // import names — never a same-named component somewhere else. |
| 932 | if (mapping.isDefault || mapping.exportedName === 'default') return lazyRouteComponent(mapping.source, ref.filePath, context); |
| 933 | const file = resolveImportPath(mapping.source, ref.filePath, ref.language, context); |
| 934 | return file ? context.getNodesInFile(file).find((n) => n.name === mapping.exportedName && COMPONENT_KINDS.has(n.kind))?.id ?? null : null; |
| 935 | } |
| 936 | |
| 937 | interface RouteDeclaration { |
| 938 | /** The route's full path as far as the file tells: nesting composed, a constant part shown as `{expr}`. */ |
no test coverage detected