fix(compiler-cli): find lazy routes in nested module import arrays
Fixes: #17531
This commit is contained in:
parent
00874c27f4
commit
8c89cc4fc5
|
@ -14,11 +14,11 @@ export class LazyComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [RouterModule.forChild([
|
imports: [[RouterModule.forChild([
|
||||||
{path: '', component: LazyComponent, pathMatch: 'full'},
|
{path: '', component: LazyComponent, pathMatch: 'full'},
|
||||||
{path: 'feature', loadChildren: './feature/feature.module#FeatureModule'},
|
{path: 'feature', loadChildren: './feature/feature.module#FeatureModule'},
|
||||||
{path: 'lazy-feature', loadChildren: './feature/lazy-feature.module#LazyFeatureModule'}
|
{path: 'lazy-feature', loadChildren: './feature/lazy-feature.module#LazyFeatureModule'}
|
||||||
])],
|
])]],
|
||||||
declarations: [LazyComponent]
|
declarations: [LazyComponent]
|
||||||
})
|
})
|
||||||
export class LazyModule {
|
export class LazyModule {
|
||||||
|
|
|
@ -124,6 +124,12 @@ function _assertRoute(map: LazyRouteMap, route: LazyRoute) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function flatten<T>(list: Array<T|T[]>): T[] {
|
||||||
|
return list.reduce((flat: any[], item: T | T[]): T[] => {
|
||||||
|
const flatItem = Array.isArray(item) ? flatten(item) : item;
|
||||||
|
return (<T[]>flat).concat(flatItem);
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract all the LazyRoutes from a module. This extracts all `loadChildren` keys from this
|
* Extract all the LazyRoutes from a module. This extracts all `loadChildren` keys from this
|
||||||
|
@ -134,12 +140,10 @@ function _extractLazyRoutesFromStaticModule(
|
||||||
staticSymbol: StaticSymbol, reflector: StaticReflector, host: AotCompilerHost,
|
staticSymbol: StaticSymbol, reflector: StaticReflector, host: AotCompilerHost,
|
||||||
ROUTES: StaticSymbol): LazyRoute[] {
|
ROUTES: StaticSymbol): LazyRoute[] {
|
||||||
const moduleMetadata = _getNgModuleMetadata(staticSymbol, reflector);
|
const moduleMetadata = _getNgModuleMetadata(staticSymbol, reflector);
|
||||||
const allRoutes: any =
|
const imports = flatten(moduleMetadata.imports || []);
|
||||||
(moduleMetadata.imports || [])
|
const allRoutes: any = imports.filter(i => 'providers' in i).reduce((mem: Route[], m: any) => {
|
||||||
.filter(i => 'providers' in i)
|
return mem.concat(_collectRoutes(m.providers || [], reflector, ROUTES));
|
||||||
.reduce((mem: Route[], m: any) => {
|
}, _collectRoutes(moduleMetadata.providers || [], reflector, ROUTES));
|
||||||
return mem.concat(_collectRoutes(m.providers || [], reflector, ROUTES));
|
|
||||||
}, _collectRoutes(moduleMetadata.providers || [], reflector, ROUTES));
|
|
||||||
|
|
||||||
const lazyRoutes: LazyRoute[] =
|
const lazyRoutes: LazyRoute[] =
|
||||||
_collectLoadChildren(allRoutes).reduce((acc: LazyRoute[], route: string) => {
|
_collectLoadChildren(allRoutes).reduce((acc: LazyRoute[], route: string) => {
|
||||||
|
@ -150,7 +154,7 @@ function _extractLazyRoutesFromStaticModule(
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const importedSymbols =
|
const importedSymbols =
|
||||||
((moduleMetadata.imports || []) as any[])
|
(imports as any[])
|
||||||
.filter(i => i instanceof StaticSymbol || i.ngModule instanceof StaticSymbol)
|
.filter(i => i instanceof StaticSymbol || i.ngModule instanceof StaticSymbol)
|
||||||
.map(i => {
|
.map(i => {
|
||||||
if (i instanceof StaticSymbol) return i;
|
if (i instanceof StaticSymbol) return i;
|
||||||
|
|
Loading…
Reference in New Issue