From 00d3666d95c340d17f147f3774bc4ed763509512 Mon Sep 17 00:00:00 2001 From: Matt Keller Date: Fri, 27 Jul 2018 15:47:12 +0100 Subject: [PATCH] fix(compiler): Fix look up of entryComponents in AOT Summaries (#24892) Previously, when you attempted to bootstrap a component that had a router-outlet using ngsummaries, it would complain that the component was not provided by any module even if it was. This commit fixes a mistake (AFAICT) which caused the lookup of the component in the AOT summaries to fail. I believe this change is safe. I've run the affected tests within Google and there were no breakages caused by this change. PR Close #24892 --- packages/compiler/src/jit/compiler.ts | 2 +- .../test/aot_ngsummary_test/BUILD.bazel | 35 +++++++++++++++ .../aot_router_bootstrap.spec.ts | 28 ++++++++++++ .../aot_ngsummary_test/aot_router_module.ts | 44 +++++++++++++++++++ packages/tsconfig-metadata.json | 3 +- packages/tsconfig.json | 4 +- 6 files changed, 112 insertions(+), 4 deletions(-) create mode 100644 packages/router/test/aot_ngsummary_test/BUILD.bazel create mode 100644 packages/router/test/aot_ngsummary_test/aot_router_bootstrap.spec.ts create mode 100644 packages/router/test/aot_ngsummary_test/aot_router_module.ts diff --git a/packages/compiler/src/jit/compiler.ts b/packages/compiler/src/jit/compiler.ts index 814d5b557c..dd245fb2d1 100644 --- a/packages/compiler/src/jit/compiler.ts +++ b/packages/compiler/src/jit/compiler.ts @@ -196,7 +196,7 @@ export class JitCompiler { } }); localModuleMeta.entryComponents.forEach((entryComponentType) => { - if (!this.hasAotSummary(entryComponentType.componentType.reference)) { + if (!this.hasAotSummary(entryComponentType.componentType)) { const moduleMeta = moduleByJitDirective.get(entryComponentType.componentType) !; templates.add( this._createCompiledHostTemplate(entryComponentType.componentType, moduleMeta)); diff --git a/packages/router/test/aot_ngsummary_test/BUILD.bazel b/packages/router/test/aot_ngsummary_test/BUILD.bazel new file mode 100644 index 0000000000..8b4ab74cdc --- /dev/null +++ b/packages/router/test/aot_ngsummary_test/BUILD.bazel @@ -0,0 +1,35 @@ +load("//tools:defaults.bzl", "ts_library", "ts_web_test_suite") +load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") +load("//tools:defaults.bzl", "ng_module") + +ng_module( + name = "aot_routing_module", + srcs = ["aot_router_module.ts"], + deps = [ + "//packages/core", + "//packages/router", + "@rxjs", + ], +) + +ts_library( + name = "aot_test_lib", + testonly = 1, + srcs = ["aot_router_bootstrap.spec.ts"], + deps = [ + ":aot_routing_module", + "//packages/core", + "//packages/core/testing", + "//packages/router", + "//packages/router/testing", + ], +) + +jasmine_node_test( + name = "test", + bootstrap = ["angular/tools/testing/init_node_spec.js"], + deps = [ + ":aot_test_lib", + "//tools/testing:node", + ], +) diff --git a/packages/router/test/aot_ngsummary_test/aot_router_bootstrap.spec.ts b/packages/router/test/aot_ngsummary_test/aot_router_bootstrap.spec.ts new file mode 100644 index 0000000000..8286936cec --- /dev/null +++ b/packages/router/test/aot_ngsummary_test/aot_router_bootstrap.spec.ts @@ -0,0 +1,28 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {TestBed} from '@angular/core/testing'; + +import {RouterTestingModule} from '../../testing'; + +import {AotRouterModule, ROUTES} from './aot_router_module'; +import {AotRouterModuleNgSummary} from './aot_router_module.ngsummary'; + +describe('The Aot Routing Component', () => { + it('should be able to compile the components while using aotSummaries', () => { + TestBed + .configureTestingModule({ + imports: [ + AotRouterModule, + RouterTestingModule.withRoutes(ROUTES), + ], + aotSummaries: () => [AotRouterModuleNgSummary], + }) + .compileComponents(); + }); +}); diff --git a/packages/router/test/aot_ngsummary_test/aot_router_module.ts b/packages/router/test/aot_ngsummary_test/aot_router_module.ts new file mode 100644 index 0000000000..ad52784a72 --- /dev/null +++ b/packages/router/test/aot_ngsummary_test/aot_router_module.ts @@ -0,0 +1,44 @@ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {Component, NgModule} from '@angular/core'; +import {RouterModule, Routes} from '../../'; + +@Component({ + selector: 'aot-router', + template: '', +}) +export class AotRouterCmp { +} + +@Component({ + selector: 'aot-router-child', + template: 'arc', +}) +export class AotRouterChildCmp { +} + +export const ROUTES: Routes = [ + {path: '', component: AotRouterChildCmp}, +]; + +@NgModule({ + declarations: [ + AotRouterCmp, + AotRouterChildCmp, + ], + exports: [ + AotRouterCmp, + AotRouterChildCmp, + ], + imports: [ + RouterModule.forRoot(ROUTES), + ], +}) +export class AotRouterModule { +} diff --git a/packages/tsconfig-metadata.json b/packages/tsconfig-metadata.json index 0fc31d7497..0aeb1e3545 100644 --- a/packages/tsconfig-metadata.json +++ b/packages/tsconfig-metadata.json @@ -12,6 +12,7 @@ "compiler/test", "compiler-cli/integrationtest", "platform-server/integrationtest", + "router/test/aot_ngsummary_test", "common/locales", "examples", "**/*_spec.ts", @@ -23,4 +24,4 @@ "annotateForClosureCompiler": false, "annotationsAs": "decorators" } -} \ No newline at end of file +} diff --git a/packages/tsconfig.json b/packages/tsconfig.json index 99c52620a9..9b8d04667c 100644 --- a/packages/tsconfig.json +++ b/packages/tsconfig.json @@ -34,7 +34,7 @@ "compiler-cli/integrationtest", "elements/schematics", "examples/**/e2e_test/*", - "platform-server/integrationtest" + "platform-server/integrationtest", + "router/test/aot_ngsummary_test", ] - }