diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts index eb9374f364..5714205d6d 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/ng_module.ts @@ -87,6 +87,12 @@ export class NgModuleDecoratorHandler implements DecoratorHandler this._extractModuleFromModuleWithProvidersFn(ref.node)); exports = this.resolveTypeList(expr, exportsMeta, 'exports'); } + let bootstrap: Reference[] = []; + if (ngModule.has('bootstrap')) { + const expr = ngModule.get('bootstrap') !; + const bootstrapMeta = staticallyResolve(expr, this.reflector, this.checker); + bootstrap = this.resolveTypeList(expr, bootstrapMeta, 'bootstrap'); + } // Register this module's information with the SelectorScopeRegistry. This ensures that during // the compile() phase, the module's metadata is available for selector scope computation. @@ -96,7 +102,7 @@ export class NgModuleDecoratorHandler implements DecoratorHandler toR3Reference(bootstrap, context)), declarations: declarations.map(decl => toR3Reference(decl, context)), exports: exports.map(exp => toR3Reference(exp, context)), imports: imports.map(imp => toR3Reference(imp, context)), diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index f130d35472..1d6045500e 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -182,6 +182,7 @@ describe('ngtsc behavioral tests', () => { @NgModule({ declarations: [TestCmp], + bootstrap: [TestCmp], }) export class TestModule {} `); @@ -193,7 +194,7 @@ describe('ngtsc behavioral tests', () => { const jsContents = getContents('test.js'); expect(jsContents) .toContain( - 'i0.ɵdefineNgModule({ type: TestModule, bootstrap: [], ' + + 'i0.ɵdefineNgModule({ type: TestModule, bootstrap: [TestCmp], ' + 'declarations: [TestCmp], imports: [], exports: [] })'); const dtsContents = getContents('test.d.ts'); diff --git a/packages/compiler/src/render3/r3_module_compiler.ts b/packages/compiler/src/render3/r3_module_compiler.ts index f27fbd2b1b..932c5c3910 100644 --- a/packages/compiler/src/render3/r3_module_compiler.ts +++ b/packages/compiler/src/render3/r3_module_compiler.ts @@ -35,7 +35,7 @@ export interface R3NgModuleMetadata { /** * An array of expressions representing the bootstrap components specified by the module. */ - bootstrap: o.Expression[]; + bootstrap: R3Reference[]; /** * An array of expressions representing the directives and pipes declared by the module. @@ -67,7 +67,7 @@ export function compileNgModule(meta: R3NgModuleMetadata): R3NgModuleDef { const {type: moduleType, bootstrap, declarations, imports, exports} = meta; const expression = o.importExpr(R3.defineNgModule).callFn([mapToMapExpression({ type: moduleType, - bootstrap: o.literalArr(bootstrap), + bootstrap: o.literalArr(bootstrap.map(ref => ref.value)), declarations: o.literalArr(declarations.map(ref => ref.value)), imports: o.literalArr(imports.map(ref => ref.value)), exports: o.literalArr(exports.map(ref => ref.value)), diff --git a/packages/core/src/render3/jit/module.ts b/packages/core/src/render3/jit/module.ts index e432d81a7a..7b203b5ad8 100644 --- a/packages/core/src/render3/jit/module.ts +++ b/packages/core/src/render3/jit/module.ts @@ -40,7 +40,7 @@ export function compileNgModuleDefs(moduleType: Type, ngModule: NgModule): if (ngModuleDef === null) { const meta: R3NgModuleMetadata = { type: wrap(moduleType), - bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(wrap), + bootstrap: flatten(ngModule.bootstrap || EMPTY_ARRAY).map(wrapReference), declarations: declarations.map(wrapReference), imports: flatten(ngModule.imports || EMPTY_ARRAY) .map(expandModuleWithProviders)