Skip to content

Commit 6f4e49e

Browse files
committed
refactor(core): rename precompile into entryComponents.
Part of #10043 BREAKING CHANGE: - `@Component.precompile` was renamed to `@Component.entryComponents` (old property still works but is deprecated) - `ANALYZE_FOR_PRECOMPILE` was renamed to `ANALYZE_FOR_ENTRY_COMPONENTS` (no deprecations)
1 parent 46b2127 commit 6f4e49e

37 files changed

+296
-294
lines changed

modules/@angular/compiler-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class MyComponent {}
3838
@NgModule({
3939
imports: [BrowserModule],
4040
declarations: [MyComponent],
41-
precompile: [MyComponent]
41+
entryComponents: [MyComponent]
4242
})
4343
export class MainModule {
4444
constructor(appRef: ApplicationRef) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
10+
11+
import {BasicComp} from './basic';
12+
13+
@Component({selector: 'cmp-entryComponents', template: '', entryComponents: [BasicComp]})
14+
export class CompWithEntryComponents {
15+
constructor(public cfr: ComponentFactoryResolver) {}
16+
}
17+
18+
export const SOME_TOKEN = new OpaqueToken('someToken');
19+
20+
export function provideValueWithEntryComponents(value: any) {
21+
return [
22+
{provide: SOME_TOKEN, useValue: value},
23+
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
24+
];
25+
}
26+
27+
@Component({
28+
selector: 'comp-entryComponents-provider',
29+
template: '',
30+
providers: [provideValueWithEntryComponents([{a: 'b', component: BasicComp}])]
31+
})
32+
export class CompWithAnalyzeEntryComponentsProvider {
33+
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
34+
}
35+
}

modules/@angular/compiler-cli/integrationtest/src/module.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,24 @@ import {BrowserModule} from '@angular/platform-browser';
1212

1313
import {AnimateCmp} from './animate';
1414
import {BasicComp} from './basic';
15+
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
1516
import {CompWithProviders, CompWithReferences} from './features';
1617
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibModule, SomePipeInRootModule, SomeService} from './module_fixtures';
17-
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from './precompile';
1818
import {ProjectingComp} from './projection';
1919
import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
2020

2121
@NgModule({
2222
declarations: [
23-
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithPrecompile,
24-
CompWithAnalyzePrecompileProvider, ProjectingComp, CompWithChildQuery, CompWithDirectiveChild,
25-
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences
23+
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithEntryComponents,
24+
CompWithAnalyzeEntryComponentsProvider, ProjectingComp, CompWithChildQuery,
25+
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
26+
CompWithReferences
2627
],
2728
imports: [BrowserModule, FormsModule, SomeLibModule],
2829
providers: [SomeService],
29-
precompile: [
30-
AnimateCmp, BasicComp, CompWithPrecompile, CompWithAnalyzePrecompileProvider, ProjectingComp,
31-
CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
30+
entryComponents: [
31+
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
32+
ProjectingComp, CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
3233
]
3334
})
3435
export class MainModule {

modules/@angular/compiler-cli/integrationtest/src/module_fixtures.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {LowerCasePipe, NgIf} from '@angular/common';
10-
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
10+
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
1111
import {BrowserModule} from '@angular/platform-browser';
1212

1313
@Injectable()
@@ -51,19 +51,19 @@ export class CompUsingLibModuleDirectiveAndPipe {
5151

5252
export const SOME_TOKEN = new OpaqueToken('someToken');
5353

54-
export function provideValueWithPrecompile(value: any) {
54+
export function provideValueWithEntryComponents(value: any) {
5555
return [
5656
{provide: SOME_TOKEN, useValue: value},
57-
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
57+
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
5858
];
5959
}
6060

6161
@NgModule({
6262
declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe],
63-
precompile: [CompUsingLibModuleDirectiveAndPipe],
63+
entryComponents: [CompUsingLibModuleDirectiveAndPipe],
6464
providers: [
6565
ServiceUsingLibModule,
66-
provideValueWithPrecompile([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
66+
provideValueWithEntryComponents([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
6767
],
6868
})
6969
export class SomeLibModule {

modules/@angular/compiler-cli/integrationtest/src/precompile.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

modules/@angular/compiler-cli/integrationtest/test/precompile_spec.ts renamed to modules/@angular/compiler-cli/integrationtest/test/entry_components_spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
import './init';
1010

1111
import {BasicComp} from '../src/basic';
12-
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from '../src/precompile';
12+
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from '../src/entry_components';
1313

1414
import {createComponent} from './util';
1515

1616
describe('content projection', () => {
17-
it('should support precompile in components', () => {
18-
var compFixture = createComponent(CompWithPrecompile);
17+
it('should support entryComponents in components', () => {
18+
var compFixture = createComponent(CompWithEntryComponents);
1919
var cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
2020
expect(cf.componentType).toBe(BasicComp);
2121
});
2222

23-
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
23+
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
2424
() => {
25-
const compFixture = createComponent(CompWithAnalyzePrecompileProvider);
25+
const compFixture = createComponent(CompWithAnalyzeEntryComponentsProvider);
2626
const cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
2727
expect(cf.componentType).toBe(BasicComp);
28-
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
28+
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
29+
// worked.
2930
expect(compFixture.componentInstance.providedValue).toEqual([
3031
{a: 'b', component: BasicComp}
3132
]);

modules/@angular/compiler-cli/integrationtest/test/ng_module_spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('NgModule', () => {
2020
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true);
2121
});
2222

23-
it('should support precompile components', () => {
23+
it('should support entryComponents components', () => {
2424
const moduleRef = createModule();
2525
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
2626
CompUsingRootModuleDirectiveAndPipe);
@@ -29,13 +29,14 @@ describe('NgModule', () => {
2929
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true);
3030
});
3131

32-
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
32+
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
3333
() => {
3434
const moduleRef = createModule();
3535
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
3636
CompUsingRootModuleDirectiveAndPipe);
3737
expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe);
38-
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
38+
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
39+
// worked.
3940
expect(moduleRef.injector.get(SOME_TOKEN)).toEqual([
4041
{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}
4142
]);

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export class CompileTemplateMetadata {
405405
export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
406406
static create(
407407
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host,
408-
lifecycleHooks, providers, viewProviders, queries, viewQueries, precompile, template}: {
408+
lifecycleHooks, providers, viewProviders, queries, viewQueries, entryComponents, template}: {
409409
type?: CompileTypeMetadata,
410410
isComponent?: boolean,
411411
selector?: string,
@@ -421,7 +421,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
421421
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
422422
queries?: CompileQueryMetadata[],
423423
viewQueries?: CompileQueryMetadata[],
424-
precompile?: CompileTypeMetadata[],
424+
entryComponents?: CompileTypeMetadata[],
425425
template?: CompileTemplateMetadata
426426
} = {}): CompileDirectiveMetadata {
427427
var hostListeners: {[key: string]: string} = {};
@@ -470,7 +470,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
470470
viewProviders,
471471
queries,
472472
viewQueries,
473-
precompile,
473+
entryComponents,
474474
template,
475475
});
476476
}
@@ -490,13 +490,13 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
490490
queries: CompileQueryMetadata[];
491491
viewQueries: CompileQueryMetadata[];
492492
// Note: Need to keep types here to prevent cycles!
493-
precompile: CompileTypeMetadata[];
493+
entryComponents: CompileTypeMetadata[];
494494
template: CompileTemplateMetadata;
495495

496496
constructor(
497497
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners,
498498
hostProperties, hostAttributes, lifecycleHooks, providers, viewProviders, queries,
499-
viewQueries, precompile, template}: {
499+
viewQueries, entryComponents, template}: {
500500
type?: CompileTypeMetadata,
501501
isComponent?: boolean,
502502
selector?: string,
@@ -514,7 +514,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
514514
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
515515
queries?: CompileQueryMetadata[],
516516
viewQueries?: CompileQueryMetadata[],
517-
precompile?: CompileTypeMetadata[],
517+
entryComponents?: CompileTypeMetadata[],
518518
template?: CompileTemplateMetadata,
519519
} = {}) {
520520
this.type = type;
@@ -532,7 +532,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
532532
this.viewProviders = _normalizeArray(viewProviders);
533533
this.queries = _normalizeArray(queries);
534534
this.viewQueries = _normalizeArray(viewQueries);
535-
this.precompile = _normalizeArray(precompile);
535+
this.entryComponents = _normalizeArray(entryComponents);
536536
this.template = template;
537537
}
538538

@@ -619,8 +619,8 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
619619
exportedDirectives: CompileDirectiveMetadata[];
620620
declaredPipes: CompilePipeMetadata[];
621621
exportedPipes: CompilePipeMetadata[];
622-
// Note: See CompileDirectiveMetadata.precompile why this has to be a type.
623-
precompile: CompileTypeMetadata[];
622+
// Note: See CompileDirectiveMetadata.entryComponents why this has to be a type.
623+
entryComponents: CompileTypeMetadata[];
624624
providers: CompileProviderMetadata[];
625625

626626
importedModules: CompileNgModuleMetadata[];
@@ -630,15 +630,15 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
630630

631631
constructor(
632632
{type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes,
633-
precompile, importedModules, exportedModules, transitiveModule}: {
633+
entryComponents, importedModules, exportedModules, transitiveModule}: {
634634
type?: CompileTypeMetadata,
635635
providers?:
636636
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
637637
declaredDirectives?: CompileDirectiveMetadata[],
638638
exportedDirectives?: CompileDirectiveMetadata[],
639639
declaredPipes?: CompilePipeMetadata[],
640640
exportedPipes?: CompilePipeMetadata[],
641-
precompile?: CompileTypeMetadata[],
641+
entryComponents?: CompileTypeMetadata[],
642642
importedModules?: CompileNgModuleMetadata[],
643643
exportedModules?: CompileNgModuleMetadata[],
644644
transitiveModule?: TransitiveCompileNgModuleMetadata
@@ -649,7 +649,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
649649
this.declaredPipes = _normalizeArray(declaredPipes);
650650
this.exportedPipes = _normalizeArray(exportedPipes);
651651
this.providers = _normalizeArray(providers);
652-
this.precompile = _normalizeArray(precompile);
652+
this.entryComponents = _normalizeArray(entryComponents);
653653
this.importedModules = _normalizeArray(importedModules);
654654
this.exportedModules = _normalizeArray(exportedModules);
655655
this.transitiveModule = transitiveModule;
@@ -670,7 +670,7 @@ export class TransitiveCompileNgModuleMetadata {
670670
pipesSet = new Set<Type>();
671671
constructor(
672672
public modules: CompileNgModuleMetadata[], public providers: CompileProviderMetadata[],
673-
public precompile: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],
673+
public entryComponents: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],
674674
public pipes: CompilePipeMetadata[]) {
675675
directives.forEach(dir => this.directivesSet.add(dir.type.runtime));
676676
pipes.forEach(pipe => this.pipesSet.add(pipe.type.runtime));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function _cloneDirectiveWithTemplate(
254254
viewProviders: directive.viewProviders,
255255
queries: directive.queries,
256256
viewQueries: directive.viewQueries,
257-
precompile: directive.precompile,
257+
entryComponents: directive.entryComponents,
258258
template: template
259259
});
260260
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export class DirectiveResolver {
143143
changeDetection: dm.changeDetection,
144144
providers: dm.providers,
145145
viewProviders: dm.viewProviders,
146-
precompile: dm.precompile
146+
entryComponents: dm.entryComponents
147147
});
148148

149149
} else {

0 commit comments

Comments
 (0)