diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index b10c8b8027..b6f07b4a91 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -69,7 +69,7 @@ const MAX_FILE_COUNT_FOR_SINGLE_FILE_EMIT = 20; /** * Fields to lower within metadata in render2 mode. */ -const LOWER_FIELDS = ['useValue', 'useFactory', 'data', 'id']; +const LOWER_FIELDS = ['useValue', 'useFactory', 'data', 'id', 'loadChildren']; /** * Fields to lower within metadata in render3 mode. diff --git a/packages/compiler-cli/test/BUILD.bazel b/packages/compiler-cli/test/BUILD.bazel index a6c0b2d355..e6cb2ebf07 100644 --- a/packages/compiler-cli/test/BUILD.bazel +++ b/packages/compiler-cli/test/BUILD.bazel @@ -69,6 +69,7 @@ jasmine_node_test( "//packages/common:npm_package", "//packages/core:npm_package", "//packages/platform-browser:npm_package", + "//packages/router:npm_package", ], deps = [ ":ngc_lib", diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 779ca766c7..259ea65783 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -869,6 +869,40 @@ describe('ngc transformer command-line', () => { expect(mymoduleSource).toMatch(/ɵ0 = .*'test'/); }); + it('should lower loadChildren', () => { + write('mymodule.ts', ` + import {Component, NgModule} from '@angular/core'; + import {RouterModule} from '@angular/router'; + + export function foo(): string { + console.log('side-effect'); + return 'test'; + } + + @Component({ + selector: 'route', + template: 'route', + }) + export class Route {} + + @NgModule({ + declarations: [Route], + imports: [ + RouterModule.forRoot([ + {path: '', pathMatch: 'full', component: Route, loadChildren: foo()} + ]), + ] + }) + export class MyModule {} + `); + expect(compile()).toEqual(0); + + const mymodulejs = path.resolve(outDir, 'mymodule.js'); + const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8'); + expect(mymoduleSource).toContain('loadChildren: ɵ0'); + expect(mymoduleSource).toMatch(/ɵ0 = .*foo\(\)/); + }); + it('should be able to lower supported expressions', () => { writeConfig(`{ "extends": "./tsconfig-base.json", diff --git a/packages/compiler/src/aot/static_reflector.ts b/packages/compiler/src/aot/static_reflector.ts index 812e54ac83..d8dd289192 100644 --- a/packages/compiler/src/aot/static_reflector.ts +++ b/packages/compiler/src/aot/static_reflector.ts @@ -28,7 +28,7 @@ const IGNORE = { const USE_VALUE = 'useValue'; const PROVIDE = 'provide'; -const REFERENCE_SET = new Set([USE_VALUE, 'useFactory', 'data', 'id']); +const REFERENCE_SET = new Set([USE_VALUE, 'useFactory', 'data', 'id', 'loadChildren']); const TYPEGUARD_POSTFIX = 'TypeGuard'; const USE_IF = 'UseIf';