refactor(Type): merge Type and ConcreType<?> into Type<?> (#10616)

Closes #9729

BREAKING CHANGE:

`Type` is now `Type<T>` which means that in most cases you have to
use `Type<any>` in place of `Type`.

We don't expect that any user applications use the `Type` type.
This commit is contained in:
Miško Hevery
2016-08-10 18:21:28 -07:00
committed by vikerman
parent 6f4ee6101c
commit b96869afd2
91 changed files with 637 additions and 714 deletions

View File

@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ChangeDetectionStrategy, SchemaMetadata, ViewEncapsulation} from '@angular/core';
import {ChangeDetectionStrategy, SchemaMetadata, Type, ViewEncapsulation} from '@angular/core';
import {LifecycleHooks, reflector} from '../core_private';
import {ListWrapper, StringMapWrapper} from './facade/collection';
import {BaseException, unimplemented} from './facade/exceptions';
import {Type, isBlank, isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';
import {isBlank, isPresent, isStringMap, normalizeBlank, normalizeBool} from './facade/lang';
import {CssSelector} from './selector';
import {getUrlScheme} from './url_resolver';
import {sanitizeIdentifier, splitAtColon} from './util';
@ -308,7 +308,7 @@ export class CompileTypeMetadata extends CompileIdentifierMetadata {
lifecycleHooks: LifecycleHooks[];
constructor({runtime, name, moduleUrl, prefix, isHost, value, diDeps, lifecycleHooks}: {
runtime?: Type,
runtime?: Type<any>,
name?: string,
moduleUrl?: string,
prefix?: string,
@ -685,8 +685,8 @@ export class CompileNgModuleMetadata implements CompileMetadataWithIdentifier {
}
export class TransitiveCompileNgModuleMetadata {
directivesSet = new Set<Type>();
pipesSet = new Set<Type>();
directivesSet = new Set<Type<any>>();
pipesSet = new Set<Type<any>>();
constructor(
public modules: CompileNgModuleMetadata[], public providers: CompileProviderMetadata[],
public entryComponents: CompileTypeMetadata[], public directives: CompileDirectiveMetadata[],

View File

@ -52,7 +52,7 @@ const _NO_XHR: XHR = {
* A set of providers that provide `RuntimeCompiler` and its dependencies to use for
* template compilation.
*/
export const COMPILER_PROVIDERS: Array<any|Type|{[k: string]: any}|any[]> = [
export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> = [
{provide: Reflector, useValue: reflector},
{provide: ReflectorReader, useExisting: Reflector},
{provide: XHR, useValue: _NO_XHR},
@ -79,8 +79,11 @@ export const COMPILER_PROVIDERS: Array<any|Type|{[k: string]: any}|any[]> = [
];
export function analyzeAppProvidersForDeprecatedConfiguration(appProviders: any[] = []):
{compilerOptions: CompilerOptions, moduleDeclarations: Type[], deprecationMessages: string[]} {
export function analyzeAppProvidersForDeprecatedConfiguration(appProviders: any[] = []): {
compilerOptions: CompilerOptions,
moduleDeclarations: Type<any>[],
deprecationMessages: string[]
} {
let platformDirectives: any[] = [];
let platformPipes: any[] = [];

View File

@ -6,12 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, resolveForwardRef} from '@angular/core';
import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, Type, resolveForwardRef} from '@angular/core';
import {ReflectorReader, reflector} from '../core_private';
import {StringMapWrapper} from './facade/collection';
import {Type, isPresent, stringify} from './facade/lang';
import {BaseException} from './facade/exceptions';
import {isPresent, stringify} from './facade/lang';
import {splitAtColon} from './util';
function _isDirectiveMetadata(type: any): type is DirectiveMetadata {
@ -32,7 +31,7 @@ export class DirectiveResolver {
/**
* Return {@link DirectiveMetadata} for a given `Type`.
*/
resolve(type: Type, throwIfNotFound = true): DirectiveMetadata {
resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata {
var typeMetadata = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(typeMetadata)) {
var metadata = typeMetadata.find(_isDirectiveMetadata);
@ -49,7 +48,7 @@ export class DirectiveResolver {
private _mergeWithPropertyMetadata(
dm: DirectiveMetadata, propertyMetadata: {[key: string]: any[]},
directiveType: Type): DirectiveMetadata {
directiveType: Type<any>): DirectiveMetadata {
var inputs: string[] = [];
var outputs: string[] = [];
var host: {[key: string]: string} = {};
@ -90,7 +89,7 @@ export class DirectiveResolver {
private _merge(
dm: DirectiveMetadata, inputs: string[], outputs: string[], host: {[key: string]: string},
queries: {[key: string]: any}, directiveType: Type): DirectiveMetadata {
queries: {[key: string]: any}, directiveType: Type<any>): DirectiveMetadata {
let mergedInputs: string[];
if (isPresent(dm.inputs)) {

View File

@ -6,14 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from '@angular/core';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit, Type} from '@angular/core';
import {LifecycleHooks, reflector} from '../core_private';
import {MapWrapper} from './facade/collection';
import {Type} from './facade/lang';
const LIFECYCLE_INTERFACES: Map<any, Type> = MapWrapper.createFromPairs([
const LIFECYCLE_INTERFACES: Map<any, Type<any>> = MapWrapper.createFromPairs([
[LifecycleHooks.OnInit, OnInit],
[LifecycleHooks.OnDestroy, OnDestroy],
[LifecycleHooks.DoCheck, DoCheck],

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, BaseException, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, Inject, InjectMetadata, Injectable, ModuleWithProviders, NgModule, NgModuleMetadata, Optional, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, ViewMetadata, ViewQueryMetadata, resolveForwardRef} from '@angular/core';
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, AttributeMetadata, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, ViewQueryMetadata, resolveForwardRef} from '@angular/core';
import {Console, LIFECYCLE_HOOKS_VALUES, ReflectorReader, createProvider, isProviderLiteral, reflector} from '../core_private';
import {StringMapWrapper} from '../src/facade/collection';
@ -15,7 +15,8 @@ import {assertArrayOfStrings, assertInterpolationSymbols} from './assertions';
import * as cpl from './compile_metadata';
import {CompilerConfig} from './config';
import {DirectiveResolver} from './directive_resolver';
import {Type, isArray, isBlank, isPresent, isString, stringify} from './facade/lang';
import {BaseException} from './facade/exceptions';
import {isArray, isBlank, isPresent, isString, stringify} from './facade/lang';
import {Identifiers, identifierToken} from './identifiers';
import {hasLifecycleHook} from './lifecycle_reflector';
import {NgModuleResolver} from './ng_module_resolver';
@ -26,10 +27,10 @@ import {MODULE_SUFFIX, ValueTransformer, sanitizeIdentifier, visitValue} from '.
@Injectable()
export class CompileMetadataResolver {
private _directiveCache = new Map<Type, cpl.CompileDirectiveMetadata>();
private _pipeCache = new Map<Type, cpl.CompilePipeMetadata>();
private _ngModuleCache = new Map<Type, cpl.CompileNgModuleMetadata>();
private _ngModuleOfTypes = new Map<Type, Type>();
private _directiveCache = new Map<Type<any>, cpl.CompileDirectiveMetadata>();
private _pipeCache = new Map<Type<any>, cpl.CompilePipeMetadata>();
private _ngModuleCache = new Map<Type<any>, cpl.CompileNgModuleMetadata>();
private _ngModuleOfTypes = new Map<Type<any>, Type<any>>();
private _anonymousTypes = new Map<Object, number>();
private _anonymousTypeIndex = 0;
@ -53,7 +54,7 @@ export class CompileMetadataResolver {
return sanitizeIdentifier(identifier);
}
clearCacheFor(type: Type) {
clearCacheFor(type: Type<any>) {
this._directiveCache.delete(type);
this._pipeCache.delete(type);
this._ngModuleOfTypes.delete(type);
@ -110,7 +111,8 @@ export class CompileMetadataResolver {
return null;
}
getDirectiveMetadata(directiveType: Type, throwIfNotFound = true): cpl.CompileDirectiveMetadata {
getDirectiveMetadata(directiveType: Type<any>, throwIfNotFound = true):
cpl.CompileDirectiveMetadata {
directiveType = resolveForwardRef(directiveType);
var meta = this._directiveCache.get(directiveType);
if (isBlank(meta)) {
@ -241,7 +243,7 @@ export class CompileMetadataResolver {
if (meta.imports) {
flattenArray(meta.imports).forEach((importedType) => {
let importedModuleType: Type;
let importedModuleType: Type<any>;
if (isValidType(importedType)) {
importedModuleType = importedType;
} else if (importedType && importedType.ngModule) {
@ -352,7 +354,7 @@ export class CompileMetadataResolver {
return compileMeta;
}
addComponentToModule(moduleType: Type, compType: Type) {
addComponentToModule(moduleType: Type<any>, compType: Type<any>) {
const moduleMeta = this.getNgModuleMetadata(moduleType);
// Collect @Component.directives/pipes/entryComponents into our declared directives/pipes.
const compMeta = this.getDirectiveMetadata(compType, false);
@ -395,7 +397,7 @@ export class CompileMetadataResolver {
(dirMeta) => { this._getTransitiveViewDirectivesAndPipes(dirMeta, moduleMeta); });
}
private _addTypeToModule(type: Type, moduleType: Type) {
private _addTypeToModule(type: Type<any>, moduleType: Type<any>) {
const oldModule = this._ngModuleOfTypes.get(type);
if (oldModule && oldModule !== moduleType) {
throw new BaseException(
@ -410,13 +412,13 @@ export class CompileMetadataResolver {
if (!compMeta.isComponent) {
return;
}
const addPipe = (pipeType: Type) => {
const addPipe = (pipeType: Type<any>) => {
const pipeMeta = this.getPipeMetadata(pipeType);
this._addPipeToModule(
pipeMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule, moduleMeta.declaredPipes);
};
const addDirective = (dirType: Type) => {
const addDirective = (dirType: Type<any>) => {
const dirMeta = this.getDirectiveMetadata(dirType);
if (this._addDirectiveToModule(
dirMeta, moduleMeta.type.runtime, moduleMeta.transitiveModule,
@ -484,7 +486,7 @@ export class CompileMetadataResolver {
return false;
}
getTypeMetadata(type: Type, moduleUrl: string, dependencies: any[] = null):
getTypeMetadata(type: Type<any>, moduleUrl: string, dependencies: any[] = null):
cpl.CompileTypeMetadata {
type = resolveForwardRef(type);
return new cpl.CompileTypeMetadata({
@ -507,7 +509,7 @@ export class CompileMetadataResolver {
});
}
getPipeMetadata(pipeType: Type, throwIfNotFound = true): cpl.CompilePipeMetadata {
getPipeMetadata(pipeType: Type<any>, throwIfNotFound = true): cpl.CompilePipeMetadata {
pipeType = resolveForwardRef(pipeType);
var meta = this._pipeCache.get(pipeType);
if (isBlank(meta)) {
@ -525,7 +527,7 @@ export class CompileMetadataResolver {
return meta;
}
getDependenciesMetadata(typeOrFunc: Type|Function, dependencies: any[]):
getDependenciesMetadata(typeOrFunc: Type<any>|Function, dependencies: any[]):
cpl.CompileDiDependencyMetadata[] {
let hasUnknownDeps = false;
let params = isPresent(dependencies) ? dependencies : this._reflector.parameters(typeOrFunc);
@ -694,7 +696,7 @@ export class CompileMetadataResolver {
getQueriesMetadata(
queries: {[key: string]: QueryMetadata}, isViewQuery: boolean,
directiveType: Type): cpl.CompileQueryMetadata[] {
directiveType: Type<any>): cpl.CompileQueryMetadata[] {
var res: cpl.CompileQueryMetadata[] = [];
StringMapWrapper.forEach(queries, (query: QueryMetadata, propertyName: string) => {
if (query.isViewQuery === isViewQuery) {
@ -704,7 +706,7 @@ export class CompileMetadataResolver {
return res;
}
getQueryMetadata(q: QueryMetadata, propertyName: string, typeOrFunc: Type|Function):
getQueryMetadata(q: QueryMetadata, propertyName: string, typeOrFunc: Type<any>|Function):
cpl.CompileQueryMetadata {
var selectors: cpl.CompileTokenMetadata[];
if (q.isVarBindingQuery) {
@ -729,7 +731,7 @@ export class CompileMetadataResolver {
function getTransitiveModules(
modules: cpl.CompileNgModuleMetadata[], includeImports: boolean,
targetModules: cpl.CompileNgModuleMetadata[] = [],
visitedModules = new Set<Type>()): cpl.CompileNgModuleMetadata[] {
visitedModules = new Set<Type<any>>()): cpl.CompileNgModuleMetadata[] {
modules.forEach((ngModule) => {
if (!visitedModules.has(ngModule.type.runtime)) {
visitedModules.add(ngModule.type.runtime);
@ -761,7 +763,7 @@ function flattenArray(tree: any[], out: Array<any> = []): Array<any> {
}
function verifyNonBlankProviders(
directiveType: Type, providersTree: any[], providersType: string): any[] {
directiveType: Type<any>, providersTree: any[], providersType: string): any[] {
var flat: any[] = [];
var errMsg: string;

View File

@ -6,11 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Injectable, NgModuleMetadata} from '@angular/core';
import {Injectable, NgModuleMetadata, Type} from '@angular/core';
import {ReflectorReader, reflector} from '../core_private';
import {Type, isPresent, stringify} from './facade/lang';
import {BaseException} from '../src/facade/exceptions';
import {isPresent, stringify} from './facade/lang';
function _isNgModuleMetadata(obj: any): obj is NgModuleMetadata {
return obj instanceof NgModuleMetadata;
@ -23,7 +23,7 @@ function _isNgModuleMetadata(obj: any): obj is NgModuleMetadata {
export class NgModuleResolver {
constructor(private _reflector: ReflectorReader = reflector) {}
resolve(type: Type, throwIfNotFound = true): NgModuleMetadata {
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
const ngModuleMeta: NgModuleMetadata =
this._reflector.annotations(type).find(_isNgModuleMetadata);

View File

@ -6,11 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Injectable, PipeMetadata, resolveForwardRef} from '@angular/core';
import {Injectable, PipeMetadata, Type, resolveForwardRef} from '@angular/core';
import {ReflectorReader, reflector} from '../core_private';
import {Type, isPresent, stringify} from './facade/lang';
import {BaseException} from './facade/exceptions';
import {isPresent, stringify} from './facade/lang';
function _isPipeMetadata(type: any): boolean {
return type instanceof PipeMetadata;
@ -30,7 +31,7 @@ export class PipeResolver {
/**
* Return {@link PipeMetadata} for a given `Type`.
*/
resolve(type: Type, throwIfNotFound = true): PipeMetadata {
resolve(type: Type<any>, throwIfNotFound = true): PipeMetadata {
var metas = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(metas)) {
var annotation = metas.find(_isPipeMetadata);

View File

@ -6,14 +6,15 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException, Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModule, NgModuleFactory, NgModuleMetadata, OptionalMetadata, Provider, SchemaMetadata, SkipSelfMetadata} from '@angular/core';
import {Compiler, ComponentFactory, ComponentResolver, ComponentStillLoadingError, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, Provider, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
import {Console} from '../core_private';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, createHostComponentMeta} from './compile_metadata';
import {CompilerConfig} from './config';
import {DirectiveNormalizer} from './directive_normalizer';
import {ConcreteType, Type, isBlank, isString, stringify} from './facade/lang';
import {BaseException} from './facade/exceptions';
import {isBlank, isString, stringify} from './facade/lang';
import {CompileMetadataResolver} from './metadata_resolver';
import {NgModuleCompiler} from './ng_module_compiler';
import * as ir from './output/output_ast';
@ -37,9 +38,9 @@ import {ComponentFactoryDependency, ViewCompiler, ViewFactoryDependency} from '.
*/
@Injectable()
export class RuntimeCompiler implements Compiler {
private _compiledTemplateCache = new Map<Type, CompiledTemplate>();
private _compiledHostTemplateCache = new Map<Type, CompiledTemplate>();
private _compiledNgModuleCache = new Map<Type, NgModuleFactory<any>>();
private _compiledTemplateCache = new Map<Type<any>, CompiledTemplate>();
private _compiledHostTemplateCache = new Map<Type<any>, CompiledTemplate>();
private _compiledNgModuleCache = new Map<Type<any>, NgModuleFactory<any>>();
constructor(
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
@ -50,25 +51,24 @@ export class RuntimeCompiler implements Compiler {
get injector(): Injector { return this._injector; }
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> {
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> {
return this._compileModuleAndComponents(moduleType, true).syncResult;
}
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> {
return this._compileModuleAndComponents(moduleType, false).asyncResult;
}
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
ModuleWithComponentFactories<T> {
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
return this._compileModuleAndAllComponents(moduleType, true).syncResult;
}
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
Promise<ModuleWithComponentFactories<T>> {
return this._compileModuleAndAllComponents(moduleType, false).asyncResult;
}
compileComponentAsync<T>(compType: ConcreteType<T>, ngModule: ConcreteType<any> = null):
compileComponentAsync<T>(compType: Type<T>, ngModule: Type<any> = null):
Promise<ComponentFactory<T>> {
if (!ngModule) {
throw new BaseException(
@ -77,8 +77,7 @@ export class RuntimeCompiler implements Compiler {
return this._compileComponentInModule(compType, false, ngModule).asyncResult;
}
compileComponentSync<T>(compType: ConcreteType<T>, ngModule: ConcreteType<any> = null):
ComponentFactory<T> {
compileComponentSync<T>(compType: Type<T>, ngModule: Type<any> = null): ComponentFactory<T> {
if (!ngModule) {
throw new BaseException(
`Calling compileComponentSync on the root compiler without a module is not allowed! (Compiling component ${stringify(compType)})`);
@ -86,14 +85,14 @@ export class RuntimeCompiler implements Compiler {
return this._compileComponentInModule(compType, true, ngModule).syncResult;
}
private _compileModuleAndComponents<T>(moduleType: ConcreteType<T>, isSync: boolean):
private _compileModuleAndComponents<T>(moduleType: Type<T>, isSync: boolean):
SyncAsyncResult<NgModuleFactory<T>> {
const componentPromise = this._compileComponents(moduleType, isSync);
const ngModuleFactory = this._compileModule(moduleType);
return new SyncAsyncResult(ngModuleFactory, componentPromise.then(() => ngModuleFactory));
}
private _compileModuleAndAllComponents<T>(moduleType: ConcreteType<T>, isSync: boolean):
private _compileModuleAndAllComponents<T>(moduleType: Type<T>, isSync: boolean):
SyncAsyncResult<ModuleWithComponentFactories<T>> {
const componentPromise = this._compileComponents(moduleType, isSync);
const ngModuleFactory = this._compileModule(moduleType);
@ -121,7 +120,7 @@ export class RuntimeCompiler implements Compiler {
return new SyncAsyncResult(syncResult, asyncResult);
}
private _compileModule<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> {
private _compileModule<T>(moduleType: Type<T>): NgModuleFactory<T> {
let ngModuleFactory = this._compiledNgModuleCache.get(moduleType);
if (!ngModuleFactory) {
const moduleMeta = this._metadataResolver.getNgModuleMetadata(moduleType);
@ -156,9 +155,8 @@ export class RuntimeCompiler implements Compiler {
return ngModuleFactory;
}
private _compileComponentInModule<T>(
compType: ConcreteType<T>, isSync: boolean,
moduleType: ConcreteType<any>): SyncAsyncResult<ComponentFactory<T>> {
private _compileComponentInModule<T>(compType: Type<T>, isSync: boolean, moduleType: Type<any>):
SyncAsyncResult<ComponentFactory<T>> {
this._metadataResolver.addComponentToModule(moduleType, compType);
const componentPromise = this._compileComponents(moduleType, isSync);
@ -171,7 +169,7 @@ export class RuntimeCompiler implements Compiler {
/**
* @internal
*/
_compileComponents(mainModule: Type, isSync: boolean): Promise<any> {
_compileComponents(mainModule: Type<any>, isSync: boolean): Promise<any> {
const templates = new Set<CompiledTemplate>();
var loadingPromises: Promise<any>[] = [];
@ -208,7 +206,7 @@ export class RuntimeCompiler implements Compiler {
}
}
clearCacheFor(type: Type) {
clearCacheFor(type: Type<any>) {
this._compiledNgModuleCache.delete(type);
this._metadataResolver.clearCacheFor(type);
this._compiledHostTemplateCache.delete(type);
@ -227,7 +225,7 @@ export class RuntimeCompiler implements Compiler {
this._compiledNgModuleCache.clear();
}
private _createCompiledHostTemplate(compType: Type): CompiledTemplate {
private _createCompiledHostTemplate(compType: Type<any>): CompiledTemplate {
var compiledTemplate = this._compiledHostTemplateCache.get(compType);
if (isBlank(compiledTemplate)) {
var compMeta = this._metadataResolver.getDirectiveMetadata(compType);
@ -350,7 +348,7 @@ class CompiledTemplate {
private _normalizedCompMeta: CompileDirectiveMetadata = null;
isCompiled = false;
isCompiledWithDeps = false;
viewComponentTypes: Type[] = [];
viewComponentTypes: Type<any>[] = [];
viewDirectives: CompileDirectiveMetadata[] = [];
constructor(
@ -414,12 +412,12 @@ class ModuleBoundCompiler implements Compiler, ComponentResolver {
private _warnOnComponentResolver = true;
constructor(
private _delegate: RuntimeCompiler, private _ngModule: ConcreteType<any>,
private _delegate: RuntimeCompiler, private _ngModule: Type<any>,
private _parentComponentResolver: ComponentResolver, private _console: Console) {}
get _injector(): Injector { return this._delegate.injector; }
resolveComponent(component: Type|string): Promise<ComponentFactory<any>> {
resolveComponent(component: Type<any>|string): Promise<ComponentFactory<any>> {
if (isString(component)) {
if (this._parentComponentResolver) {
return this._parentComponentResolver.resolveComponent(component);
@ -432,32 +430,30 @@ class ModuleBoundCompiler implements Compiler, ComponentResolver {
this._console.warn(ComponentResolver.DynamicCompilationDeprecationMsg);
this._warnOnComponentResolver = false;
}
return this.compileComponentAsync(<ConcreteType<any>>component);
return this.compileComponentAsync(<Type<any>>component);
}
compileComponentAsync<T>(compType: ConcreteType<T>, ngModule: ConcreteType<any> = null):
compileComponentAsync<T>(compType: Type<T>, ngModule: Type<any> = null):
Promise<ComponentFactory<T>> {
return this._delegate.compileComponentAsync(compType, ngModule ? ngModule : this._ngModule);
}
compileComponentSync<T>(compType: ConcreteType<T>, ngModule: ConcreteType<any> = null):
ComponentFactory<T> {
compileComponentSync<T>(compType: Type<T>, ngModule: Type<any> = null): ComponentFactory<T> {
return this._delegate.compileComponentSync(compType, ngModule ? ngModule : this._ngModule);
}
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> {
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> {
return this._delegate.compileModuleSync(moduleType);
}
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> {
return this._delegate.compileModuleAsync(moduleType);
}
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
ModuleWithComponentFactories<T> {
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
return this._delegate.compileModuleAndAllComponentsSync(moduleType);
}
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
Promise<ModuleWithComponentFactories<T>> {
return this._delegate.compileModuleAndAllComponentsAsync(moduleType);
}
@ -475,5 +471,5 @@ class ModuleBoundCompiler implements Compiler, ComponentResolver {
/**
* Clears the cache for the given component/ngModule.
*/
clearCacheFor(type: Type) { this._delegate.clearCacheFor(type); }
clearCacheFor(type: Type<any>) { this._delegate.clearCacheFor(type); }
}

View File

@ -8,12 +8,12 @@
import {DirectiveResolver, XHR} from '@angular/compiler';
import {MockDirectiveResolver} from '@angular/compiler/testing';
import {Compiler, Component, ComponentFactory, Injectable, Injector, Input, NgModule, NgModuleFactory, ViewMetadata} from '@angular/core';
import {Compiler, Component, ComponentFactory, Injectable, Injector, Input, NgModule, NgModuleFactory, Type, ViewMetadata} from '@angular/core';
import {ComponentFixture, TestBed, TestComponentBuilder, fakeAsync, tick} from '@angular/core/testing';
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {expect} from '@angular/platform-browser/testing/matchers';
import {ConcreteType, stringify} from '../src/facade/lang';
import {stringify} from '../src/facade/lang';
import {SpyXHR} from './spies';

View File

@ -12,8 +12,7 @@ export * from './testing/directive_resolver_mock';
export * from './testing/ng_module_resolver_mock';
export * from './testing/pipe_resolver_mock';
import {ConcreteType, Type} from './src/facade/lang';
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, PlatformRef, CompilerFactory, ComponentFactory, NgModuleFactory, Injector, NgModuleMetadata, NgModuleMetadataType, ComponentMetadata, ComponentMetadataType, DirectiveMetadata, DirectiveMetadataType, PipeMetadata, PipeMetadataType} from '@angular/core';
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, ComponentFactory, NgModuleFactory, Injector, NgModuleMetadata, NgModuleMetadataType, ComponentMetadata, ComponentMetadataType, DirectiveMetadata, DirectiveMetadataType, PipeMetadata, PipeMetadataType, Type, PlatformRef} from '@angular/core';
import {MetadataOverride} from '@angular/core/testing';
import {TestingCompilerFactory, TestingCompiler} from './core_private_testing';
import {platformCoreDynamic, RuntimeCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from './index';
@ -40,55 +39,51 @@ export class TestingCompilerImpl implements TestingCompiler {
private _compiler: RuntimeCompiler, private _directiveResolver: MockDirectiveResolver,
private _pipeResolver: MockPipeResolver, private _moduleResolver: MockNgModuleResolver) {}
get injector(): Injector { return this._compiler.injector; }
compileComponentAsync<T>(component: ConcreteType<T>, ngModule: Type = null):
compileComponentAsync<T>(component: Type<T>, ngModule: Type<any> = null):
Promise<ComponentFactory<T>> {
return this._compiler.compileComponentAsync(component, <any>ngModule);
}
compileComponentSync<T>(component: ConcreteType<T>, ngModule: Type = null): ComponentFactory<T> {
compileComponentSync<T>(component: Type<T>, ngModule: Type<any> = null): ComponentFactory<T> {
return this._compiler.compileComponentSync(component, <any>ngModule);
}
compileModuleSync<T>(moduleType: ConcreteType<T>): NgModuleFactory<T> {
compileModuleSync<T>(moduleType: Type<T>): NgModuleFactory<T> {
return this._compiler.compileModuleSync(moduleType);
}
compileModuleAsync<T>(moduleType: ConcreteType<T>): Promise<NgModuleFactory<T>> {
compileModuleAsync<T>(moduleType: Type<T>): Promise<NgModuleFactory<T>> {
return this._compiler.compileModuleAsync(moduleType);
}
compileModuleAndAllComponentsSync<T>(moduleType: ConcreteType<T>):
ModuleWithComponentFactories<T> {
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
return this._compiler.compileModuleAndAllComponentsSync(moduleType);
}
compileModuleAndAllComponentsAsync<T>(moduleType: ConcreteType<T>):
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
Promise<ModuleWithComponentFactories<T>> {
return this._compiler.compileModuleAndAllComponentsAsync(moduleType);
}
overrideModule(ngModule: ConcreteType<any>, override: MetadataOverride<NgModuleMetadataType>):
void {
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModuleMetadataType>): void {
const oldMetadata = this._moduleResolver.resolve(ngModule, false);
this._moduleResolver.setNgModule(
ngModule, this._overrider.overrideMetadata(NgModuleMetadata, oldMetadata, override));
}
overrideDirective(
directive: ConcreteType<any>, override: MetadataOverride<DirectiveMetadataType>): void {
overrideDirective(directive: Type<any>, override: MetadataOverride<DirectiveMetadataType>): void {
const oldMetadata = this._directiveResolver.resolve(directive, false);
this._directiveResolver.setDirective(
directive, this._overrider.overrideMetadata(DirectiveMetadata, oldMetadata, override));
}
overrideComponent(
component: ConcreteType<any>, override: MetadataOverride<ComponentMetadataType>): void {
overrideComponent(component: Type<any>, override: MetadataOverride<ComponentMetadataType>): void {
const oldMetadata = this._directiveResolver.resolve(component, false);
this._directiveResolver.setDirective(
component, this._overrider.overrideMetadata(ComponentMetadata, oldMetadata, override));
}
overridePipe(pipe: ConcreteType<any>, override: MetadataOverride<PipeMetadataType>): void {
overridePipe(pipe: Type<any>, override: MetadataOverride<PipeMetadataType>): void {
const oldMetadata = this._pipeResolver.resolve(pipe, false);
this._pipeResolver.setPipe(
pipe, this._overrider.overrideMetadata(PipeMetadata, oldMetadata, override));
}
clearCache(): void { this._compiler.clearCache(); }
clearCacheFor(type: Type) { this._compiler.clearCacheFor(type); }
clearCacheFor(type: Type<any>) { this._compiler.clearCacheFor(type); }
}
/**
@ -96,7 +91,7 @@ export class TestingCompilerImpl implements TestingCompiler {
*
* @experimental
*/
export const platformCoreDynamicTesting =
export const platformCoreDynamicTesting: (extraProviders?: any[]) => PlatformRef =
createPlatformFactory(platformCoreDynamic, 'coreDynamicTesting', [
{
provide: COMPILER_OPTIONS,

View File

@ -6,11 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AnimationEntryMetadata, BaseException, Compiler, ComponentMetadata, DirectiveMetadata, Injectable, Injector, ViewMetadata, resolveForwardRef} from '@angular/core';
import {AnimationEntryMetadata, Compiler, ComponentMetadata, DirectiveMetadata, Injectable, Injector, Type, ViewMetadata, resolveForwardRef} from '@angular/core';
import {DirectiveResolver} from '../src/directive_resolver';
import {Map} from '../src/facade/collection';
import {Type, isArray, isPresent, stringify} from '../src/facade/lang';
import {BaseException} from '../src/facade/exceptions';
import {isArray, isPresent, stringify} from '../src/facade/lang';
@ -20,21 +21,21 @@ import {Type, isArray, isPresent, stringify} from '../src/facade/lang';
*/
@Injectable()
export class MockDirectiveResolver extends DirectiveResolver {
private _directives = new Map<Type, DirectiveMetadata>();
private _providerOverrides = new Map<Type, any[]>();
private _viewProviderOverrides = new Map<Type, any[]>();
private _views = new Map<Type, ViewMetadata>();
private _inlineTemplates = new Map<Type, string>();
private _animations = new Map<Type, AnimationEntryMetadata[]>();
private _directiveOverrides = new Map<Type, Map<Type, Type>>();
private _directives = new Map<Type<any>, DirectiveMetadata>();
private _providerOverrides = new Map<Type<any>, any[]>();
private _viewProviderOverrides = new Map<Type<any>, any[]>();
private _views = new Map<Type<any>, ViewMetadata>();
private _inlineTemplates = new Map<Type<any>, string>();
private _animations = new Map<Type<any>, AnimationEntryMetadata[]>();
private _directiveOverrides = new Map<Type<any>, Map<Type<any>, Type<any>>>();
constructor(private _injector: Injector) { super(); }
private get _compiler(): Compiler { return this._injector.get(Compiler); }
private _clearCacheFor(component: Type) { this._compiler.clearCacheFor(component); }
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
resolve(type: Type, throwIfNotFound = true): DirectiveMetadata {
resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata {
let metadata = this._directives.get(type);
if (!metadata) {
metadata = super.resolve(type, throwIfNotFound);
@ -134,17 +135,17 @@ export class MockDirectiveResolver extends DirectiveResolver {
/**
* Overrides the {@link DirectiveMetadata} for a directive.
*/
setDirective(type: Type, metadata: DirectiveMetadata): void {
setDirective(type: Type<any>, metadata: DirectiveMetadata): void {
this._directives.set(type, metadata);
this._clearCacheFor(type);
}
setProvidersOverride(type: Type, providers: any[]): void {
setProvidersOverride(type: Type<any>, providers: any[]): void {
this._providerOverrides.set(type, providers);
this._clearCacheFor(type);
}
setViewProvidersOverride(type: Type, viewProviders: any[]): void {
setViewProvidersOverride(type: Type<any>, viewProviders: any[]): void {
this._viewProviderOverrides.set(type, viewProviders);
this._clearCacheFor(type);
}
@ -152,19 +153,19 @@ export class MockDirectiveResolver extends DirectiveResolver {
/**
* Overrides the {@link ViewMetadata} for a component.
*/
setView(component: Type, view: ViewMetadata): void {
setView(component: Type<any>, view: ViewMetadata): void {
this._views.set(component, view);
this._clearCacheFor(component);
}
/**
* Overrides the inline template for a component - other configuration remains unchanged.
*/
setInlineTemplate(component: Type, template: string): void {
setInlineTemplate(component: Type<any>, template: string): void {
this._inlineTemplates.set(component, template);
this._clearCacheFor(component);
}
setAnimations(component: Type, animations: AnimationEntryMetadata[]): void {
setAnimations(component: Type<any>, animations: AnimationEntryMetadata[]): void {
this._animations.set(component, animations);
this._clearCacheFor(component);
}
@ -172,11 +173,11 @@ export class MockDirectiveResolver extends DirectiveResolver {
/**
* Overrides a directive from the component {@link ViewMetadata}.
*/
overrideViewDirective(component: Type, from: Type, to: Type): void {
overrideViewDirective(component: Type<any>, from: Type<any>, to: Type<any>): void {
var overrides = this._directiveOverrides.get(component);
if (!overrides) {
overrides = new Map<Type, Type>();
overrides = new Map<Type<any>, Type<any>>();
this._directiveOverrides.set(component, overrides);
}
@ -185,7 +186,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
}
}
function flattenArray(tree: any[], out: Array<Type|any[]>): void {
function flattenArray(tree: any[], out: Array<Type<any>|any[]>): void {
if (!isPresent(tree)) return;
for (var i = 0; i < tree.length; i++) {
var item = resolveForwardRef(tree[i]);

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {BaseException} from '@angular/core';
import {MetadataOverride} from '@angular/core/testing';
import {ConcreteType, stringify} from '../src/facade/lang';
import {BaseException} from '../src/facade/exceptions';
import {stringify} from '../src/facade/lang';
type StringMap = {
[key: string]: any

View File

@ -13,18 +13,18 @@ import {Map} from '../src/facade/collection';
@Injectable()
export class MockNgModuleResolver extends NgModuleResolver {
private _ngModules = new Map<Type, NgModuleMetadata>();
private _ngModules = new Map<Type<any>, NgModuleMetadata>();
constructor(private _injector: Injector) { super(); }
private get _compiler(): Compiler { return this._injector.get(Compiler); }
private _clearCacheFor(component: Type) { this._compiler.clearCacheFor(component); }
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
/**
* Overrides the {@link NgModuleMetadata} for a module.
*/
setNgModule(type: Type, metadata: NgModuleMetadata): void {
setNgModule(type: Type<any>, metadata: NgModuleMetadata): void {
this._ngModules.set(type, metadata);
this._clearCacheFor(type);
}
@ -35,7 +35,7 @@ export class MockNgModuleResolver extends NgModuleResolver {
* default
* `NgModuleResolver`, see `setNgModule`.
*/
resolve(type: Type, throwIfNotFound = true): NgModuleMetadata {
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
var metadata = this._ngModules.get(type);
if (!metadata) {
metadata = super.resolve(type, throwIfNotFound);

View File

@ -13,18 +13,18 @@ import {Map} from '../src/facade/collection';
@Injectable()
export class MockPipeResolver extends PipeResolver {
private _pipes = new Map<Type, PipeMetadata>();
private _pipes = new Map<Type<any>, PipeMetadata>();
constructor(private _injector: Injector) { super(); }
private get _compiler(): Compiler { return this._injector.get(Compiler); }
private _clearCacheFor(pipe: Type) { this._compiler.clearCacheFor(pipe); }
private _clearCacheFor(pipe: Type<any>) { this._compiler.clearCacheFor(pipe); }
/**
* Overrides the {@link PipeMetadata} for a pipe.
*/
setPipe(type: Type, metadata: PipeMetadata): void {
setPipe(type: Type<any>, metadata: PipeMetadata): void {
this._pipes.set(type, metadata);
this._clearCacheFor(type);
}
@ -35,7 +35,7 @@ export class MockPipeResolver extends PipeResolver {
* default
* `PipeResolver`, see `setPipe`.
*/
resolve(type: Type, throwIfNotFound = true): PipeMetadata {
resolve(type: Type<any>, throwIfNotFound = true): PipeMetadata {
var metadata = this._pipes.get(type);
if (!metadata) {
metadata = super.resolve(type, throwIfNotFound);

View File

@ -6,12 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AnimationEntryMetadata, Compiler, ComponentFactory, Inject, Injectable, Injector, NgZone, ViewMetadata} from '@angular/core';
import {AnimationEntryMetadata, Compiler, ComponentFactory, Inject, Injectable, Injector, NgZone, Type, ViewMetadata} from '@angular/core';
import {ComponentFixture, ComponentFixtureNoNgZone, TestBed, TestComponentBuilder} from '@angular/core/testing';
import {DirectiveResolver} from '../index';
import {MapWrapper} from '../src/facade/collection';
import {ConcreteType, Type, isPresent} from '../src/facade/lang';
import {isPresent} from '../src/facade/lang';
/**
@ -23,17 +24,17 @@ import {ConcreteType, Type, isPresent} from '../src/facade/lang';
@Injectable()
export class OverridingTestComponentBuilder extends TestComponentBuilder {
/** @internal */
_bindingsOverrides = new Map<Type, any[]>();
_bindingsOverrides = new Map<Type<any>, any[]>();
/** @internal */
_directiveOverrides = new Map<Type, Map<Type, Type>>();
_directiveOverrides = new Map<Type<any>, Map<Type<any>, Type<any>>>();
/** @internal */
_templateOverrides = new Map<Type, string>();
_templateOverrides = new Map<Type<any>, string>();
/** @internal */
_animationOverrides = new Map<Type, AnimationEntryMetadata[]>();
_animationOverrides = new Map<Type<any>, AnimationEntryMetadata[]>();
/** @internal */
_viewBindingsOverrides = new Map<Type, any[]>();
_viewBindingsOverrides = new Map<Type<any>, any[]>();
/** @internal */
_viewOverrides = new Map<Type, ViewMetadata>();
_viewOverrides = new Map<Type<any>, ViewMetadata>();
constructor(@Inject(TestBed) injector: Injector) { super(injector); }
@ -48,54 +49,55 @@ export class OverridingTestComponentBuilder extends TestComponentBuilder {
return clone;
}
overrideTemplate(componentType: Type, template: string): OverridingTestComponentBuilder {
overrideTemplate(componentType: Type<any>, template: string): OverridingTestComponentBuilder {
let clone = this._clone();
clone._templateOverrides.set(componentType, template);
return clone;
}
overrideAnimations(componentType: Type, animations: AnimationEntryMetadata[]):
overrideAnimations(componentType: Type<any>, animations: AnimationEntryMetadata[]):
TestComponentBuilder {
var clone = this._clone();
clone._animationOverrides.set(componentType, animations);
return clone;
}
overrideView(componentType: Type, view: ViewMetadata): OverridingTestComponentBuilder {
overrideView(componentType: Type<any>, view: ViewMetadata): OverridingTestComponentBuilder {
let clone = this._clone();
clone._viewOverrides.set(componentType, view);
return clone;
}
overrideDirective(componentType: Type, from: Type, to: Type): OverridingTestComponentBuilder {
overrideDirective(componentType: Type<any>, from: Type<any>, to: Type<any>):
OverridingTestComponentBuilder {
let clone = this._clone();
let overridesForComponent = clone._directiveOverrides.get(componentType);
if (!isPresent(overridesForComponent)) {
clone._directiveOverrides.set(componentType, new Map<Type, Type>());
clone._directiveOverrides.set(componentType, new Map<Type<any>, Type<any>>());
overridesForComponent = clone._directiveOverrides.get(componentType);
}
overridesForComponent.set(from, to);
return clone;
}
overrideProviders(type: Type, providers: any[]): OverridingTestComponentBuilder {
overrideProviders(type: Type<any>, providers: any[]): OverridingTestComponentBuilder {
let clone = this._clone();
clone._bindingsOverrides.set(type, providers);
return clone;
}
overrideViewProviders(type: Type, providers: any[]): OverridingTestComponentBuilder {
overrideViewProviders(type: Type<any>, providers: any[]): OverridingTestComponentBuilder {
let clone = this._clone();
clone._viewBindingsOverrides.set(type, providers);
return clone;
}
createAsync<T>(rootComponentType: ConcreteType<T>): Promise<ComponentFixture<T>> {
createAsync<T>(rootComponentType: Type<T>): Promise<ComponentFixture<T>> {
this._applyMetadataOverrides();
return super.createAsync(rootComponentType);
}
createSync<T>(rootComponentType: ConcreteType<T>): ComponentFixture<T> {
createSync<T>(rootComponentType: Type<T>): ComponentFixture<T> {
this._applyMetadataOverrides();
return super.createSync(rootComponentType);
}