Skip to content

Commit c56f3f2

Browse files
vsavkinkara
authored andcommitted
fix(compiler): do not autoinclude components declared as entry points (angular#10898)
1 parent cc0e3d2 commit c56f3f2

File tree

24 files changed

+42
-45
lines changed

24 files changed

+42
-45
lines changed

modules/@angular/compiler/src/metadata_resolver.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,8 @@ export class CompileMetadataResolver {
388388
});
389389
moduleMeta.entryComponents.forEach((entryComponentType) => {
390390
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
391-
this._addDirectiveToModule(
392-
this.getDirectiveMetadata(entryComponentType.runtime), moduleMeta.type.runtime,
393-
moduleMeta.transitiveModule, moduleMeta.declaredDirectives);
394-
this._console.warn(
395-
`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.`);
391+
throw new BaseException(
392+
`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.`);
396393
}
397394
});
398395
// Collect @Component.directives/pipes/entryComponents into our declared

modules/@angular/core/test/linker/ng_module_integration_spec.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,27 +263,19 @@ function declareTests({useJit}: {useJit: boolean}) {
263263
.toBe(SomeComp);
264264
});
265265

266-
it('should warn and auto declare when using an entryComponent that was neither declared nor imported',
267-
() => {
268-
@Component({template: '', entryComponents: [SomeComp]})
269-
class SomeCompWithEntryComponents {
270-
}
271-
272-
@NgModule({entryComponents: [SomeCompWithEntryComponents]})
273-
class SomeModule {
274-
}
266+
it('should throw when using an entryComponent that was neither declared nor imported', () => {
267+
@Component({template: '', entryComponents: [SomeComp]})
268+
class SomeCompWithEntryComponents {
269+
}
275270

276-
const ngModule = createModule(SomeModule);
277-
expect(ngModule.componentFactoryResolver
278-
.resolveComponentFactory(SomeCompWithEntryComponents)
279-
.componentType)
280-
.toBe(SomeCompWithEntryComponents);
271+
@NgModule({entryComponents: [SomeCompWithEntryComponents]})
272+
class SomeModule {
273+
}
281274

282-
expect(console.warnings).toEqual([
283-
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeCompWithEntryComponents)} via "entryComponents" but it was neither declared nor imported! This warning will become an error after final.`,
284-
`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.`
285-
]);
286-
});
275+
expect(() => createModule(SomeModule))
276+
.toThrowError(
277+
`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.`);
278+
});
287279

288280
it('should create ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
289281
@NgModule({

modules/@angular/platform-server/test/integration_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function writeBody(html: string): any {
2424
class MyServerApp {
2525
}
2626

27-
@NgModule({imports: [ServerModule], bootstrap: [MyServerApp]})
27+
@NgModule({imports: [ServerModule], declarations: [MyServerApp], bootstrap: [MyServerApp]})
2828
class ExampleModule {
2929
}
3030

modules/playground/src/animate/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
1111

1212
import {AnimateApp} from './app/animate-app';
1313

14-
@NgModule({bootstrap: [AnimateApp], imports: [BrowserModule]})
14+
@NgModule({declarations: [AnimateApp], bootstrap: [AnimateApp], imports: [BrowserModule]})
1515
class ExampleModule {
1616
}
1717

modules/playground/src/async/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class AsyncApplication {
9898
};
9999
}
100100

101-
@NgModule({bootstrap: [AsyncApplication], imports: [BrowserModule]})
101+
@NgModule(
102+
{declarations: [AsyncApplication], bootstrap: [AsyncApplication], imports: [BrowserModule]})
102103
class ExampleModule {
103104
}
104105

modules/playground/src/gestures/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GesturesCmp {
2525
onRotate(event: any /** TODO #9100 */): void { this.rotateAngle = event.rotation; }
2626
}
2727

28-
@NgModule({bootstrap: [GesturesCmp], imports: [BrowserModule]})
28+
@NgModule({declarations: [GesturesCmp], bootstrap: [GesturesCmp], imports: [BrowserModule]})
2929
class ExampleModule {
3030
}
3131

modules/playground/src/hello_world/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ export class HelloCmp {
5757
changeGreeting(): void { this.greeting = 'howdy'; }
5858
}
5959

60-
@NgModule({bootstrap: [HelloCmp], declarations: [RedDec], imports: [BrowserModule]})
60+
@NgModule({bootstrap: [HelloCmp], declarations: [HelloCmp, RedDec], imports: [BrowserModule]})
6161
class ExampleModule {
6262
}

modules/playground/src/http/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
1313

1414
import {HttpCmp} from './app/http_comp';
1515

16-
@NgModule({bootstrap: [HttpCmp], imports: [BrowserModule, HttpModule]})
16+
@NgModule({declarations: [HttpCmp], bootstrap: [HttpCmp], imports: [BrowserModule, HttpModule]})
1717
class ExampleModule {
1818
}
1919

modules/playground/src/key_events/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class KeyEventsApp {
4141
resetShiftEnter(): void { this.shiftEnter = false; }
4242
}
4343

44-
@NgModule({bootstrap: [KeyEventsApp], imports: [BrowserModule]})
44+
@NgModule({declarations: [KeyEventsApp], bootstrap: [KeyEventsApp], imports: [BrowserModule]})
4545
class ExampleModule {
4646
}
4747

modules/playground/src/model_driven_forms/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class ReactiveForms {
158158

159159
@NgModule({
160160
bootstrap: [ReactiveForms],
161-
declarations: [ShowError],
161+
declarations: [ReactiveForms, ShowError],
162162
imports: [BrowserModule, ReactiveFormsModule]
163163
})
164164
class ExampleModule {

0 commit comments

Comments
 (0)