fix(compiler): do not autoinclude components declared as entry points (#10898)

This commit is contained in:
Victor Savkin 2016-08-19 15:59:50 -07:00 committed by Kara
parent cc0e3d2296
commit c56f3f2246
24 changed files with 42 additions and 45 deletions

View File

@ -388,11 +388,8 @@ export class CompileMetadataResolver {
}); });
moduleMeta.entryComponents.forEach((entryComponentType) => { moduleMeta.entryComponents.forEach((entryComponentType) => {
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) { if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
this._addDirectiveToModule( throw new BaseException(
this.getDirectiveMetadata(entryComponentType.runtime), moduleMeta.type.runtime, `NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponentType.runtime)} via "entryComponents" but it was neither declared nor imported! If ${stringify(entryComponentType.runtime)} is declared in an imported module, make sure it is exported.`);
moduleMeta.transitiveModule, moduleMeta.declaredDirectives);
this._console.warn(
`NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponentType.runtime)} via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.`);
} }
}); });
// Collect @Component.directives/pipes/entryComponents into our declared // Collect @Component.directives/pipes/entryComponents into our declared

View File

@ -263,27 +263,19 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp); .toBe(SomeComp);
}); });
it('should warn and auto declare when using an entryComponent that was neither declared nor imported', it('should throw when using an entryComponent that was neither declared nor imported', () => {
() => { @Component({template: '', entryComponents: [SomeComp]})
@Component({template: '', entryComponents: [SomeComp]}) class SomeCompWithEntryComponents {
class SomeCompWithEntryComponents { }
}
@NgModule({entryComponents: [SomeCompWithEntryComponents]}) @NgModule({entryComponents: [SomeCompWithEntryComponents]})
class SomeModule { class SomeModule {
} }
const ngModule = createModule(SomeModule); expect(() => createModule(SomeModule))
expect(ngModule.componentFactoryResolver .toThrowError(
.resolveComponentFactory(SomeCompWithEntryComponents) `NgModule ${stringify(SomeModule)} uses ${stringify(SomeCompWithEntryComponents)} via "entryComponents" but it was neither declared nor imported! If ${stringify(SomeCompWithEntryComponents)} is declared in an imported module, make sure it is exported.`);
.componentType) });
.toBe(SomeCompWithEntryComponents);
expect(console.warnings).toEqual([
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeCompWithEntryComponents)} via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.`,
`Component ${stringify(SomeCompWithEntryComponents)} in NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "entryComponents" but it was neither declared nor imported into the module! This warning will become an error after final.`
]);
});
it('should create ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => { it('should create ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
@NgModule({ @NgModule({

View File

@ -24,7 +24,7 @@ function writeBody(html: string): any {
class MyServerApp { class MyServerApp {
} }
@NgModule({imports: [ServerModule], bootstrap: [MyServerApp]}) @NgModule({imports: [ServerModule], declarations: [MyServerApp], bootstrap: [MyServerApp]})
class ExampleModule { class ExampleModule {
} }

View File

@ -11,7 +11,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AnimateApp} from './app/animate-app'; import {AnimateApp} from './app/animate-app';
@NgModule({bootstrap: [AnimateApp], imports: [BrowserModule]}) @NgModule({declarations: [AnimateApp], bootstrap: [AnimateApp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -98,7 +98,8 @@ class AsyncApplication {
}; };
} }
@NgModule({bootstrap: [AsyncApplication], imports: [BrowserModule]}) @NgModule(
{declarations: [AsyncApplication], bootstrap: [AsyncApplication], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -25,7 +25,7 @@ class GesturesCmp {
onRotate(event: any /** TODO #9100 */): void { this.rotateAngle = event.rotation; } onRotate(event: any /** TODO #9100 */): void { this.rotateAngle = event.rotation; }
} }
@NgModule({bootstrap: [GesturesCmp], imports: [BrowserModule]}) @NgModule({declarations: [GesturesCmp], bootstrap: [GesturesCmp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -57,6 +57,6 @@ export class HelloCmp {
changeGreeting(): void { this.greeting = 'howdy'; } changeGreeting(): void { this.greeting = 'howdy'; }
} }
@NgModule({bootstrap: [HelloCmp], declarations: [RedDec], imports: [BrowserModule]}) @NgModule({bootstrap: [HelloCmp], declarations: [HelloCmp, RedDec], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -13,7 +13,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {HttpCmp} from './app/http_comp'; import {HttpCmp} from './app/http_comp';
@NgModule({bootstrap: [HttpCmp], imports: [BrowserModule, HttpModule]}) @NgModule({declarations: [HttpCmp], bootstrap: [HttpCmp], imports: [BrowserModule, HttpModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -41,7 +41,7 @@ class KeyEventsApp {
resetShiftEnter(): void { this.shiftEnter = false; } resetShiftEnter(): void { this.shiftEnter = false; }
} }
@NgModule({bootstrap: [KeyEventsApp], imports: [BrowserModule]}) @NgModule({declarations: [KeyEventsApp], bootstrap: [KeyEventsApp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -158,7 +158,7 @@ class ReactiveForms {
@NgModule({ @NgModule({
bootstrap: [ReactiveForms], bootstrap: [ReactiveForms],
declarations: [ShowError], declarations: [ReactiveForms, ShowError],
imports: [BrowserModule, ReactiveFormsModule] imports: [BrowserModule, ReactiveFormsModule]
}) })
class ExampleModule { class ExampleModule {

View File

@ -197,7 +197,8 @@ class OrderManagementApplication {
@NgModule({ @NgModule({
bootstrap: [OrderManagementApplication], bootstrap: [OrderManagementApplication],
declarations: [OrderListComponent, OrderDetailsComponent, OrderItemComponent], declarations:
[OrderManagementApplication, OrderListComponent, OrderDetailsComponent, OrderItemComponent],
imports: [BrowserModule, FormsModule] imports: [BrowserModule, FormsModule]
}) })
class ExampleModule { class ExampleModule {

View File

@ -198,7 +198,8 @@ class PersonManagementApplication {
@NgModule({ @NgModule({
bootstrap: [PersonManagementApplication], bootstrap: [PersonManagementApplication],
declarations: [FullNameComponent, PersonsComponent, PersonsDetailComponent], declarations:
[PersonManagementApplication, FullNameComponent, PersonsComponent, PersonsDetailComponent],
imports: [BrowserModule, FormsModule] imports: [BrowserModule, FormsModule]
}) })
class ExampleModule { class ExampleModule {

View File

@ -24,6 +24,6 @@ export function main() {
export class RelativeApp { export class RelativeApp {
} }
@NgModule({bootstrap: [RelativeApp], imports: [BrowserModule]}) @NgModule({declarations: [RelativeApp], bootstrap: [RelativeApp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -20,7 +20,7 @@ export class ErrorComponent {
createError(): void { throw new BaseException('Sourcemap test'); } createError(): void { throw new BaseException('Sourcemap test'); }
} }
@NgModule({bootstrap: [ErrorComponent], imports: [BrowserModule]}) @NgModule({declarations: [ErrorComponent], bootstrap: [ErrorComponent], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -23,7 +23,7 @@ class SvgGroup {
class SvgApp { class SvgApp {
} }
@NgModule({bootstrap: [SvgApp], declarations: [SvgGroup], imports: [BrowserModule]}) @NgModule({bootstrap: [SvgApp], declarations: [SvgApp, SvgGroup], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -169,7 +169,11 @@ class TemplateDrivenForms {
print(this.model); print(this.model);
} }
} }
@NgModule({bootstrap: [TemplateDrivenForms], imports: [BrowserModule]}) @NgModule({
declarations: [TemplateDrivenForms],
bootstrap: [TemplateDrivenForms],
imports: [BrowserModule]
})
class ExampleModule { class ExampleModule {
} }

View File

@ -51,7 +51,7 @@ class TodoApp {
clearCompleted(): void { this.todoStore.removeBy((todo: Todo) => todo.completed); } clearCompleted(): void { this.todoStore.removeBy((todo: Todo) => todo.completed); }
} }
@NgModule({bootstrap: [TodoApp], imports: [BrowserModule]}) @NgModule({declarations: [TodoApp], bootstrap: [TodoApp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -12,7 +12,7 @@ import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {ImageDemo} from './index_common'; import {ImageDemo} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [ImageDemo]}) @NgModule({imports: [WorkerAppModule], bootstrap: [ImageDemo], declarations: [ImageDemo]})
class ExampleModule { class ExampleModule {
} }

View File

@ -12,7 +12,7 @@ import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {InputCmp} from './index_common'; import {InputCmp} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [InputCmp]}) @NgModule({imports: [WorkerAppModule], bootstrap: [InputCmp], declarations: [InputCmp]})
class ExampleModule { class ExampleModule {
} }

View File

@ -12,7 +12,7 @@ import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {HelloCmp} from './index_common'; import {HelloCmp} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [HelloCmp]}) @NgModule({imports: [WorkerAppModule], bootstrap: [HelloCmp], declarations: [HelloCmp]})
class ExampleModule { class ExampleModule {
} }

View File

@ -12,7 +12,7 @@ import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {App} from './index_common'; import {App} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [App]}) @NgModule({imports: [WorkerAppModule], bootstrap: [App], declarations: [App]})
class ExampleModule { class ExampleModule {
} }

View File

@ -12,7 +12,7 @@ import {platformWorkerAppDynamic} from '@angular/platform-browser-dynamic';
import {TodoApp} from './index_common'; import {TodoApp} from './index_common';
@NgModule({imports: [WorkerAppModule], bootstrap: [TodoApp]}) @NgModule({imports: [WorkerAppModule], bootstrap: [TodoApp], declarations: [TodoApp]})
class ExampleModule { class ExampleModule {
} }

View File

@ -30,7 +30,7 @@ class ZippyApp {
pushLog(log: string) { this.logs.push(log); } pushLog(log: string) { this.logs.push(log); }
} }
@NgModule({bootstrap: [ZippyApp], imports: [BrowserModule]}) @NgModule({declarations: [ZippyApp], bootstrap: [ZippyApp], imports: [BrowserModule]})
class ExampleModule { class ExampleModule {
} }

View File

@ -15,6 +15,7 @@ class HelloWorldComponent {
} }
@NgModule({ @NgModule({
declarations: [HelloWorldComponent],
bootstrap: [HelloWorldComponent], bootstrap: [HelloWorldComponent],
imports: [BrowserModule] imports: [BrowserModule]
}) })