refactor(core): remove …Metadata for all decorators and use the decorator directly.

BREAKING CHANGE:
- all `…Metadata` classes have been removed. Use the corresponding decorator
  as constructor or for `instanceof` checks instead.
- Example:
  * Before: `new ComponentMetadata(…)`
  * After: `new Component(…)`
- Note: `new Component(…)` worked before as well.
This commit is contained in:
Tobias Bosch
2016-09-12 19:14:17 -07:00
committed by Igor Minar
parent 1b15170c89
commit 63e15ffaec
40 changed files with 229 additions and 279 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {COMPILER_OPTIONS, ClassProvider, Compiler, CompilerFactory, CompilerOptions, Component, ExistingProvider, FactoryProvider, Inject, Injectable, OptionalMetadata, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, TypeProvider, ValueProvider, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
import {COMPILER_OPTIONS, ClassProvider, Compiler, CompilerFactory, CompilerOptions, Component, ExistingProvider, FactoryProvider, Inject, Injectable, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, TypeProvider, ValueProvider, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
export * from './template_parser/template_ast';
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser';
@ -66,8 +66,8 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
new i18n.I18NHtmlParser(parser, translations, format),
deps: [
HtmlParser,
[new OptionalMetadata(), new Inject(TRANSLATIONS)],
[new OptionalMetadata(), new Inject(TRANSLATIONS_FORMAT)],
[new Optional(), new Inject(TRANSLATIONS)],
[new Optional(), new Inject(TRANSLATIONS_FORMAT)],
]
},
TemplateParser,

View File

@ -6,19 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, Type, resolveForwardRef} from '@angular/core';
import {Component, Directive, HostBinding, HostListener, Injectable, Input, Output, Query, Type, resolveForwardRef} from '@angular/core';
import {StringMapWrapper} from './facade/collection';
import {isPresent, stringify} from './facade/lang';
import {ReflectorReader, reflector} from './private_import_core';
import {splitAtColon} from './util';
function _isDirectiveMetadata(type: any): type is DirectiveMetadata {
return type instanceof DirectiveMetadata;
function _isDirectiveMetadata(type: any): type is Directive {
return type instanceof Directive;
}
/*
* Resolve a `Type` for {@link DirectiveMetadata}.
* Resolve a `Type` for {@link Directive}.
*
* This interface can be overridden by the application developer to create custom behavior.
*
@ -29,9 +29,9 @@ export class DirectiveResolver {
constructor(private _reflector: ReflectorReader = reflector) {}
/**
* Return {@link DirectiveMetadata} for a given `Type`.
* Return {@link Directive} for a given `Type`.
*/
resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata {
resolve(type: Type<any>, throwIfNotFound = true): Directive {
var typeMetadata = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(typeMetadata)) {
var metadata = typeMetadata.find(_isDirectiveMetadata);
@ -47,8 +47,8 @@ export class DirectiveResolver {
}
private _mergeWithPropertyMetadata(
dm: DirectiveMetadata, propertyMetadata: {[key: string]: any[]},
directiveType: Type<any>): DirectiveMetadata {
dm: Directive, propertyMetadata: {[key: string]: any[]},
directiveType: Type<any>): Directive {
var inputs: string[] = [];
var outputs: string[] = [];
var host: {[key: string]: string} = {};
@ -56,31 +56,31 @@ export class DirectiveResolver {
StringMapWrapper.forEach(propertyMetadata, (metadata: any[], propName: string) => {
metadata.forEach(a => {
if (a instanceof InputMetadata) {
if (a instanceof Input) {
if (isPresent(a.bindingPropertyName)) {
inputs.push(`${propName}: ${a.bindingPropertyName}`);
} else {
inputs.push(propName);
}
} else if (a instanceof OutputMetadata) {
const output: OutputMetadata = a;
} else if (a instanceof Output) {
const output: Output = a;
if (isPresent(output.bindingPropertyName)) {
outputs.push(`${propName}: ${output.bindingPropertyName}`);
} else {
outputs.push(propName);
}
} else if (a instanceof HostBindingMetadata) {
const hostBinding: HostBindingMetadata = a;
} else if (a instanceof HostBinding) {
const hostBinding: HostBinding = a;
if (isPresent(hostBinding.hostPropertyName)) {
host[`[${hostBinding.hostPropertyName}]`] = propName;
} else {
host[`[${propName}]`] = propName;
}
} else if (a instanceof HostListenerMetadata) {
const hostListener: HostListenerMetadata = a;
} else if (a instanceof HostListener) {
const hostListener: HostListener = a;
var args = isPresent(hostListener.args) ? (<any[]>hostListener.args).join(', ') : '';
host[`(${hostListener.eventName})`] = `${propName}(${args})`;
} else if (a instanceof QueryMetadata) {
} else if (a instanceof Query) {
queries[propName] = a;
}
});
@ -91,8 +91,8 @@ export class DirectiveResolver {
private _extractPublicName(def: string) { return splitAtColon(def, [null, def])[1].trim(); }
private _merge(
dm: DirectiveMetadata, inputs: string[], outputs: string[], host: {[key: string]: string},
queries: {[key: string]: any}, directiveType: Type<any>): DirectiveMetadata {
dm: Directive, inputs: string[], outputs: string[], host: {[key: string]: string},
queries: {[key: string]: any}, directiveType: Type<any>): Directive {
let mergedInputs: string[];
if (isPresent(dm.inputs)) {
@ -132,8 +132,8 @@ export class DirectiveResolver {
var mergedQueries =
isPresent(dm.queries) ? StringMapWrapper.merge(dm.queries, queries) : queries;
if (dm instanceof ComponentMetadata) {
return new ComponentMetadata({
if (dm instanceof Component) {
return new Component({
selector: dm.selector,
inputs: mergedInputs,
outputs: mergedOutputs,
@ -155,7 +155,7 @@ export class DirectiveResolver {
});
} else {
return new DirectiveMetadata({
return new Directive({
selector: dm.selector,
inputs: mergedInputs,
outputs: mergedOutputs,

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, ChangeDetectionStrategy, ComponentMetadata, HostMetadata, InjectMetadata, Injectable, ModuleWithProviders, OptionalMetadata, Provider, QueryMetadata, SchemaMetadata, SelfMetadata, SkipSelfMetadata, Type, resolveForwardRef} from '@angular/core';
import {AnimationAnimateMetadata, AnimationEntryMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationStateDeclarationMetadata, AnimationStateMetadata, AnimationStateTransitionMetadata, AnimationStyleMetadata, AnimationWithStepsMetadata, Attribute, ChangeDetectionStrategy, Component, Host, Inject, Injectable, ModuleWithProviders, Optional, Provider, Query, SchemaMetadata, Self, SkipSelf, Type, resolveForwardRef} from '@angular/core';
import {StringMapWrapper} from '../src/facade/collection';
@ -55,7 +55,7 @@ export class CompileMetadataResolver {
this._directiveCache.delete(type);
this._pipeCache.delete(type);
this._ngModuleOfTypes.delete(type);
// Clear all of the NgModuleMetadata as they contain transitive information!
// Clear all of the NgModule as they contain transitive information!
this._ngModuleCache.clear();
}
@ -123,8 +123,8 @@ export class CompileMetadataResolver {
var moduleUrl = staticTypeModuleUrl(directiveType);
var entryComponentMetadata: cpl.CompileTypeMetadata[] = [];
let selector = dirMeta.selector;
if (dirMeta instanceof ComponentMetadata) {
var cmpMeta = <ComponentMetadata>dirMeta;
if (dirMeta instanceof Component) {
var cmpMeta = <Component>dirMeta;
assertArrayOfStrings('styles', cmpMeta.styles);
assertInterpolationSymbols('interpolation', cmpMeta.interpolation);
var animations = isPresent(cmpMeta.animations) ?
@ -483,29 +483,29 @@ export class CompileMetadataResolver {
let isSelf = false;
let isSkipSelf = false;
let isOptional = false;
let query: QueryMetadata = null;
let viewQuery: QueryMetadata = null;
let query: Query = null;
let viewQuery: Query = null;
var token: any = null;
if (isArray(param)) {
(<any[]>param).forEach((paramEntry) => {
if (paramEntry instanceof HostMetadata) {
if (paramEntry instanceof Host) {
isHost = true;
} else if (paramEntry instanceof SelfMetadata) {
} else if (paramEntry instanceof Self) {
isSelf = true;
} else if (paramEntry instanceof SkipSelfMetadata) {
} else if (paramEntry instanceof SkipSelf) {
isSkipSelf = true;
} else if (paramEntry instanceof OptionalMetadata) {
} else if (paramEntry instanceof Optional) {
isOptional = true;
} else if (paramEntry instanceof AttributeMetadata) {
} else if (paramEntry instanceof Attribute) {
isAttribute = true;
token = paramEntry.attributeName;
} else if (paramEntry instanceof QueryMetadata) {
} else if (paramEntry instanceof Query) {
if (paramEntry.isViewQuery) {
viewQuery = paramEntry;
} else {
query = paramEntry;
}
} else if (paramEntry instanceof InjectMetadata) {
} else if (paramEntry instanceof Inject) {
token = paramEntry.token;
} else if (isValidType(paramEntry) && isBlank(token)) {
token = paramEntry;
@ -653,10 +653,10 @@ export class CompileMetadataResolver {
}
getQueriesMetadata(
queries: {[key: string]: QueryMetadata}, isViewQuery: boolean,
queries: {[key: string]: Query}, isViewQuery: boolean,
directiveType: Type<any>): cpl.CompileQueryMetadata[] {
var res: cpl.CompileQueryMetadata[] = [];
StringMapWrapper.forEach(queries, (query: QueryMetadata, propertyName: string) => {
StringMapWrapper.forEach(queries, (query: Query, propertyName: string) => {
if (query.isViewQuery === isViewQuery) {
res.push(this.getQueryMetadata(query, propertyName, directiveType));
}
@ -669,7 +669,7 @@ export class CompileMetadataResolver {
}
getQueryMetadata(q: QueryMetadata, propertyName: string, typeOrFunc: Type<any>|Function):
getQueryMetadata(q: Query, propertyName: string, typeOrFunc: Type<any>|Function):
cpl.CompileQueryMetadata {
var selectors: cpl.CompileTokenMetadata[];
if (isString(q.selector)) {
@ -733,8 +733,7 @@ function staticTypeModuleUrl(value: any): string {
return cpl.isStaticSymbol(value) ? value.filePath : null;
}
function componentModuleUrl(
reflector: ReflectorReader, type: any, cmpMetadata: ComponentMetadata): string {
function componentModuleUrl(reflector: ReflectorReader, type: any, cmpMetadata: Component): string {
if (cpl.isStaticSymbol(type)) {
return staticTypeModuleUrl(type);
}

View File

@ -6,25 +6,24 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable, NgModuleMetadata, Type} from '@angular/core';
import {Injectable, NgModule, Type} from '@angular/core';
import {isPresent, stringify} from './facade/lang';
import {ReflectorReader, reflector} from './private_import_core';
function _isNgModuleMetadata(obj: any): obj is NgModuleMetadata {
return obj instanceof NgModuleMetadata;
function _isNgModuleMetadata(obj: any): obj is NgModule {
return obj instanceof NgModule;
}
/**
* Resolves types to {@link NgModuleMetadata}.
* Resolves types to {@link NgModule}.
*/
@Injectable()
export class NgModuleResolver {
constructor(private _reflector: ReflectorReader = reflector) {}
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata {
const ngModuleMeta: NgModuleMetadata =
this._reflector.annotations(type).find(_isNgModuleMetadata);
resolve(type: Type<any>, throwIfNotFound = true): NgModule {
const ngModuleMeta: NgModule = this._reflector.annotations(type).find(_isNgModuleMetadata);
if (isPresent(ngModuleMeta)) {
return ngModuleMeta;

View File

@ -6,17 +6,17 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Injectable, PipeMetadata, Type, resolveForwardRef} from '@angular/core';
import {Injectable, Pipe, Type, resolveForwardRef} from '@angular/core';
import {isPresent, stringify} from './facade/lang';
import {ReflectorReader, reflector} from './private_import_core';
function _isPipeMetadata(type: any): boolean {
return type instanceof PipeMetadata;
return type instanceof Pipe;
}
/**
* Resolve a `Type` for {@link PipeMetadata}.
* Resolve a `Type` for {@link Pipe}.
*
* This interface can be overridden by the application developer to create custom behavior.
*
@ -27,9 +27,9 @@ export class PipeResolver {
constructor(private _reflector: ReflectorReader = reflector) {}
/**
* Return {@link PipeMetadata} for a given `Type`.
* Return {@link Pipe} for a given `Type`.
*/
resolve(type: Type<any>, throwIfNotFound = true): PipeMetadata {
resolve(type: Type<any>, throwIfNotFound = true): Pipe {
var metas = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(metas)) {
var annotation = metas.find(_isPipeMetadata);

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Compiler, ComponentFactory, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, OptionalMetadata, Provider, SchemaMetadata, SkipSelfMetadata, Type} from '@angular/core';
import {Compiler, ComponentFactory, Injectable, Injector, ModuleWithComponentFactories, NgModuleFactory, Optional, Provider, SchemaMetadata, SkipSelf, Type} from '@angular/core';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from './compile_metadata';
import {CompilerConfig} from './config';