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)
This commit is contained in:
parent
46b212706b
commit
6f4e49ed53
|
@ -38,7 +38,7 @@ export class MyComponent {}
|
|||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
declarations: [MyComponent],
|
||||
precompile: [MyComponent]
|
||||
entryComponents: [MyComponent]
|
||||
})
|
||||
export class MainModule {
|
||||
constructor(appRef: ApplicationRef) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
|
||||
|
||||
import {BasicComp} from './basic';
|
||||
|
||||
@Component({selector: 'cmp-entryComponents', template: '', entryComponents: [BasicComp]})
|
||||
export class CompWithEntryComponents {
|
||||
constructor(public cfr: ComponentFactoryResolver) {}
|
||||
}
|
||||
|
||||
export const SOME_TOKEN = new OpaqueToken('someToken');
|
||||
|
||||
export function provideValueWithEntryComponents(value: any) {
|
||||
return [
|
||||
{provide: SOME_TOKEN, useValue: value},
|
||||
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
|
||||
];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'comp-entryComponents-provider',
|
||||
template: '',
|
||||
providers: [provideValueWithEntryComponents([{a: 'b', component: BasicComp}])]
|
||||
})
|
||||
export class CompWithAnalyzeEntryComponentsProvider {
|
||||
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
|
||||
}
|
||||
}
|
|
@ -12,23 +12,24 @@ import {BrowserModule} from '@angular/platform-browser';
|
|||
|
||||
import {AnimateCmp} from './animate';
|
||||
import {BasicComp} from './basic';
|
||||
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from './entry_components';
|
||||
import {CompWithProviders, CompWithReferences} from './features';
|
||||
import {CompUsingRootModuleDirectiveAndPipe, SomeDirectiveInRootModule, SomeLibModule, SomePipeInRootModule, SomeService} from './module_fixtures';
|
||||
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from './precompile';
|
||||
import {ProjectingComp} from './projection';
|
||||
import {CompWithChildQuery, CompWithDirectiveChild} from './queries';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithPrecompile,
|
||||
CompWithAnalyzePrecompileProvider, ProjectingComp, CompWithChildQuery, CompWithDirectiveChild,
|
||||
CompUsingRootModuleDirectiveAndPipe, CompWithProviders, CompWithReferences
|
||||
SomeDirectiveInRootModule, SomePipeInRootModule, AnimateCmp, BasicComp, CompWithEntryComponents,
|
||||
CompWithAnalyzeEntryComponentsProvider, ProjectingComp, CompWithChildQuery,
|
||||
CompWithDirectiveChild, CompUsingRootModuleDirectiveAndPipe, CompWithProviders,
|
||||
CompWithReferences
|
||||
],
|
||||
imports: [BrowserModule, FormsModule, SomeLibModule],
|
||||
providers: [SomeService],
|
||||
precompile: [
|
||||
AnimateCmp, BasicComp, CompWithPrecompile, CompWithAnalyzePrecompileProvider, ProjectingComp,
|
||||
CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
|
||||
entryComponents: [
|
||||
AnimateCmp, BasicComp, CompWithEntryComponents, CompWithAnalyzeEntryComponentsProvider,
|
||||
ProjectingComp, CompWithChildQuery, CompUsingRootModuleDirectiveAndPipe
|
||||
]
|
||||
})
|
||||
export class MainModule {
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {LowerCasePipe, NgIf} from '@angular/common';
|
||||
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
@Injectable()
|
||||
|
@ -51,19 +51,19 @@ export class CompUsingLibModuleDirectiveAndPipe {
|
|||
|
||||
export const SOME_TOKEN = new OpaqueToken('someToken');
|
||||
|
||||
export function provideValueWithPrecompile(value: any) {
|
||||
export function provideValueWithEntryComponents(value: any) {
|
||||
return [
|
||||
{provide: SOME_TOKEN, useValue: value},
|
||||
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
|
||||
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: value, multi: true},
|
||||
];
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe],
|
||||
precompile: [CompUsingLibModuleDirectiveAndPipe],
|
||||
entryComponents: [CompUsingLibModuleDirectiveAndPipe],
|
||||
providers: [
|
||||
ServiceUsingLibModule,
|
||||
provideValueWithPrecompile([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
|
||||
provideValueWithEntryComponents([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
|
||||
],
|
||||
})
|
||||
export class SomeLibModule {
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Inject, OpaqueToken} from '@angular/core';
|
||||
|
||||
import {BasicComp} from './basic';
|
||||
|
||||
@Component({selector: 'cmp-precompile', template: '', precompile: [BasicComp]})
|
||||
export class CompWithPrecompile {
|
||||
constructor(public cfr: ComponentFactoryResolver) {}
|
||||
}
|
||||
|
||||
export const SOME_TOKEN = new OpaqueToken('someToken');
|
||||
|
||||
export function provideValueWithPrecompile(value: any) {
|
||||
return [
|
||||
{provide: SOME_TOKEN, useValue: value},
|
||||
{provide: ANALYZE_FOR_PRECOMPILE, useValue: value, multi: true},
|
||||
];
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'comp-precompile-provider',
|
||||
template: '',
|
||||
providers: [provideValueWithPrecompile([{a: 'b', component: BasicComp}])]
|
||||
})
|
||||
export class CompWithAnalyzePrecompileProvider {
|
||||
constructor(public cfr: ComponentFactoryResolver, @Inject(SOME_TOKEN) public providedValue: any) {
|
||||
}
|
||||
}
|
|
@ -9,23 +9,24 @@
|
|||
import './init';
|
||||
|
||||
import {BasicComp} from '../src/basic';
|
||||
import {CompWithAnalyzePrecompileProvider, CompWithPrecompile} from '../src/precompile';
|
||||
import {CompWithAnalyzeEntryComponentsProvider, CompWithEntryComponents} from '../src/entry_components';
|
||||
|
||||
import {createComponent} from './util';
|
||||
|
||||
describe('content projection', () => {
|
||||
it('should support precompile in components', () => {
|
||||
var compFixture = createComponent(CompWithPrecompile);
|
||||
it('should support entryComponents in components', () => {
|
||||
var compFixture = createComponent(CompWithEntryComponents);
|
||||
var cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
|
||||
expect(cf.componentType).toBe(BasicComp);
|
||||
});
|
||||
|
||||
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
|
||||
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
|
||||
() => {
|
||||
const compFixture = createComponent(CompWithAnalyzePrecompileProvider);
|
||||
const compFixture = createComponent(CompWithAnalyzeEntryComponentsProvider);
|
||||
const cf = compFixture.componentInstance.cfr.resolveComponentFactory(BasicComp);
|
||||
expect(cf.componentType).toBe(BasicComp);
|
||||
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
|
||||
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
|
||||
// worked.
|
||||
expect(compFixture.componentInstance.providedValue).toEqual([
|
||||
{a: 'b', component: BasicComp}
|
||||
]);
|
|
@ -20,7 +20,7 @@ describe('NgModule', () => {
|
|||
expect(moduleRef.injector.get(SomeService) instanceof SomeService).toBe(true);
|
||||
});
|
||||
|
||||
it('should support precompile components', () => {
|
||||
it('should support entryComponents components', () => {
|
||||
const moduleRef = createModule();
|
||||
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
|
||||
CompUsingRootModuleDirectiveAndPipe);
|
||||
|
@ -29,13 +29,14 @@ describe('NgModule', () => {
|
|||
expect(compRef.instance instanceof CompUsingRootModuleDirectiveAndPipe).toBe(true);
|
||||
});
|
||||
|
||||
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
|
||||
it('should support entryComponents via the ANALYZE_FOR_ENTRY_COMPONENTS provider and function providers in components',
|
||||
() => {
|
||||
const moduleRef = createModule();
|
||||
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(
|
||||
CompUsingRootModuleDirectiveAndPipe);
|
||||
expect(cf.componentType).toBe(CompUsingRootModuleDirectiveAndPipe);
|
||||
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
|
||||
// check that the function call that created the provider for ANALYZE_FOR_ENTRY_COMPONENTS
|
||||
// worked.
|
||||
expect(moduleRef.injector.get(SOME_TOKEN)).toEqual([
|
||||
{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}
|
||||
]);
|
||||
|
|
|
@ -405,7 +405,7 @@ export class CompileTemplateMetadata {
|
|||
export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
||||
static create(
|
||||
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host,
|
||||
lifecycleHooks, providers, viewProviders, queries, viewQueries, precompile, template}: {
|
||||
lifecycleHooks, providers, viewProviders, queries, viewQueries, entryComponents, template}: {
|
||||
type?: CompileTypeMetadata,
|
||||
isComponent?: boolean,
|
||||
selector?: string,
|
||||
|
@ -421,7 +421,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
|||
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
|
||||
queries?: CompileQueryMetadata[],
|
||||
viewQueries?: CompileQueryMetadata[],
|
||||
precompile?: CompileTypeMetadata[],
|
||||
entryComponents?: CompileTypeMetadata[],
|
||||
template?: CompileTemplateMetadata
|
||||
} = {}): CompileDirectiveMetadata {
|
||||
var hostListeners: {[key: string]: string} = {};
|
||||
|
@ -470,7 +470,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
|||
viewProviders,
|
||||
queries,
|
||||
viewQueries,
|
||||
precompile,
|
||||
entryComponents,
|
||||
template,
|
||||
});
|
||||
}
|
||||
|
@ -490,13 +490,13 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
|||
queries: CompileQueryMetadata[];
|
||||
viewQueries: CompileQueryMetadata[];
|
||||
// Note: Need to keep types here to prevent cycles!
|
||||
precompile: CompileTypeMetadata[];
|
||||
entryComponents: CompileTypeMetadata[];
|
||||
template: CompileTemplateMetadata;
|
||||
|
||||
constructor(
|
||||
{type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners,
|
||||
hostProperties, hostAttributes, lifecycleHooks, providers, viewProviders, queries,
|
||||
viewQueries, precompile, template}: {
|
||||
viewQueries, entryComponents, template}: {
|
||||
type?: CompileTypeMetadata,
|
||||
isComponent?: boolean,
|
||||
selector?: string,
|
||||
|
@ -514,7 +514,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
|||
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
|
||||
queries?: CompileQueryMetadata[],
|
||||
viewQueries?: CompileQueryMetadata[],
|
||||
precompile?: CompileTypeMetadata[],
|
||||
entryComponents?: CompileTypeMetadata[],
|
||||
template?: CompileTemplateMetadata,
|
||||
} = {}) {
|
||||
this.type = type;
|
||||
|
@ -532,7 +532,7 @@ export class CompileDirectiveMetadata implements CompileMetadataWithIdentifier {
|
|||
this.viewProviders = _normalizeArray(viewProviders);
|
||||
this.queries = _normalizeArray(queries);
|
||||
this.viewQueries = _normalizeArray(viewQueries);
|
||||
this.precompile = _normalizeArray(precompile);
|
||||
this.entryComponents = _normalizeArray(entryComponents);
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
|
@ -619,8 +619,8 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
|
|||
exportedDirectives: CompileDirectiveMetadata[];
|
||||
declaredPipes: CompilePipeMetadata[];
|
||||
exportedPipes: CompilePipeMetadata[];
|
||||
// Note: See CompileDirectiveMetadata.precompile why this has to be a type.
|
||||
precompile: CompileTypeMetadata[];
|
||||
// Note: See CompileDirectiveMetadata.entryComponents why this has to be a type.
|
||||
entryComponents: CompileTypeMetadata[];
|
||||
providers: CompileProviderMetadata[];
|
||||
|
||||
importedModules: CompileNgModuleMetadata[];
|
||||
|
@ -630,7 +630,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
|
|||
|
||||
constructor(
|
||||
{type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes,
|
||||
precompile, importedModules, exportedModules, transitiveModule}: {
|
||||
entryComponents, importedModules, exportedModules, transitiveModule}: {
|
||||
type?: CompileTypeMetadata,
|
||||
providers?:
|
||||
Array<CompileProviderMetadata|CompileTypeMetadata|CompileIdentifierMetadata|any[]>,
|
||||
|
@ -638,7 +638,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
|
|||
exportedDirectives?: CompileDirectiveMetadata[],
|
||||
declaredPipes?: CompilePipeMetadata[],
|
||||
exportedPipes?: CompilePipeMetadata[],
|
||||
precompile?: CompileTypeMetadata[],
|
||||
entryComponents?: CompileTypeMetadata[],
|
||||
importedModules?: CompileNgModuleMetadata[],
|
||||
exportedModules?: CompileNgModuleMetadata[],
|
||||
transitiveModule?: TransitiveCompileNgModuleMetadata
|
||||
|
@ -649,7 +649,7 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
|
|||
this.declaredPipes = _normalizeArray(declaredPipes);
|
||||
this.exportedPipes = _normalizeArray(exportedPipes);
|
||||
this.providers = _normalizeArray(providers);
|
||||
this.precompile = _normalizeArray(precompile);
|
||||
this.entryComponents = _normalizeArray(entryComponents);
|
||||
this.importedModules = _normalizeArray(importedModules);
|
||||
this.exportedModules = _normalizeArray(exportedModules);
|
||||
this.transitiveModule = transitiveModule;
|
||||
|
@ -670,7 +670,7 @@ export class TransitiveCompileNgModuleMetadata {
|
|||
pipesSet = new Set<Type>();
|
||||
constructor(
|
||||
public modules: CompileNgModuleMetadata[], public providers: CompileProviderMetadata[],
|
||||
public precompile: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],
|
||||
public entryComponents: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],
|
||||
public pipes: CompilePipeMetadata[]) {
|
||||
directives.forEach(dir => this.directivesSet.add(dir.type.runtime));
|
||||
pipes.forEach(pipe => this.pipesSet.add(pipe.type.runtime));
|
||||
|
|
|
@ -254,7 +254,7 @@ function _cloneDirectiveWithTemplate(
|
|||
viewProviders: directive.viewProviders,
|
||||
queries: directive.queries,
|
||||
viewQueries: directive.viewQueries,
|
||||
precompile: directive.precompile,
|
||||
entryComponents: directive.entryComponents,
|
||||
template: template
|
||||
});
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ export class DirectiveResolver {
|
|||
changeDetection: dm.changeDetection,
|
||||
providers: dm.providers,
|
||||
viewProviders: dm.viewProviders,
|
||||
precompile: dm.precompile
|
||||
entryComponents: dm.entryComponents
|
||||
});
|
||||
|
||||
} else {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_PRECOMPILE, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, ChangeDetectionStrategy, ChangeDetectorRef, ComponentFactory, ComponentFactoryResolver, ElementRef, Injector, NgModuleFactory, QueryList, RenderComponentType, Renderer, SecurityContext, SimpleChange, TemplateRef, ViewContainerRef, ViewEncapsulation} from '@angular/core';
|
||||
|
||||
import {AnimationGroupPlayer as AnimationGroupPlayer_, AnimationKeyframe as AnimationKeyframe_, AnimationSequencePlayer as AnimationSequencePlayer_, AnimationStyles as AnimationStyles_, AppElement, AppView, ChangeDetectorStatus, CodegenComponentFactoryResolver, DebugAppView, DebugContext, EMPTY_ARRAY, EMPTY_MAP, NgModuleInjector, NoOpAnimationPlayer as NoOpAnimationPlayer_, StaticNodeDebugInfo, TemplateRef_, UNINITIALIZED, ValueUnwrapper, ViewType, ViewUtils, balanceAnimationKeyframes as impBalanceAnimationKeyframes, castByValue, checkBinding, clearStyles as impClearStyles, collectAndResolveStyles as impCollectAndResolveStyles, devModeEqual, flattenNestedViewRenderNodes, interpolate, prepareFinalAnimationStyles as impBalanceAnimationStyles, pureProxy1, pureProxy10, pureProxy2, pureProxy3, pureProxy4, pureProxy5, pureProxy6, pureProxy7, pureProxy8, pureProxy9, renderStyles as impRenderStyles} from '../core_private';
|
||||
|
||||
|
@ -58,10 +58,10 @@ var impNoOpAnimationPlayer = NoOpAnimationPlayer_;
|
|||
var ANIMATION_STYLE_UTIL_ASSET_URL = assetUrl('core', 'animation/animation_style_util');
|
||||
|
||||
export class Identifiers {
|
||||
static ANALYZE_FOR_PRECOMPILE = new CompileIdentifierMetadata({
|
||||
name: 'ANALYZE_FOR_PRECOMPILE',
|
||||
static ANALYZE_FOR_ENTRY_COMPONENTS = new CompileIdentifierMetadata({
|
||||
name: 'ANALYZE_FOR_ENTRY_COMPONENTS',
|
||||
moduleUrl: assetUrl('core', 'metadata/di'),
|
||||
runtime: ANALYZE_FOR_PRECOMPILE
|
||||
runtime: ANALYZE_FOR_ENTRY_COMPONENTS
|
||||
});
|
||||
static ViewUtils = new CompileIdentifierMetadata(
|
||||
{name: 'ViewUtils', moduleUrl: assetUrl('core', 'linker/view_utils'), runtime: impViewUtils});
|
||||
|
|
|
@ -123,7 +123,7 @@ export class CompileMetadataResolver {
|
|||
var changeDetectionStrategy: ChangeDetectionStrategy = null;
|
||||
var viewProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
|
||||
var moduleUrl = staticTypeModuleUrl(directiveType);
|
||||
var precompileTypes: cpl.CompileTypeMetadata[] = [];
|
||||
var entryComponentTypes: cpl.CompileTypeMetadata[] = [];
|
||||
if (dirMeta instanceof ComponentMetadata) {
|
||||
var cmpMeta = <ComponentMetadata>dirMeta;
|
||||
var viewMeta = this._viewResolver.resolve(directiveType);
|
||||
|
@ -150,9 +150,10 @@ export class CompileMetadataResolver {
|
|||
verifyNonBlankProviders(directiveType, dirMeta.viewProviders, 'viewProviders'), []);
|
||||
}
|
||||
moduleUrl = componentModuleUrl(this._reflector, directiveType, cmpMeta);
|
||||
if (cmpMeta.precompile) {
|
||||
precompileTypes = flattenArray(cmpMeta.precompile)
|
||||
.map((cmp) => this.getTypeMetadata(cmp, staticTypeModuleUrl(cmp)));
|
||||
if (cmpMeta.entryComponents) {
|
||||
entryComponentTypes =
|
||||
flattenArray(cmpMeta.entryComponents)
|
||||
.map((cmp) => this.getTypeMetadata(cmp, staticTypeModuleUrl(cmp)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,7 +161,7 @@ export class CompileMetadataResolver {
|
|||
if (isPresent(dirMeta.providers)) {
|
||||
providers = this.getProvidersMetadata(
|
||||
verifyNonBlankProviders(directiveType, dirMeta.providers, 'providers'),
|
||||
precompileTypes);
|
||||
entryComponentTypes);
|
||||
}
|
||||
var queries: cpl.CompileQueryMetadata[] = [];
|
||||
var viewQueries: cpl.CompileQueryMetadata[] = [];
|
||||
|
@ -184,7 +185,7 @@ export class CompileMetadataResolver {
|
|||
viewProviders: viewProviders,
|
||||
queries: queries,
|
||||
viewQueries: viewQueries,
|
||||
precompile: precompileTypes
|
||||
entryComponents: entryComponentTypes
|
||||
});
|
||||
this._directiveCache.set(directiveType, meta);
|
||||
}
|
||||
|
@ -259,7 +260,8 @@ export class CompileMetadataResolver {
|
|||
if (declaredDirMeta = this.getDirectiveMetadata(declaredType, false)) {
|
||||
this._addDirectiveToModule(
|
||||
declaredDirMeta, moduleType, transitiveModule, declaredDirectives, true);
|
||||
// Collect @Component.directives/pipes/precompile into our declared directives/pipes.
|
||||
// Collect @Component.directives/pipes/entryComponents into our declared
|
||||
// directives/pipes.
|
||||
this._getTransitiveViewDirectivesAndPipes(
|
||||
declaredDirMeta, moduleType, transitiveModule, declaredDirectives, declaredPipes);
|
||||
} else if (declaredPipeMeta = this.getPipeMetadata(declaredType, false)) {
|
||||
|
@ -273,22 +275,23 @@ export class CompileMetadataResolver {
|
|||
}
|
||||
|
||||
const providers: any[] = [];
|
||||
const precompile: cpl.CompileTypeMetadata[] = [];
|
||||
const entryComponents: cpl.CompileTypeMetadata[] = [];
|
||||
if (meta.providers) {
|
||||
providers.push(...this.getProvidersMetadata(meta.providers, precompile));
|
||||
providers.push(...this.getProvidersMetadata(meta.providers, entryComponents));
|
||||
}
|
||||
if (meta.precompile) {
|
||||
precompile.push(...flattenArray(meta.precompile)
|
||||
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
|
||||
if (meta.entryComponents) {
|
||||
entryComponents.push(
|
||||
...flattenArray(meta.entryComponents)
|
||||
.map(type => this.getTypeMetadata(type, staticTypeModuleUrl(type))));
|
||||
}
|
||||
|
||||
transitiveModule.precompile.push(...precompile);
|
||||
transitiveModule.entryComponents.push(...entryComponents);
|
||||
transitiveModule.providers.push(...providers);
|
||||
|
||||
compileMeta = new cpl.CompileNgModuleMetadata({
|
||||
type: this.getTypeMetadata(moduleType, staticTypeModuleUrl(moduleType)),
|
||||
providers: providers,
|
||||
precompile: precompile,
|
||||
entryComponents: entryComponents,
|
||||
declaredDirectives: declaredDirectives,
|
||||
exportedDirectives: exportedDirectives,
|
||||
declaredPipes: declaredPipes,
|
||||
|
@ -306,7 +309,7 @@ export class CompileMetadataResolver {
|
|||
|
||||
addComponentToModule(moduleType: Type, compType: Type) {
|
||||
const moduleMeta = this.getNgModuleMetadata(moduleType);
|
||||
// Collect @Component.directives/pipes/precompile into our declared directives/pipes.
|
||||
// Collect @Component.directives/pipes/entryComponents into our declared directives/pipes.
|
||||
const compMeta = this.getDirectiveMetadata(compType, false);
|
||||
this._addDirectiveToModule(
|
||||
compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
|
||||
|
@ -315,8 +318,8 @@ export class CompileMetadataResolver {
|
|||
compMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
|
||||
moduleMeta.declaredDirectives, moduleMeta.declaredPipes);
|
||||
|
||||
moduleMeta.transitiveModule.precompile.push(compMeta.type);
|
||||
moduleMeta.precompile.push(compMeta.type);
|
||||
moduleMeta.transitiveModule.entryComponents.push(compMeta.type);
|
||||
moduleMeta.entryComponents.push(compMeta.type);
|
||||
|
||||
this._verifyModule(moduleMeta);
|
||||
}
|
||||
|
@ -335,17 +338,17 @@ export class CompileMetadataResolver {
|
|||
}
|
||||
});
|
||||
moduleMeta.declaredDirectives.forEach((dirMeta) => {
|
||||
dirMeta.precompile.forEach((precompileComp) => {
|
||||
if (!moduleMeta.transitiveModule.directivesSet.has(precompileComp.runtime)) {
|
||||
dirMeta.entryComponents.forEach((entryComponent) => {
|
||||
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponent.runtime)) {
|
||||
throw new BaseException(
|
||||
`Component ${stringify(dirMeta.type.runtime)} in NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(precompileComp.runtime)} via "precompile" but it was neither declared nor imported into the module!`);
|
||||
`Component ${stringify(dirMeta.type.runtime)} in NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponent.runtime)} via "entryComponents" but it was neither declared nor imported into the module!`);
|
||||
}
|
||||
});
|
||||
});
|
||||
moduleMeta.precompile.forEach((precompileType) => {
|
||||
if (!moduleMeta.transitiveModule.directivesSet.has(precompileType.runtime)) {
|
||||
moduleMeta.entryComponents.forEach((entryComponentType) => {
|
||||
if (!moduleMeta.transitiveModule.directivesSet.has(entryComponentType.runtime)) {
|
||||
throw new BaseException(
|
||||
`NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(precompileType.runtime)} via "precompile" but it was neither declared nor imported!`);
|
||||
`NgModule ${stringify(moduleMeta.type.runtime)} uses ${stringify(entryComponentType.runtime)} via "entryComponents" but it was neither declared nor imported!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -400,17 +403,18 @@ export class CompileMetadataResolver {
|
|||
private _getTransitiveNgModuleMetadata(
|
||||
importedModules: cpl.CompileNgModuleMetadata[],
|
||||
exportedModules: cpl.CompileNgModuleMetadata[]): cpl.TransitiveCompileNgModuleMetadata {
|
||||
// collect `providers` / `precompile` from all imported and all exported modules
|
||||
// collect `providers` / `entryComponents` from all imported and all exported modules
|
||||
const transitiveModules = getTransitiveModules(importedModules.concat(exportedModules), true);
|
||||
const providers = flattenArray(transitiveModules.map((ngModule) => ngModule.providers));
|
||||
const precompile = flattenArray(transitiveModules.map((ngModule) => ngModule.precompile));
|
||||
const entryComponents =
|
||||
flattenArray(transitiveModules.map((ngModule) => ngModule.entryComponents));
|
||||
|
||||
const transitiveExportedModules = getTransitiveModules(importedModules, false);
|
||||
const directives =
|
||||
flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedDirectives));
|
||||
const pipes = flattenArray(transitiveExportedModules.map((ngModule) => ngModule.exportedPipes));
|
||||
return new cpl.TransitiveCompileNgModuleMetadata(
|
||||
transitiveModules, providers, precompile, directives, pipes);
|
||||
transitiveModules, providers, entryComponents, directives, pipes);
|
||||
}
|
||||
|
||||
private _addDirectiveToModule(
|
||||
|
@ -571,7 +575,7 @@ export class CompileMetadataResolver {
|
|||
return compileToken;
|
||||
}
|
||||
|
||||
getProvidersMetadata(providers: any[], targetPrecompileComponents: cpl.CompileTypeMetadata[]):
|
||||
getProvidersMetadata(providers: any[], targetEntryComponents: cpl.CompileTypeMetadata[]):
|
||||
Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> {
|
||||
const compileProviders: Array<cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[]> = [];
|
||||
providers.forEach((provider) => {
|
||||
|
@ -581,11 +585,11 @@ export class CompileMetadataResolver {
|
|||
}
|
||||
let compileProvider: cpl.CompileProviderMetadata|cpl.CompileTypeMetadata|any[];
|
||||
if (isArray(provider)) {
|
||||
compileProvider = this.getProvidersMetadata(provider, targetPrecompileComponents);
|
||||
compileProvider = this.getProvidersMetadata(provider, targetEntryComponents);
|
||||
} else if (provider instanceof Provider) {
|
||||
let tokenMeta = this.getTokenMetadata(provider.token);
|
||||
if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_PRECOMPILE))) {
|
||||
targetPrecompileComponents.push(...this.getPrecompileComponentsFromProvider(provider));
|
||||
if (tokenMeta.equalsTo(identifierToken(Identifiers.ANALYZE_FOR_ENTRY_COMPONENTS))) {
|
||||
targetEntryComponents.push(...this._getEntryComponentsFromProvider(provider));
|
||||
} else {
|
||||
compileProvider = this.getProviderMetadata(provider);
|
||||
}
|
||||
|
@ -602,14 +606,15 @@ export class CompileMetadataResolver {
|
|||
return compileProviders;
|
||||
}
|
||||
|
||||
getPrecompileComponentsFromProvider(provider: Provider): cpl.CompileTypeMetadata[] {
|
||||
private _getEntryComponentsFromProvider(provider: Provider): cpl.CompileTypeMetadata[] {
|
||||
let components: cpl.CompileTypeMetadata[] = [];
|
||||
let collectedIdentifiers: cpl.CompileIdentifierMetadata[] = [];
|
||||
if (provider.useFactory || provider.useExisting || provider.useClass) {
|
||||
throw new BaseException(`The ANALYZE_FOR_PRECOMPILE token only supports useValue!`);
|
||||
throw new BaseException(`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports useValue!`);
|
||||
}
|
||||
if (!provider.multi) {
|
||||
throw new BaseException(`The ANALYZE_FOR_PRECOMPILE token only supports 'multi = true'!`);
|
||||
throw new BaseException(
|
||||
`The ANALYZE_FOR_ENTRY_COMPONENTS token only supports 'multi = true'!`);
|
||||
}
|
||||
convertToCompileValue(provider.useValue, collectedIdentifiers);
|
||||
collectedIdentifiers.forEach((identifier) => {
|
||||
|
|
|
@ -41,12 +41,12 @@ export class NgModuleCompiler {
|
|||
new ParseLocation(sourceFile, null, null, null),
|
||||
new ParseLocation(sourceFile, null, null, null));
|
||||
var deps: ComponentFactoryDependency[] = [];
|
||||
var precompileComponents = ngModuleMeta.transitiveModule.precompile.map((precompileComp) => {
|
||||
var id = new CompileIdentifierMetadata({name: precompileComp.name});
|
||||
deps.push(new ComponentFactoryDependency(precompileComp, id));
|
||||
var entryComponents = ngModuleMeta.transitiveModule.entryComponents.map((entryComponent) => {
|
||||
var id = new CompileIdentifierMetadata({name: entryComponent.name});
|
||||
deps.push(new ComponentFactoryDependency(entryComponent, id));
|
||||
return id;
|
||||
});
|
||||
var builder = new _InjectorBuilder(ngModuleMeta, precompileComponents, sourceSpan);
|
||||
var builder = new _InjectorBuilder(ngModuleMeta, entryComponents, sourceSpan);
|
||||
|
||||
var providerParser = new NgModuleProviderAnalyzer(ngModuleMeta, extraProviders, sourceSpan);
|
||||
providerParser.parse().forEach((provider) => builder.addProvider(provider));
|
||||
|
@ -75,8 +75,8 @@ class _InjectorBuilder {
|
|||
|
||||
constructor(
|
||||
private _ngModuleMeta: CompileNgModuleMetadata,
|
||||
private _precompileComponents: CompileIdentifierMetadata[],
|
||||
private _sourceSpan: ParseSourceSpan) {}
|
||||
private _entryComponents: CompileIdentifierMetadata[], private _sourceSpan: ParseSourceSpan) {
|
||||
}
|
||||
|
||||
addProvider(resolvedProvider: ProviderAst) {
|
||||
var providerValueExpressions =
|
||||
|
@ -116,8 +116,8 @@ class _InjectorBuilder {
|
|||
[o.SUPER_EXPR
|
||||
.callFn([
|
||||
o.variable(InjectorProps.parent.name),
|
||||
o.literalArr(this._precompileComponents.map(
|
||||
(precompiledComponent) => o.importExpr(precompiledComponent)))
|
||||
o.literalArr(
|
||||
this._entryComponents.map((entryComponent) => o.importExpr(entryComponent)))
|
||||
])
|
||||
.toStmt()]);
|
||||
|
||||
|
|
|
@ -146,13 +146,13 @@ export class RuntimeCompiler implements Compiler {
|
|||
templates.add(this._createCompiledTemplate(
|
||||
dirMeta, localModuleMeta.transitiveModule.directives,
|
||||
localModuleMeta.transitiveModule.pipes));
|
||||
dirMeta.precompile.forEach((precompileType) => {
|
||||
templates.add(this._createCompiledHostTemplate(precompileType.runtime));
|
||||
dirMeta.entryComponents.forEach((entryComponentType) => {
|
||||
templates.add(this._createCompiledHostTemplate(entryComponentType.runtime));
|
||||
});
|
||||
}
|
||||
});
|
||||
localModuleMeta.precompile.forEach((precompileType) => {
|
||||
templates.add(this._createCompiledHostTemplate(precompileType.runtime));
|
||||
localModuleMeta.entryComponents.forEach((entryComponentType) => {
|
||||
templates.add(this._createCompiledHostTemplate(entryComponentType.runtime));
|
||||
});
|
||||
});
|
||||
templates.forEach((template) => {
|
||||
|
|
|
@ -92,14 +92,13 @@ export class CompileElement extends CompileNode {
|
|||
this._instances.add(identifierToken(Identifiers.AppElement), this.appElement);
|
||||
}
|
||||
|
||||
public createComponentFactoryResolver(precompileComponent: CompileIdentifierMetadata[]) {
|
||||
if (!precompileComponent || precompileComponent.length === 0) {
|
||||
public createComponentFactoryResolver(entryComponents: CompileIdentifierMetadata[]) {
|
||||
if (!entryComponents || entryComponents.length === 0) {
|
||||
return;
|
||||
}
|
||||
var createComponentFactoryResolverExpr =
|
||||
o.importExpr(Identifiers.CodegenComponentFactoryResolver).instantiate([
|
||||
o.literalArr(precompileComponent.map(
|
||||
(precompiledComponent) => o.importExpr(precompiledComponent))),
|
||||
o.literalArr(entryComponents.map((entryComponent) => o.importExpr(entryComponent))),
|
||||
injectFromViewParentInjector(identifierToken(Identifiers.ComponentFactoryResolver), false)
|
||||
]);
|
||||
var provider = new CompileProviderMetadata({
|
||||
|
|
|
@ -211,13 +211,13 @@ class ViewBuilderVisitor implements TemplateAstVisitor {
|
|||
new CompileIdentifierMetadata({name: getViewFactoryName(component, 0)});
|
||||
this.targetDependencies.push(
|
||||
new ViewFactoryDependency(component.type, nestedComponentIdentifier));
|
||||
let precompileComponentIdentifiers =
|
||||
component.precompile.map((precompileComp: CompileIdentifierMetadata) => {
|
||||
var id = new CompileIdentifierMetadata({name: precompileComp.name});
|
||||
this.targetDependencies.push(new ComponentFactoryDependency(precompileComp, id));
|
||||
let entryComponentIdentifiers =
|
||||
component.entryComponents.map((entryComponent: CompileIdentifierMetadata) => {
|
||||
var id = new CompileIdentifierMetadata({name: entryComponent.name});
|
||||
this.targetDependencies.push(new ComponentFactoryDependency(entryComponent, id));
|
||||
return id;
|
||||
});
|
||||
compileElement.createComponentFactoryResolver(precompileComponentIdentifiers);
|
||||
compileElement.createComponentFactoryResolver(entryComponentIdentifiers);
|
||||
|
||||
compViewExpr = o.variable(`compView_${nodeIndex}`); // fix highlighting: `
|
||||
compileElement.setComponentView(compViewExpr);
|
||||
|
|
|
@ -21,7 +21,7 @@ class SomeClass5 {}
|
|||
imports: [SomeClass2],
|
||||
exports: [SomeClass3],
|
||||
providers: [SomeClass4],
|
||||
precompile: [SomeClass5]
|
||||
entryComponents: [SomeClass5]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ export function main() {
|
|||
imports: [SomeClass2],
|
||||
exports: [SomeClass3],
|
||||
providers: [SomeClass4],
|
||||
precompile: [SomeClass5]
|
||||
entryComponents: [SomeClass5]
|
||||
}));
|
||||
});
|
||||
|
||||
|
|
|
@ -116,8 +116,10 @@ export function main() {
|
|||
|
||||
describe('compileModuleAsync', () => {
|
||||
it('should allow to use templateUrl components', fakeAsync(() => {
|
||||
@NgModule(
|
||||
{declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]})
|
||||
@NgModule({
|
||||
declarations: [SomeCompWithUrlTemplate],
|
||||
entryComponents: [SomeCompWithUrlTemplate]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
@ -131,7 +133,8 @@ export function main() {
|
|||
|
||||
describe('compileModuleSync', () => {
|
||||
it('should throw when using a templateUrl that has not been compiled before', () => {
|
||||
@NgModule({declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]})
|
||||
@NgModule(
|
||||
{declarations: [SomeCompWithUrlTemplate], entryComponents: [SomeCompWithUrlTemplate]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
@ -143,7 +146,7 @@ export function main() {
|
|||
|
||||
it('should throw when using a templateUrl in a nested component that has not been compiled before',
|
||||
() => {
|
||||
@NgModule({declarations: [SomeComp], precompile: [SomeComp]})
|
||||
@NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
@ -158,8 +161,10 @@ export function main() {
|
|||
|
||||
it('should allow to use templateUrl components that have been loaded before',
|
||||
fakeAsync(() => {
|
||||
@NgModule(
|
||||
{declarations: [SomeCompWithUrlTemplate], precompile: [SomeCompWithUrlTemplate]})
|
||||
@NgModule({
|
||||
declarations: [SomeCompWithUrlTemplate],
|
||||
entryComponents: [SomeCompWithUrlTemplate]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
|
|||
changeDetection: dm.changeDetection,
|
||||
providers: providers,
|
||||
viewProviders: viewProviders,
|
||||
precompile: dm.precompile
|
||||
entryComponents: dm.entryComponents
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ export class Compiler {
|
|||
`Runtime compiler is not loaded. Tried to compile ${stringify(component)}`);
|
||||
}
|
||||
/**
|
||||
* Compiles the given NgModule. All templates of the components listed in `precompile`
|
||||
* Compiles the given NgModule. All templates of the components listed in `entryComponents`
|
||||
* have to be either inline or compiled before via `compileComponentAsync` /
|
||||
* `compileModuleAsync`. Otherwise throws a {@link ComponentStillLoadingError}.
|
||||
*/
|
||||
|
|
|
@ -14,13 +14,13 @@ import {ComponentFactory} from './component_factory';
|
|||
* can later be used to create and render a Component instance.
|
||||
*
|
||||
* @deprecated Use {@link ComponentFactoryResolver} together with {@link
|
||||
* NgModule}.precompile}/{@link Component}.precompile or
|
||||
* {@link ANALYZE_FOR_PRECOMPILE} provider for dynamic component creation.
|
||||
* NgModule}.entryComponents}/{@link Component}.entryComponents or
|
||||
* {@link ANALYZE_FOR_ENTRY_COMPONENTS} provider for dynamic component creation.
|
||||
* Use {@link NgModuleFactoryLoader} for lazy loading.
|
||||
*/
|
||||
export abstract class ComponentResolver {
|
||||
static DynamicCompilationDeprecationMsg =
|
||||
'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.precompile or ANALYZE_FOR_PRECOMPILE provider instead. For runtime compile only, you can also use Compiler.compileComponentSync/Async.';
|
||||
'ComponentResolver is deprecated for dynamic compilation. Use ComponentFactoryResolver together with @NgModule/@Component.entryComponents or ANALYZE_FOR_ENTRY_COMPONENTS provider instead. For runtime compile only, you can also use Compiler.compileComponentSync/Async.';
|
||||
static LazyLoadingDeprecationMsg =
|
||||
'ComponentResolver is deprecated for lazy loading. Use NgModuleFactoryLoader instead.';
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ export abstract class NgModuleRef<T> {
|
|||
|
||||
/**
|
||||
* The ComponentFactoryResolver to get hold of the ComponentFactories
|
||||
* delcared in the `precompile` property of the module.
|
||||
* delcared in the `entryComponents` property of the module.
|
||||
*/
|
||||
get componentFactoryResolver(): ComponentFactoryResolver { return unimplemented(); }
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerM
|
|||
import {NgModuleMetadata} from './metadata/ng_module';
|
||||
import {ViewEncapsulation, ViewMetadata} from './metadata/view';
|
||||
|
||||
export {ANALYZE_FOR_PRECOMPILE, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
|
||||
export {ANALYZE_FOR_ENTRY_COMPONENTS, AttributeMetadata, ContentChildMetadata, ContentChildrenMetadata, QueryMetadata, ViewChildMetadata, ViewChildrenMetadata, ViewQueryMetadata} from './metadata/di';
|
||||
export {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, InputMetadata, OutputMetadata, PipeMetadata} from './metadata/directives';
|
||||
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
|
||||
export {NgModuleMetadata} from './metadata/ng_module';
|
||||
|
@ -209,7 +209,7 @@ export interface ComponentMetadataFactory {
|
|||
pipes?: Array<Type|any[]>,
|
||||
encapsulation?: ViewEncapsulation,
|
||||
interpolation?: [string, string],
|
||||
precompile?: Array<Type|any[]>
|
||||
entryComponents?: Array<Type|any[]>
|
||||
}): ComponentDecorator;
|
||||
new (obj: {
|
||||
selector?: string,
|
||||
|
@ -233,7 +233,7 @@ export interface ComponentMetadataFactory {
|
|||
pipes?: Array<Type|any[]>,
|
||||
encapsulation?: ViewEncapsulation,
|
||||
interpolation?: [string, string],
|
||||
precompile?: Array<Type|any[]>
|
||||
entryComponents?: Array<Type|any[]>
|
||||
}): ComponentMetadata;
|
||||
}
|
||||
|
||||
|
@ -500,14 +500,14 @@ export interface NgModuleMetadataFactory {
|
|||
declarations?: Array<Type|any[]>,
|
||||
imports?: Array<Type|any[]>,
|
||||
exports?: Array<Type|any[]>,
|
||||
precompile?: Array<Type|any[]>
|
||||
entryComponents?: Array<Type|any[]>
|
||||
}): NgModuleDecorator;
|
||||
new (obj?: {
|
||||
providers?: any[],
|
||||
declarations?: Array<Type|any[]>,
|
||||
imports?: Array<Type|any[]>,
|
||||
exports?: Array<Type|any[]>,
|
||||
precompile?: Array<Type|any[]>
|
||||
entryComponents?: Array<Type|any[]>
|
||||
}): NgModuleMetadata;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,12 +13,12 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
|
|||
|
||||
/**
|
||||
* This token can be used to create a virtual provider that will populate the
|
||||
* `precompile` fields of components and ng modules based on its `useValue`.
|
||||
* `entryComponents` fields of components and ng modules based on its `useValue`.
|
||||
* All components that are referenced in the `useValue` value (either directly
|
||||
* or in a nested array or map) will be added to the `precompile` property.
|
||||
* or in a nested array or map) will be added to the `entryComponents` property.
|
||||
*
|
||||
* ### Example
|
||||
* The following example shows how the router can populate the `precompile`
|
||||
* The following example shows how the router can populate the `entryComponents`
|
||||
* field of an NgModule based on the router configuration which refers
|
||||
* to components.
|
||||
*
|
||||
|
@ -27,7 +27,7 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
|
|||
* function provideRoutes(routes) {
|
||||
* return [
|
||||
* {provide: ROUTES, useValue: routes},
|
||||
* {provide: ANALYZE_FOR_PRECOMPILE, useValue: routes, multi: true}
|
||||
* {provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: routes, multi: true}
|
||||
* ];
|
||||
* }
|
||||
*
|
||||
|
@ -45,7 +45,7 @@ import {StringWrapper, Type, isString, stringify} from '../facade/lang';
|
|||
*
|
||||
* @experimental
|
||||
*/
|
||||
export const ANALYZE_FOR_PRECOMPILE = new OpaqueToken('AnalyzeForPrecompile');
|
||||
export const ANALYZE_FOR_ENTRY_COMPONENTS = new OpaqueToken('AnalyzeForEntryComponents');
|
||||
|
||||
/**
|
||||
* Specifies that a constant attribute value should be injected.
|
||||
|
|
|
@ -967,58 +967,43 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
interpolation: [string, string];
|
||||
|
||||
/**
|
||||
* Defines the components that should be precompiled as well when
|
||||
* Defines the components that should be compiled as well when
|
||||
* this component is defined. For each components listed here,
|
||||
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
|
||||
* {@link ComponentFactoryResolver ComponentFactoryResolver}.
|
||||
*/
|
||||
precompile: Array<Type|any[]>;
|
||||
entryComponents: Array<Type|any[]>;
|
||||
|
||||
constructor({selector,
|
||||
inputs,
|
||||
outputs,
|
||||
properties,
|
||||
events,
|
||||
host,
|
||||
exportAs,
|
||||
moduleId,
|
||||
providers,
|
||||
viewProviders,
|
||||
changeDetection = ChangeDetectionStrategy.Default,
|
||||
queries,
|
||||
templateUrl,
|
||||
template,
|
||||
styleUrls,
|
||||
styles,
|
||||
animations,
|
||||
directives,
|
||||
pipes,
|
||||
encapsulation,
|
||||
interpolation,
|
||||
precompile}: {
|
||||
selector?: string,
|
||||
inputs?: string[],
|
||||
outputs?: string[],
|
||||
/** @deprecated */ properties?: string[],
|
||||
/** @deprecated */ events?: string[],
|
||||
host?: {[key: string]: string},
|
||||
providers?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
viewProviders?: any[],
|
||||
queries?: {[key: string]: any},
|
||||
changeDetection?: ChangeDetectionStrategy,
|
||||
templateUrl?: string,
|
||||
template?: string,
|
||||
styleUrls?: string[],
|
||||
styles?: string[],
|
||||
animations?: AnimationEntryMetadata[],
|
||||
directives?: Array<Type|any[]>,
|
||||
pipes?: Array<Type|any[]>,
|
||||
encapsulation?: ViewEncapsulation,
|
||||
interpolation?: [string, string],
|
||||
precompile?: Array<Type|any[]>
|
||||
} = {}) {
|
||||
constructor(
|
||||
{selector, inputs, outputs, properties, events, host, exportAs, moduleId, providers,
|
||||
viewProviders, changeDetection = ChangeDetectionStrategy.Default, queries, templateUrl,
|
||||
template, styleUrls, styles, animations, directives, pipes, encapsulation, interpolation,
|
||||
/** @deprecated use entryComponents instead! */
|
||||
precompile, entryComponents}: {
|
||||
selector?: string,
|
||||
inputs?: string[],
|
||||
outputs?: string[],
|
||||
/** @deprecated */ properties?: string[],
|
||||
/** @deprecated */ events?: string[],
|
||||
host?: {[key: string]: string},
|
||||
providers?: any[],
|
||||
exportAs?: string,
|
||||
moduleId?: string,
|
||||
viewProviders?: any[],
|
||||
queries?: {[key: string]: any},
|
||||
changeDetection?: ChangeDetectionStrategy,
|
||||
templateUrl?: string,
|
||||
template?: string,
|
||||
styleUrls?: string[],
|
||||
styles?: string[],
|
||||
animations?: AnimationEntryMetadata[],
|
||||
directives?: Array<Type|any[]>,
|
||||
pipes?: Array<Type|any[]>,
|
||||
encapsulation?: ViewEncapsulation,
|
||||
interpolation?: [string, string],
|
||||
precompile?: Array<Type|any[]>,
|
||||
entryComponents?: Array<Type|any[]>
|
||||
} = {}) {
|
||||
super({
|
||||
selector: selector,
|
||||
inputs: inputs,
|
||||
|
@ -1043,7 +1028,7 @@ export class ComponentMetadata extends DirectiveMetadata {
|
|||
this.moduleId = moduleId;
|
||||
this.animations = animations;
|
||||
this.interpolation = interpolation;
|
||||
this.precompile = precompile;
|
||||
this.entryComponents = precompile ? precompile : entryComponents;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -96,25 +96,25 @@ export class NgModuleMetadata extends InjectableMetadata {
|
|||
exports: Array<Type|any[]>;
|
||||
|
||||
/**
|
||||
* Defines the components that should be precompiled as well when
|
||||
* Defines the components that should be compiled as well when
|
||||
* this component is defined. For each components listed here,
|
||||
* Angular will create a {@link ComponentFactory ComponentFactory} and store it in the
|
||||
* {@link ComponentFactoryResolver ComponentFactoryResolver}.
|
||||
*/
|
||||
precompile: Array<Type|any[]>;
|
||||
entryComponents: Array<Type|any[]>;
|
||||
|
||||
constructor({providers, declarations, imports, exports, precompile}: {
|
||||
constructor({providers, declarations, imports, exports, entryComponents}: {
|
||||
providers?: any[],
|
||||
declarations?: Array<Type|any[]>,
|
||||
imports?: Array<Type|any[]>,
|
||||
exports?: Array<Type|any[]>,
|
||||
precompile?: Array<Type|any[]>
|
||||
entryComponents?: Array<Type|any[]>
|
||||
} = {}) {
|
||||
super();
|
||||
this._providers = providers;
|
||||
this.declarations = declarations;
|
||||
this.imports = imports;
|
||||
this.exports = exports;
|
||||
this.precompile = precompile;
|
||||
this.entryComponents = entryComponents;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import {AsyncTestCompleter, beforeEach, ddescribe, xdescribe, describe, expect, iit, inject, beforeEachProviders, it, xit,} from '@angular/core/testing/testing_internal';
|
||||
import {TestComponentBuilder, configureModule} from '@angular/core/testing';
|
||||
import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_PRECOMPILE, ViewMetadata} from '@angular/core';
|
||||
import {Component, ComponentFactoryResolver, NoComponentFactoryError, forwardRef, ANALYZE_FOR_ENTRY_COMPONENTS, ViewMetadata} from '@angular/core';
|
||||
import {stringify} from '../../src/facade/lang';
|
||||
|
||||
export function main() {
|
||||
|
@ -17,7 +17,7 @@ export function main() {
|
|||
}
|
||||
|
||||
function declareTests({useJit}: {useJit: boolean}) {
|
||||
describe('@Component.precompile', function() {
|
||||
describe('@Component.entryComponents', function() {
|
||||
beforeEach(() => { configureModule({declarations: [MainComp, ChildComp, NestedChildComp]}); });
|
||||
|
||||
it('should error if the component was not declared nor imported by the module',
|
||||
|
@ -27,13 +27,13 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
class ChildComp {
|
||||
}
|
||||
|
||||
@Component({template: 'comp', precompile: [ChildComp]})
|
||||
@Component({template: 'comp', entryComponents: [ChildComp]})
|
||||
class SomeComp {
|
||||
}
|
||||
|
||||
expect(() => tcb.createSync(SomeComp))
|
||||
.toThrowError(
|
||||
`Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "precompile" but it was neither declared nor imported into the module!`);
|
||||
`Component ${stringify(SomeComp)} in NgModule DynamicTestModule uses ${stringify(ChildComp)} via "entryComponents" but it was neither declared nor imported into the module!`);
|
||||
}));
|
||||
|
||||
|
||||
|
@ -47,10 +47,10 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
}));
|
||||
|
||||
|
||||
it('should resolve ComponentFactories via ANALYZE_FOR_PRECOMPILE',
|
||||
it('should resolve ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS',
|
||||
inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
|
||||
let compFixture = tcb.createSync(CompWithAnalyzePrecompileProvider);
|
||||
let mainComp: CompWithAnalyzePrecompileProvider = compFixture.componentInstance;
|
||||
let compFixture = tcb.createSync(CompWithAnalyzeEntryComponentsProvider);
|
||||
let mainComp: CompWithAnalyzeEntryComponentsProvider = compFixture.componentInstance;
|
||||
let cfr: ComponentFactoryResolver =
|
||||
compFixture.componentRef.injector.get(ComponentFactoryResolver);
|
||||
expect(cfr.resolveComponentFactory(ChildComp).componentType).toBe(ChildComp);
|
||||
|
@ -97,14 +97,14 @@ class NestedChildComp {
|
|||
constructor(public cfr: ComponentFactoryResolver) {}
|
||||
}
|
||||
|
||||
@Component({selector: 'child', precompile: [NestedChildComp], template: ''})
|
||||
@Component({selector: 'child', entryComponents: [NestedChildComp], template: ''})
|
||||
class ChildComp {
|
||||
constructor(public cfr: ComponentFactoryResolver) {}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'main',
|
||||
precompile: [ChildComp],
|
||||
entryComponents: [ChildComp],
|
||||
template: '',
|
||||
})
|
||||
class MainComp {
|
||||
|
@ -115,7 +115,7 @@ class MainComp {
|
|||
selector: 'comp-with-analyze',
|
||||
template: '',
|
||||
providers: [{
|
||||
provide: ANALYZE_FOR_PRECOMPILE,
|
||||
provide: ANALYZE_FOR_ENTRY_COMPONENTS,
|
||||
multi: true,
|
||||
useValue: [
|
||||
{a: 'b', component: ChildComp},
|
||||
|
@ -123,5 +123,5 @@ class MainComp {
|
|||
]
|
||||
}]
|
||||
})
|
||||
class CompWithAnalyzePrecompileProvider {
|
||||
class CompWithAnalyzeEntryComponentsProvider {
|
||||
}
|
|
@ -9,7 +9,7 @@
|
|||
import {LowerCasePipe, NgIf} from '@angular/common';
|
||||
import {CompilerConfig, NgModuleResolver, ViewResolver} from '@angular/compiler';
|
||||
import {MockNgModuleResolver, MockViewResolver} from '@angular/compiler/testing';
|
||||
import {ANALYZE_FOR_PRECOMPILE, Compiler, Component, ComponentFactoryResolver, ComponentRef, ComponentResolver, DebugElement, Directive, Host, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleMetadata, NgModuleRef, OpaqueToken, Optional, Pipe, Provider, ReflectiveInjector, SelfMetadata, SkipSelf, SkipSelfMetadata, ViewMetadata, forwardRef, getDebugNode, provide} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, Compiler, Component, ComponentFactoryResolver, ComponentRef, ComponentResolver, DebugElement, Directive, Host, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleMetadata, NgModuleRef, OpaqueToken, Optional, Pipe, Provider, ReflectiveInjector, SelfMetadata, SkipSelf, SkipSelfMetadata, ViewMetadata, forwardRef, getDebugNode, provide} from '@angular/core';
|
||||
import {Console} from '@angular/core/src/console';
|
||||
import {ComponentFixture, configureCompiler} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
|
@ -164,14 +164,14 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
`Can't export pipe ${stringify(SomePipe)} from ${stringify(SomeModule)} as it was neither declared nor imported!`);
|
||||
});
|
||||
|
||||
it('should error when precompiling a component that was neither declared nor imported', () => {
|
||||
@NgModule({precompile: [SomeComp]})
|
||||
it('should error when using an entryComponent that was neither declared nor imported', () => {
|
||||
@NgModule({entryComponents: [SomeComp]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
expect(() => createModule(SomeModule))
|
||||
.toThrowError(
|
||||
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "precompile" but it was neither declared nor imported!`);
|
||||
`NgModule ${stringify(SomeModule)} uses ${stringify(SomeComp)} via "entryComponents" but it was neither declared nor imported!`);
|
||||
});
|
||||
|
||||
it('should error if a directive is declared in more than 1 module', () => {
|
||||
|
@ -238,9 +238,9 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
|
||||
});
|
||||
|
||||
describe('precompile', function() {
|
||||
it('should precompile ComponentFactories in root modules', () => {
|
||||
@NgModule({declarations: [SomeComp], precompile: [SomeComp]})
|
||||
describe('entryComponents', function() {
|
||||
it('should entryComponents ComponentFactories in root modules', () => {
|
||||
@NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
@ -253,11 +253,11 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
.toBe(SomeComp);
|
||||
});
|
||||
|
||||
it('should precompile ComponentFactories via ANALYZE_FOR_PRECOMPILE', () => {
|
||||
it('should entryComponents ComponentFactories via ANALYZE_FOR_ENTRY_COMPONENTS', () => {
|
||||
@NgModule({
|
||||
declarations: [SomeComp],
|
||||
providers: [{
|
||||
provide: ANALYZE_FOR_PRECOMPILE,
|
||||
provide: ANALYZE_FOR_ENTRY_COMPONENTS,
|
||||
multi: true,
|
||||
useValue: [{a: 'b', component: SomeComp}]
|
||||
}]
|
||||
|
@ -274,8 +274,8 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
.toBe(SomeComp);
|
||||
});
|
||||
|
||||
it('should precompile ComponentFactories in imported modules', () => {
|
||||
@NgModule({declarations: [SomeComp], precompile: [SomeComp]})
|
||||
it('should entryComponents ComponentFactories in imported modules', () => {
|
||||
@NgModule({declarations: [SomeComp], entryComponents: [SomeComp]})
|
||||
class SomeImportedModule {
|
||||
}
|
||||
|
||||
|
@ -292,12 +292,12 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
.toBe(SomeComp);
|
||||
});
|
||||
|
||||
it('should precompile ComponentFactories if the component was imported', () => {
|
||||
it('should entryComponents ComponentFactories if the component was imported', () => {
|
||||
@NgModule({declarations: [SomeComp], exports: [SomeComp]})
|
||||
class SomeImportedModule {
|
||||
}
|
||||
|
||||
@NgModule({imports: [SomeImportedModule], precompile: [SomeComp]})
|
||||
@NgModule({imports: [SomeImportedModule], entryComponents: [SomeComp]})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
|
@ -317,7 +317,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
it('should be supported in root modules', () => {
|
||||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -331,7 +331,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
it('should be supported in imported modules', () => {
|
||||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe, SomeDirective, SomePipe],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeImportedModule {
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
ParentCompUsingModuleDirectiveAndPipe, CompUsingModuleDirectiveAndPipe, SomeDirective,
|
||||
SomePipe
|
||||
],
|
||||
precompile: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -383,7 +383,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
|
||||
@NgModule({
|
||||
declarations: [ParentCompUsingModuleDirectiveAndPipe],
|
||||
precompile: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -415,7 +415,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [ParentCompUsingModuleDirectiveAndPipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [ParentCompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -437,7 +437,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -484,7 +484,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
@ -524,7 +524,7 @@ function declareTests({useJit}: {useJit: boolean}) {
|
|||
@NgModule({
|
||||
declarations: [CompUsingModuleDirectiveAndPipe, SomePipe],
|
||||
imports: [SomeImportedModule],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ export class TestBed implements Injector {
|
|||
private _providers: Array<Type|Provider|any[]|any> = [];
|
||||
private _declarations: Array<Type|any[]|any> = [];
|
||||
private _imports: Array<Type|any[]|any> = [];
|
||||
private _precompile: Array<Type|any[]|any> = [];
|
||||
private _entryComponents: Array<Type|any[]|any> = [];
|
||||
|
||||
reset() {
|
||||
this._compiler = null;
|
||||
|
@ -40,7 +40,7 @@ export class TestBed implements Injector {
|
|||
this._providers = [];
|
||||
this._declarations = [];
|
||||
this._imports = [];
|
||||
this._precompile = [];
|
||||
this._entryComponents = [];
|
||||
this._instantiated = false;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,8 @@ export class TestBed implements Injector {
|
|||
}
|
||||
|
||||
configureModule(
|
||||
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}) {
|
||||
moduleDef:
|
||||
{providers?: any[], declarations?: any[], imports?: any[], entryComponents?: any[]}) {
|
||||
if (this._instantiated) {
|
||||
throw new BaseException('Cannot add configuration after test injector is instantiated');
|
||||
}
|
||||
|
@ -69,16 +70,16 @@ export class TestBed implements Injector {
|
|||
if (moduleDef.imports) {
|
||||
this._imports = ListWrapper.concat(this._imports, moduleDef.imports);
|
||||
}
|
||||
if (moduleDef.precompile) {
|
||||
this._precompile = ListWrapper.concat(this._precompile, moduleDef.precompile);
|
||||
if (moduleDef.entryComponents) {
|
||||
this._entryComponents = ListWrapper.concat(this._entryComponents, moduleDef.entryComponents);
|
||||
}
|
||||
}
|
||||
|
||||
createModuleFactory(): Promise<NgModuleFactory<any>> {
|
||||
if (this._instantiated) {
|
||||
throw new BaseException(
|
||||
'Cannot run precompilation when the test NgModule has already been instantiated. ' +
|
||||
'Make sure you are not using `inject` before `doAsyncPrecompilation`.');
|
||||
'Cannot compile entryComponents when the test NgModule has already been instantiated. ' +
|
||||
'Make sure you are not using `inject` before `doAsyncEntryPointCompilation`.');
|
||||
}
|
||||
|
||||
if (this._ngModuleFactory) {
|
||||
|
@ -122,13 +123,13 @@ export class TestBed implements Injector {
|
|||
const providers = this._providers.concat([{provide: TestBed, useValue: this}]);
|
||||
const declarations = this._declarations;
|
||||
const imports = [this.ngModule, this._imports];
|
||||
const precompile = this._precompile;
|
||||
const entryComponents = this._entryComponents;
|
||||
|
||||
@NgModule({
|
||||
providers: providers,
|
||||
declarations: declarations,
|
||||
imports: imports,
|
||||
precompile: precompile
|
||||
entryComponents: entryComponents
|
||||
})
|
||||
class DynamicTestModule {
|
||||
}
|
||||
|
@ -258,13 +259,13 @@ export function resetTestEnvironment() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Run asynchronous precompilation for the test's NgModule. It is necessary to call this function
|
||||
* if your test is using an NgModule which has precompiled components that require an asynchronous
|
||||
* call, such as an XHR. Should be called once before the test case.
|
||||
* Compile entryComponents with a `templateUrl` for the test's NgModule.
|
||||
* It is necessary to call this function
|
||||
* as fetching urls is asynchronous.
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
export function doAsyncPrecompilation(): Promise<any> {
|
||||
export function doAsyncEntryPointCompilation(): Promise<any> {
|
||||
let testBed = getTestBed();
|
||||
return testBed.createModuleFactory();
|
||||
}
|
||||
|
@ -312,8 +313,8 @@ export function inject(tokens: any[], fn: Function): () => any {
|
|||
} catch (e) {
|
||||
if (e instanceof ComponentStillLoadingError) {
|
||||
throw new Error(
|
||||
`This test module precompiles the component ${stringify(e.compType)} which is using a "templateUrl", but precompilation was never done. ` +
|
||||
`Please call "doAsyncPrecompilation" before "inject".`);
|
||||
`This test module uses the entryComponents ${stringify(e.compType)} which is using a "templateUrl", but they were never compiled. ` +
|
||||
`Please call "doAsyncEntryPointCompilation" before "inject".`);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
|
@ -327,9 +328,12 @@ export function inject(tokens: any[], fn: Function): () => any {
|
|||
* @experimental
|
||||
*/
|
||||
export class InjectSetupWrapper {
|
||||
constructor(
|
||||
private _moduleDef:
|
||||
() => {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}) {}
|
||||
constructor(private _moduleDef: () => {
|
||||
providers?: any[],
|
||||
declarations?: any[],
|
||||
imports?: any[],
|
||||
entryComponents?: any[]
|
||||
}) {}
|
||||
|
||||
private _addModule() {
|
||||
var moduleDef = this._moduleDef();
|
||||
|
@ -360,7 +364,7 @@ export function withModule(moduleDef: () => {
|
|||
providers?: any[],
|
||||
declarations?: any[],
|
||||
imports?: any[],
|
||||
precompile?: any[]
|
||||
entryComponents?: any[]
|
||||
}) {
|
||||
return new InjectSetupWrapper(moduleDef);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ export function addProviders(providers: Array<any>): void {
|
|||
* @stable
|
||||
*/
|
||||
export function configureModule(
|
||||
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], precompile?: any[]}):
|
||||
moduleDef: {providers?: any[], declarations?: any[], imports?: any[], entryComponents?: any[]}):
|
||||
void {
|
||||
if (!moduleDef) return;
|
||||
try {
|
||||
|
|
|
@ -106,7 +106,7 @@ export const browserDynamicPlatform = createPlatformFactory(
|
|||
* ## API (version 2)
|
||||
* - `appComponentType`: The root component which should act as the application. This is
|
||||
* a reference to a `Type` which is annotated with `@Component(...)`.
|
||||
* - `providers`, `declarations`, `imports`, `precompile`: Defines the properties
|
||||
* - `providers`, `declarations`, `imports`, `entryComponents`: Defines the properties
|
||||
* of the dynamically created module that is used to bootstrap the module.
|
||||
* - to configure the compiler, use the `compilerOptions` parameter.
|
||||
*
|
||||
|
@ -121,11 +121,11 @@ export function bootstrap<C>(
|
|||
customProviders?: Array<any /*Type | Provider | any[]*/>): Promise<ComponentRef<C>>;
|
||||
export function bootstrap<C>(
|
||||
appComponentType: ConcreteType<C>,
|
||||
{providers, imports, declarations, precompile, compilerOptions}?: {
|
||||
{providers, imports, declarations, entryComponents, compilerOptions}?: {
|
||||
providers?: Array<any /*Type | Provider | any[]*/>,
|
||||
declarations?: any[],
|
||||
imports?: any[],
|
||||
precompile?: any[],
|
||||
entryComponents?: any[],
|
||||
compilerOptions?: CompilerOptions
|
||||
}): Promise<ComponentRef<C>>;
|
||||
export function bootstrap<C>(
|
||||
|
@ -134,14 +134,14 @@ export function bootstrap<C>(
|
|||
providers: Array<any /*Type | Provider | any[]*/>,
|
||||
declarations?: any[],
|
||||
imports: any[],
|
||||
precompile: any[],
|
||||
entryComponents: any[],
|
||||
compilerOptions: CompilerOptions
|
||||
}): Promise<ComponentRef<C>> {
|
||||
let compilerOptions: CompilerOptions;
|
||||
let providers: any[] = [];
|
||||
let declarations: any[] = [];
|
||||
let imports: any[] = [];
|
||||
let precompile: any[] = [];
|
||||
let entryComponents: any[] = [];
|
||||
let deprecationMessages: string[] = [];
|
||||
if (customProvidersOrDynamicModule instanceof Array) {
|
||||
providers = customProvidersOrDynamicModule;
|
||||
|
@ -153,7 +153,7 @@ export function bootstrap<C>(
|
|||
providers = normalizeArray(customProvidersOrDynamicModule.providers);
|
||||
declarations = normalizeArray(customProvidersOrDynamicModule.declarations);
|
||||
imports = normalizeArray(customProvidersOrDynamicModule.imports);
|
||||
precompile = normalizeArray(customProvidersOrDynamicModule.precompile);
|
||||
entryComponents = normalizeArray(customProvidersOrDynamicModule.entryComponents);
|
||||
compilerOptions = customProvidersOrDynamicModule.compilerOptions;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ export function bootstrap<C>(
|
|||
providers: providers,
|
||||
declarations: declarations.concat([appComponentType]),
|
||||
imports: [BrowserModule, imports],
|
||||
precompile: precompile.concat([appComponentType])
|
||||
entryComponents: entryComponents.concat([appComponentType])
|
||||
})
|
||||
class DynamicModule {
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ export function bootstrapWorkerApp<T>(
|
|||
providers: customProviders,
|
||||
declarations: declarations,
|
||||
imports: [WorkerAppModule],
|
||||
precompile: [appComponentType]
|
||||
entryComponents: [appComponentType]
|
||||
})
|
||||
class DynamicModule {
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {NgIf} from '@angular/common';
|
||||
import {CompilerConfig, XHR} from '@angular/compiler';
|
||||
import {Component, ComponentFactoryResolver, Directive, Injectable, Input, NgModule, Pipe, ViewMetadata, provide} from '@angular/core';
|
||||
import {TestComponentBuilder, addProviders, async, configureCompiler, configureModule, doAsyncPrecompilation, fakeAsync, inject, tick, withModule, withProviders} from '@angular/core/testing';
|
||||
import {TestComponentBuilder, addProviders, async, configureCompiler, configureModule, doAsyncEntryPointCompilation, fakeAsync, inject, tick, withModule, withProviders} from '@angular/core/testing';
|
||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||
|
||||
import {stringify} from '../../http/src/facade/lang';
|
||||
|
@ -235,7 +235,7 @@ export function main() {
|
|||
providers: [FancyService],
|
||||
imports: [SomeLibModule],
|
||||
declarations: [SomeDirective, SomePipe, CompUsingModuleDirectiveAndPipe],
|
||||
precompile: [CompUsingModuleDirectiveAndPipe]
|
||||
entryComponents: [CompUsingModuleDirectiveAndPipe]
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -260,7 +260,7 @@ export function main() {
|
|||
expect(libModule).toBeAnInstanceOf(SomeLibModule);
|
||||
}));
|
||||
|
||||
it('should use set up precompile components',
|
||||
it('should use set up entryComponents components',
|
||||
inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => {
|
||||
expect(resolver.resolveComponentFactory(CompUsingModuleDirectiveAndPipe).componentType)
|
||||
.toBe(CompUsingModuleDirectiveAndPipe);
|
||||
|
@ -288,7 +288,7 @@ export function main() {
|
|||
expect(libModule).toBeAnInstanceOf(SomeLibModule);
|
||||
}));
|
||||
|
||||
it('should use set up precompile components',
|
||||
it('should use set up entryComponents components',
|
||||
withModule(() => moduleConfig)
|
||||
.inject([ComponentFactoryResolver], (resolver: ComponentFactoryResolver) => {
|
||||
expect(
|
||||
|
@ -297,13 +297,14 @@ export function main() {
|
|||
}));
|
||||
});
|
||||
|
||||
describe('precompile components with template url', () => {
|
||||
describe('entryComponents components with template url', () => {
|
||||
beforeEach(async(() => {
|
||||
configureModule({declarations: [CompWithUrlTemplate], precompile: [CompWithUrlTemplate]});
|
||||
doAsyncPrecompilation();
|
||||
configureModule(
|
||||
{declarations: [CompWithUrlTemplate], entryComponents: [CompWithUrlTemplate]});
|
||||
doAsyncEntryPointCompilation();
|
||||
}));
|
||||
|
||||
it('should allow to createSync components with templateUrl after async precompilation',
|
||||
it('should allow to createSync components with templateUrl after explicit async compilation',
|
||||
inject([TestComponentBuilder], (builder: TestComponentBuilder) => {
|
||||
let fixture = builder.createSync(CompWithUrlTemplate);
|
||||
expect(fixture.nativeElement).toHaveText('from external template\n');
|
||||
|
@ -434,14 +435,14 @@ export function main() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('precompile', () => {
|
||||
describe('entryComponents', () => {
|
||||
let xhrGet: jasmine.Spy;
|
||||
beforeEach(() => {
|
||||
xhrGet = jasmine.createSpy('xhrGet').and.returnValue(Promise.resolve('Hello world!'));
|
||||
configureCompiler({providers: [{provide: XHR, useValue: {get: xhrGet}}]});
|
||||
});
|
||||
|
||||
it('should report an error for precompile components with templateUrl which never call doAsyncPrecompile',
|
||||
it('should report an error for entryComponents components with templateUrl which never call doAsyncEntryComponents',
|
||||
() => {
|
||||
var itPromise = patchJasmineIt();
|
||||
|
||||
|
@ -451,7 +452,7 @@ export function main() {
|
|||
withModule(() => {
|
||||
return {
|
||||
declarations: [CompWithUrlTemplate],
|
||||
precompile: [CompWithUrlTemplate]
|
||||
entryComponents: [CompWithUrlTemplate]
|
||||
};
|
||||
})
|
||||
.inject(
|
||||
|
@ -462,8 +463,8 @@ export function main() {
|
|||
.toBe(CompWithUrlTemplate);
|
||||
})))
|
||||
.toThrowError(
|
||||
`This test module precompiles the component ${stringify(CompWithUrlTemplate)} which is using a "templateUrl", but precompilation was never done. ` +
|
||||
'Please call "doAsyncPrecompilation" before "inject".');
|
||||
`This test module uses the entryComponents ${stringify(CompWithUrlTemplate)} which is using a "templateUrl", but they were never compiled. ` +
|
||||
`Please call "doAsyncEntryPointCompilation" before "inject".`);
|
||||
|
||||
restoreJasmineIt();
|
||||
});
|
||||
|
|
|
@ -100,7 +100,7 @@ export function serverBootstrap<T>(
|
|||
providers: customProviders,
|
||||
declarations: declarations,
|
||||
imports: [BrowserModule],
|
||||
precompile: [appComponentType]
|
||||
entryComponents: [appComponentType]
|
||||
})
|
||||
class DynamicModule {
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
|
||||
import {ANALYZE_FOR_PRECOMPILE, APP_INITIALIZER, ApplicationRef, ComponentResolver, Injector, NgModuleFactoryLoader, OpaqueToken, SystemJsNgModuleLoader} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, APP_INITIALIZER, ApplicationRef, ComponentResolver, Injector, NgModuleFactoryLoader, OpaqueToken, SystemJsNgModuleLoader} from '@angular/core';
|
||||
|
||||
import {Routes} from './config';
|
||||
import {Router} from './router';
|
||||
|
@ -88,7 +88,7 @@ export function setupRouterInitializer(injector: Injector) {
|
|||
*/
|
||||
export function provideRouter(routes: Routes, config: ExtraOptions): any[] {
|
||||
return [
|
||||
{provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes},
|
||||
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
|
||||
{provide: ROUTES, useExisting: ROUTER_CONFIG}, {provide: ROUTER_CONFIG, useValue: routes},
|
||||
|
||||
{provide: ROUTER_CONFIGURATION, useValue: config}, Location,
|
||||
|
@ -130,7 +130,7 @@ export function provideRouter(routes: Routes, config: ExtraOptions): any[] {
|
|||
*/
|
||||
export function provideRoutes(routes: Routes): any {
|
||||
return [
|
||||
{provide: ANALYZE_FOR_PRECOMPILE, multi: true, useValue: routes},
|
||||
{provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes},
|
||||
{provide: ROUTES, useValue: routes}
|
||||
];
|
||||
}
|
||||
|
|
|
@ -94,9 +94,9 @@ export class RouterOutlet {
|
|||
if (!(e instanceof NoComponentFactoryError)) throw e;
|
||||
const componentName = component ? component.name : null;
|
||||
console.warn(
|
||||
`'${componentName}' not found in precompile array. To ensure all components referred
|
||||
`'${componentName}' not found in entryComponents array. To ensure all components referred
|
||||
to by the Routes are compiled, you must add '${componentName}' to the
|
||||
'precompile' array of your application component. This will be required in a future
|
||||
'entryComponents' array of your application component. This will be required in a future
|
||||
release of the router.`);
|
||||
factory = snapshot._resolvedComponentFactory;
|
||||
}
|
||||
|
|
|
@ -1326,7 +1326,7 @@ describe('Integration', () => {
|
|||
children: [{path: 'child', component: ChildLazyLoadedComponent}]
|
||||
}])],
|
||||
imports: [RouterModuleWithoutProviders],
|
||||
precompile: [ParentLazyLoadedComponent, ChildLazyLoadedComponent]
|
||||
entryComponents: [ParentLazyLoadedComponent, ChildLazyLoadedComponent]
|
||||
})
|
||||
class LoadedModule {
|
||||
}
|
||||
|
@ -1359,7 +1359,7 @@ describe('Integration', () => {
|
|||
}
|
||||
|
||||
@NgModule({
|
||||
precompile: [LazyLoadedComponent],
|
||||
entryComponents: [LazyLoadedComponent],
|
||||
declarations: [LazyLoadedComponent],
|
||||
imports: [RouterModuleWithoutProviders],
|
||||
providers: [
|
||||
|
@ -1558,7 +1558,7 @@ class RouteCmp {
|
|||
template:
|
||||
`<div *ngIf="show"><a [routerLink]="['./simple']">link</a></div> <router-outlet></router-outlet>`,
|
||||
directives: ROUTER_DIRECTIVES,
|
||||
precompile: [BlankCmp, SimpleCmp]
|
||||
entryComponents: [BlankCmp, SimpleCmp]
|
||||
})
|
||||
class RelativeLinkInIfCmp {
|
||||
show: boolean = false;
|
||||
|
@ -1613,7 +1613,7 @@ class ComponentRecordingRoutePathAndUrl {
|
|||
selector: 'root-cmp',
|
||||
template: `<router-outlet></router-outlet>`,
|
||||
directives: [ROUTER_DIRECTIVES],
|
||||
precompile: [
|
||||
entryComponents: [
|
||||
BlankCmp, SimpleCmp, TeamCmp, UserCmp, StringLinkCmp, DummyLinkCmp, AbsoluteLinkCmp,
|
||||
RelativeLinkCmp, DummyLinkWithParentCmp, LinkWithQueryParamsAndFragment, CollectParamsCmp,
|
||||
QueryParamsAndFragmentCmp, StringLinkButtonCmp, WrapperCmp, LinkInNgIf,
|
||||
|
@ -1628,7 +1628,7 @@ class RootCmp {
|
|||
template:
|
||||
`primary [<router-outlet></router-outlet>] right [<router-outlet name="right"></router-outlet>]`,
|
||||
directives: [ROUTER_DIRECTIVES],
|
||||
precompile: [BlankCmp, SimpleCmp, RouteCmp, UserCmp]
|
||||
entryComponents: [BlankCmp, SimpleCmp, RouteCmp, UserCmp]
|
||||
})
|
||||
class RootCmpWithTwoOutlets {
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ export const ROUTES = [
|
|||
@NgModule({
|
||||
imports: [WorkerAppModule, RouterModule],
|
||||
providers: [provideRoutes(ROUTES), WORKER_APP_LOCATION_PROVIDERS, {provide: LocationStrategy, useClass: HashLocationStrategy}],
|
||||
precompile: [App],
|
||||
entryComponents: [App],
|
||||
declarations: [App, Start, Contact, About]
|
||||
})
|
||||
export class AppModule {
|
||||
|
|
Loading…
Reference in New Issue