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) => {
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
this._addDirectiveToModule(
this.getDirectiveMetadata(entryComponentType.runtime), moduleMeta.type.runtime,
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.`);
throw new BaseException(
`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.`);
}
});
// Collect @Component.directives/pipes/entryComponents into our declared

View File

@ -263,27 +263,19 @@ function declareTests({useJit}: {useJit: boolean}) {
.toBe(SomeComp);
});
it('should warn and auto declare when using an entryComponent that was neither declared nor imported',
() => {
@Component({template: '', entryComponents: [SomeComp]})
class SomeCompWithEntryComponents {
}
it('should throw when using an entryComponent that was neither declared nor imported', () => {
@Component({template: '', entryComponents: [SomeComp]})
class SomeCompWithEntryComponents {
}
@NgModule({entryComponents: [SomeCompWithEntryComponents]})
class SomeModule {
}
@NgModule({entryComponents: [SomeCompWithEntryComponents]})
class SomeModule {
}
const ngModule = createModule(SomeModule);
expect(ngModule.componentFactoryResolver
.resolveComponentFactory(SomeCompWithEntryComponents)
.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.`
]);
});
expect(() => createModule(SomeModule))
.toThrowError(
`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.`);
});
it('should create ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
@NgModule({

View File

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