fix(compiler): auto declare entryComponents recursively

Closes #10348
This commit is contained in:
Tobias Bosch
2016-07-28 02:50:50 -07:00
parent fb3608aa5d
commit a32c4ad2f0
3 changed files with 37 additions and 32 deletions

View File

@ -36,7 +36,11 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should warn and auto declare if the component was not declared nor imported by the module',
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
@Component({selector: 'child', template: ''})
@Component({selector: 'nestedchild', template: ''})
class NestedChildComp {
}
@Component({selector: 'child', template: '', entryComponents: [NestedChildComp]})
class ChildComp {
}
@ -50,7 +54,8 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(cf.componentType).toBe(ChildComp);
expect(console.warnings).toEqual([
`Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "entryComponents" but it was neither declared nor imported into the module! This warning will become an error after final.`
`Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "entryComponents" but it was neither declared nor imported into the module! This warning will become an error after final.`,
`Component ${stringify(ChildComp)} in NgModule DynamicTestModule uses ${stringify(NestedChildComp)} via "entryComponents" but it was neither declared nor imported into the module! This warning will become an error after final.`
]);
}));

View File

@ -273,16 +273,23 @@ function declareTests({useJit}: {useJit: boolean}) {
it('should warn and auto declare when using an entryComponent that was neither declared nor imported',
() => {
@NgModule({entryComponents: [SomeComp]})
@Component({template: '', entryComponents: [SomeComp]})
class SomeCompWithEntryComponents {
}
@NgModule({entryComponents: [SomeCompWithEntryComponents]})
class SomeModule {
}
const ngModule = createModule(SomeModule);
expect(ngModule.componentFactoryResolver.resolveComponentFactory(SomeComp).componentType)
.toBe(SomeComp);
expect(ngModule.componentFactoryResolver
.resolveComponentFactory(SomeCompWithEntryComponents)
.componentType)
.toBe(SomeCompWithEntryComponents);
expect(console.warnings).toEqual([
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.`
`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.`
]);
});