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

@ -11,7 +11,7 @@
* Intended to be used in a build step. * Intended to be used in a build step.
*/ */
import * as compiler from '@angular/compiler'; import * as compiler from '@angular/compiler';
import {ComponentMetadata, NgModuleMetadata, ViewEncapsulation} from '@angular/core'; import {Component, NgModule, ViewEncapsulation} from '@angular/core';
import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped'; import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
import * as path from 'path'; import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
@ -62,9 +62,9 @@ export class CodeGenerator {
const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath); const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath);
const annotations = this.staticReflector.annotations(staticType); const annotations = this.staticReflector.annotations(staticType);
annotations.forEach((annotation) => { annotations.forEach((annotation) => {
if (annotation instanceof NgModuleMetadata) { if (annotation instanceof NgModule) {
result.ngModules.push(staticType); result.ngModules.push(staticType);
} else if (annotation instanceof ComponentMetadata) { } else if (annotation instanceof Component) {
result.components.push(staticType); result.components.push(staticType);
} }
}); });

View File

@ -17,7 +17,7 @@
import 'reflect-metadata'; import 'reflect-metadata';
import * as compiler from '@angular/compiler'; import * as compiler from '@angular/compiler';
import {ComponentMetadata, NgModuleMetadata, ViewEncapsulation} from '@angular/core'; import {Component, NgModule, ViewEncapsulation} from '@angular/core';
import * as path from 'path'; import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import * as tsc from '@angular/tsc-wrapped'; import * as tsc from '@angular/tsc-wrapped';
@ -87,9 +87,9 @@ export class Extractor {
const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath); const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath);
const annotations = this.staticReflector.annotations(staticType); const annotations = this.staticReflector.annotations(staticType);
annotations.forEach((annotation) => { annotations.forEach((annotation) => {
if (annotation instanceof NgModuleMetadata) { if (annotation instanceof NgModule) {
result.ngModules.push(staticType); result.ngModules.push(staticType);
} else if (annotation instanceof ComponentMetadata) { } else if (annotation instanceof Component) {
result.components.push(staticType); result.components.push(staticType);
} }
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AttributeMetadata, ComponentMetadata, ContentChildMetadata, ContentChildrenMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, HostMetadata, InjectMetadata, InjectableMetadata, InputMetadata, NgModuleMetadata, OptionalMetadata, OutputMetadata, PipeMetadata, QueryMetadata, SelfMetadata, SkipSelfMetadata, ViewChildMetadata, ViewChildrenMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core'; import {Attribute, Component, ContentChild, ContentChildren, Directive, Host, HostBinding, HostListener, Inject, Injectable, Input, NgModule, Optional, Output, Pipe, Query, Self, SkipSelf, ViewChild, ViewChildren, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
import {ReflectorReader} from './private_import_core'; import {ReflectorReader} from './private_import_core';
@ -181,54 +181,47 @@ export class StaticReflector implements ReflectorReader {
this.host.angularImportLocations(); this.host.angularImportLocations();
this.opaqueToken = this.host.findDeclaration(diOpaqueToken, 'OpaqueToken'); this.opaqueToken = this.host.findDeclaration(diOpaqueToken, 'OpaqueToken');
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Host'), Host);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'Host'), HostMetadata); this.host.findDeclaration(diDecorators, 'Injectable'), Injectable);
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Self'), Self);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'Injectable'), InjectableMetadata); this.host.findDeclaration(diDecorators, 'SkipSelf'), SkipSelf);
this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Inject'), Inject);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'Self'), SelfMetadata); this.host.findDeclaration(diDecorators, 'Optional'), Optional);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'SkipSelf'), SkipSelfMetadata); this.host.findDeclaration(coreDecorators, 'Attribute'), Attribute);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'Inject'), InjectMetadata); this.host.findDeclaration(coreDecorators, 'ContentChild'), ContentChild);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diDecorators, 'Optional'), OptionalMetadata); this.host.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildren);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Attribute'), AttributeMetadata); this.host.findDeclaration(coreDecorators, 'ViewChild'), ViewChild);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'ContentChild'), ContentChildMetadata); this.host.findDeclaration(coreDecorators, 'ViewChildren'), ViewChildren);
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Input'), Input);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildrenMetadata); this.host.findDeclaration(coreDecorators, 'Output'), Output);
this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Pipe'), Pipe);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'ViewChild'), ViewChildMetadata); this.host.findDeclaration(coreDecorators, 'HostBinding'), HostBinding);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'ViewChildren'), ViewChildrenMetadata); this.host.findDeclaration(coreDecorators, 'HostListener'), HostListener);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Input'), InputMetadata); this.host.findDeclaration(coreDecorators, 'Directive'), Directive);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Output'), OutputMetadata); this.host.findDeclaration(coreDecorators, 'Component'), Component);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Pipe'), PipeMetadata); this.host.findDeclaration(coreDecorators, 'NgModule'), NgModule);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'HostBinding'), HostBindingMetadata);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'HostListener'), HostListenerMetadata);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Directive'), DirectiveMetadata);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'Component'), ComponentMetadata);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(coreDecorators, 'NgModule'), NgModuleMetadata);
// Note: Some metadata classes can be used directly with Provider.deps. // Note: Some metadata classes can be used directly with Provider.deps.
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'Host'), Host);
this.registerDecoratorOrConstructor(this.host.findDeclaration(diMetadata, 'Self'), Self);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diMetadata, 'HostMetadata'), HostMetadata); this.host.findDeclaration(diMetadata, 'SkipSelf'), SkipSelf);
this.registerDecoratorOrConstructor( this.registerDecoratorOrConstructor(
this.host.findDeclaration(diMetadata, 'SelfMetadata'), SelfMetadata); this.host.findDeclaration(diMetadata, 'Optional'), Optional);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(diMetadata, 'SkipSelfMetadata'), SkipSelfMetadata);
this.registerDecoratorOrConstructor(
this.host.findDeclaration(diMetadata, 'OptionalMetadata'), OptionalMetadata);
this.registerFunction(this.host.findDeclaration(animationMetadata, 'trigger'), trigger); this.registerFunction(this.host.findDeclaration(animationMetadata, 'trigger'), trigger);
this.registerFunction(this.host.findDeclaration(animationMetadata, 'state'), state); this.registerFunction(this.host.findDeclaration(animationMetadata, 'state'), state);

View File

@ -7,7 +7,7 @@
*/ */
import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector'; import {StaticReflector, StaticReflectorHost, StaticSymbol} from '@angular/compiler-cli/src/static_reflector';
import {HostListenerMetadata, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core'; import {HostListener, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
import {ListWrapper} from '@angular/facade/src/collection'; import {ListWrapper} from '@angular/facade/src/collection';
import {isBlank} from '@angular/facade/src/lang'; import {isBlank} from '@angular/facade/src/lang';
import {MetadataCollector} from '@angular/tsc-wrapped'; import {MetadataCollector} from '@angular/tsc-wrapped';
@ -92,7 +92,7 @@ describe('StaticReflector', () => {
host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent'); host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
let props = reflector.propMetadata(HeroDetailComponent); let props = reflector.propMetadata(HeroDetailComponent);
expect(props['hero']).toBeTruthy(); expect(props['hero']).toBeTruthy();
expect(props['onMouseOver']).toEqual([new HostListenerMetadata('mouseover', ['$event'])]); expect(props['onMouseOver']).toEqual([new HostListener('mouseover', ['$event'])]);
}); });
it('should get an empty object from propMetadata for an unknown class', () => { it('should get an empty object from propMetadata for an unknown class', () => {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * 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 * from './template_parser/template_ast';
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser'; 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), new i18n.I18NHtmlParser(parser, translations, format),
deps: [ deps: [
HtmlParser, HtmlParser,
[new OptionalMetadata(), new Inject(TRANSLATIONS)], [new Optional(), new Inject(TRANSLATIONS)],
[new OptionalMetadata(), new Inject(TRANSLATIONS_FORMAT)], [new Optional(), new Inject(TRANSLATIONS_FORMAT)],
] ]
}, },
TemplateParser, TemplateParser,

View File

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

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * 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'; import {StringMapWrapper} from '../src/facade/collection';
@ -55,7 +55,7 @@ export class CompileMetadataResolver {
this._directiveCache.delete(type); this._directiveCache.delete(type);
this._pipeCache.delete(type); this._pipeCache.delete(type);
this._ngModuleOfTypes.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(); this._ngModuleCache.clear();
} }
@ -123,8 +123,8 @@ export class CompileMetadataResolver {
var moduleUrl = staticTypeModuleUrl(directiveType); var moduleUrl = staticTypeModuleUrl(directiveType);
var entryComponentMetadata: cpl.CompileTypeMetadata[] = []; var entryComponentMetadata: cpl.CompileTypeMetadata[] = [];
let selector = dirMeta.selector; let selector = dirMeta.selector;
if (dirMeta instanceof ComponentMetadata) { if (dirMeta instanceof Component) {
var cmpMeta = <ComponentMetadata>dirMeta; var cmpMeta = <Component>dirMeta;
assertArrayOfStrings('styles', cmpMeta.styles); assertArrayOfStrings('styles', cmpMeta.styles);
assertInterpolationSymbols('interpolation', cmpMeta.interpolation); assertInterpolationSymbols('interpolation', cmpMeta.interpolation);
var animations = isPresent(cmpMeta.animations) ? var animations = isPresent(cmpMeta.animations) ?
@ -483,29 +483,29 @@ export class CompileMetadataResolver {
let isSelf = false; let isSelf = false;
let isSkipSelf = false; let isSkipSelf = false;
let isOptional = false; let isOptional = false;
let query: QueryMetadata = null; let query: Query = null;
let viewQuery: QueryMetadata = null; let viewQuery: Query = null;
var token: any = null; var token: any = null;
if (isArray(param)) { if (isArray(param)) {
(<any[]>param).forEach((paramEntry) => { (<any[]>param).forEach((paramEntry) => {
if (paramEntry instanceof HostMetadata) { if (paramEntry instanceof Host) {
isHost = true; isHost = true;
} else if (paramEntry instanceof SelfMetadata) { } else if (paramEntry instanceof Self) {
isSelf = true; isSelf = true;
} else if (paramEntry instanceof SkipSelfMetadata) { } else if (paramEntry instanceof SkipSelf) {
isSkipSelf = true; isSkipSelf = true;
} else if (paramEntry instanceof OptionalMetadata) { } else if (paramEntry instanceof Optional) {
isOptional = true; isOptional = true;
} else if (paramEntry instanceof AttributeMetadata) { } else if (paramEntry instanceof Attribute) {
isAttribute = true; isAttribute = true;
token = paramEntry.attributeName; token = paramEntry.attributeName;
} else if (paramEntry instanceof QueryMetadata) { } else if (paramEntry instanceof Query) {
if (paramEntry.isViewQuery) { if (paramEntry.isViewQuery) {
viewQuery = paramEntry; viewQuery = paramEntry;
} else { } else {
query = paramEntry; query = paramEntry;
} }
} else if (paramEntry instanceof InjectMetadata) { } else if (paramEntry instanceof Inject) {
token = paramEntry.token; token = paramEntry.token;
} else if (isValidType(paramEntry) && isBlank(token)) { } else if (isValidType(paramEntry) && isBlank(token)) {
token = paramEntry; token = paramEntry;
@ -653,10 +653,10 @@ export class CompileMetadataResolver {
} }
getQueriesMetadata( getQueriesMetadata(
queries: {[key: string]: QueryMetadata}, isViewQuery: boolean, queries: {[key: string]: Query}, isViewQuery: boolean,
directiveType: Type<any>): cpl.CompileQueryMetadata[] { directiveType: Type<any>): cpl.CompileQueryMetadata[] {
var res: cpl.CompileQueryMetadata[] = []; var res: cpl.CompileQueryMetadata[] = [];
StringMapWrapper.forEach(queries, (query: QueryMetadata, propertyName: string) => { StringMapWrapper.forEach(queries, (query: Query, propertyName: string) => {
if (query.isViewQuery === isViewQuery) { if (query.isViewQuery === isViewQuery) {
res.push(this.getQueryMetadata(query, propertyName, directiveType)); 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 { cpl.CompileQueryMetadata {
var selectors: cpl.CompileTokenMetadata[]; var selectors: cpl.CompileTokenMetadata[];
if (isString(q.selector)) { if (isString(q.selector)) {
@ -733,8 +733,7 @@ function staticTypeModuleUrl(value: any): string {
return cpl.isStaticSymbol(value) ? value.filePath : null; return cpl.isStaticSymbol(value) ? value.filePath : null;
} }
function componentModuleUrl( function componentModuleUrl(reflector: ReflectorReader, type: any, cmpMetadata: Component): string {
reflector: ReflectorReader, type: any, cmpMetadata: ComponentMetadata): string {
if (cpl.isStaticSymbol(type)) { if (cpl.isStaticSymbol(type)) {
return staticTypeModuleUrl(type); return staticTypeModuleUrl(type);
} }

View File

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

View File

@ -6,17 +6,17 @@
* found in the LICENSE file at https://angular.io/license * 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 {isPresent, stringify} from './facade/lang';
import {ReflectorReader, reflector} from './private_import_core'; import {ReflectorReader, reflector} from './private_import_core';
function _isPipeMetadata(type: any): boolean { 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. * 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) {} 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)); var metas = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(metas)) { if (isPresent(metas)) {
var annotation = metas.find(_isPipeMetadata); var annotation = metas.find(_isPipeMetadata);

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * 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 {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeMetadata, ProviderMeta, createHostComponentMeta} from './compile_metadata';
import {CompilerConfig} from './config'; import {CompilerConfig} from './config';

View File

@ -11,7 +11,7 @@ import {LifecycleHooks} from '@angular/core/src/metadata/lifecycle_hooks';
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe} from '@angular/core/testing/testing_internal'; import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe} from '@angular/core/testing/testing_internal';
export function main() { export function main() {
describe('Create DirectiveMetadata', () => { describe('Create Directive', () => {
describe('lifecycle', () => { describe('lifecycle', () => {
describe('ngOnChanges', () => { describe('ngOnChanges', () => {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Component, ComponentMetadata, Directive, Injector} from '@angular/core'; import {Component, Directive, Injector} from '@angular/core';
import {TestBed, inject} from '@angular/core/testing'; import {TestBed, inject} from '@angular/core/testing';
import {MockDirectiveResolver} from '../testing/index'; import {MockDirectiveResolver} from '../testing/index';
@ -34,8 +34,7 @@ export function main() {
}); });
it('should allow overriding the @Directive', () => { it('should allow overriding the @Directive', () => {
dirResolver.setDirective( dirResolver.setDirective(SomeComponent, new Component({selector: 'someOtherSelector'}));
SomeComponent, new ComponentMetadata({selector: 'someOtherSelector'}));
var metadata = dirResolver.resolve(SomeComponent); var metadata = dirResolver.resolve(SomeComponent);
expect(metadata.selector).toEqual('someOtherSelector'); expect(metadata.selector).toEqual('someOtherSelector');
}); });
@ -43,20 +42,20 @@ export function main() {
describe('View overriding', () => { describe('View overriding', () => {
it('should fallback to the default ViewResolver when templates are not overridden', () => { it('should fallback to the default ViewResolver when templates are not overridden', () => {
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('template'); expect(view.template).toEqual('template');
}); });
it('should allow overriding the @View', () => { it('should allow overriding the @View', () => {
dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'})); dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template'); expect(view.template).toEqual('overridden template');
}); });
it('should allow overriding a view after it has been resolved', () => { it('should allow overriding a view after it has been resolved', () => {
dirResolver.resolve(SomeComponent); dirResolver.resolve(SomeComponent);
dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'})); dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template'); expect(view.template).toEqual('overridden template');
}); });
}); });
@ -64,21 +63,21 @@ export function main() {
describe('inline template definition overriding', () => { describe('inline template definition overriding', () => {
it('should allow overriding the default template', () => { it('should allow overriding the default template', () => {
dirResolver.setInlineTemplate(SomeComponent, 'overridden template'); dirResolver.setInlineTemplate(SomeComponent, 'overridden template');
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template'); expect(view.template).toEqual('overridden template');
}); });
it('should allow overriding an overridden @View', () => { it('should allow overriding an overridden @View', () => {
dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'})); dirResolver.setView(SomeComponent, new ViewMetadata({template: 'overridden template'}));
dirResolver.setInlineTemplate(SomeComponent, 'overridden template x 2'); dirResolver.setInlineTemplate(SomeComponent, 'overridden template x 2');
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template x 2'); expect(view.template).toEqual('overridden template x 2');
}); });
it('should allow overriding a view after it has been resolved', () => { it('should allow overriding a view after it has been resolved', () => {
dirResolver.resolve(SomeComponent); dirResolver.resolve(SomeComponent);
dirResolver.setInlineTemplate(SomeComponent, 'overridden template'); dirResolver.setInlineTemplate(SomeComponent, 'overridden template');
var view = <ComponentMetadata>dirResolver.resolve(SomeComponent); var view = <Component>dirResolver.resolve(SomeComponent);
expect(view.template).toEqual('overridden template'); expect(view.template).toEqual('overridden template');
}); });
}); });

View File

@ -7,7 +7,7 @@
*/ */
import {DirectiveResolver} from '@angular/compiler/src/directive_resolver'; import {DirectiveResolver} from '@angular/compiler/src/directive_resolver';
import {Component, ComponentMetadata, ContentChild, ContentChildren, Directive, DirectiveMetadata, HostBinding, HostListener, Input, Output, ViewChild, ViewChildren} from '@angular/core/src/metadata'; import {Component, ContentChild, ContentChildren, Directive, HostBinding, HostListener, Input, Output, ViewChild, ViewChildren} from '@angular/core/src/metadata';
@Directive({selector: 'someDirective'}) @Directive({selector: 'someDirective'})
class SomeDirective { class SomeDirective {
@ -119,7 +119,7 @@ export function main() {
it('should read out the Directive metadata', () => { it('should read out the Directive metadata', () => {
var directiveMetadata = resolver.resolve(SomeDirective); var directiveMetadata = resolver.resolve(SomeDirective);
expect(directiveMetadata) expect(directiveMetadata)
.toEqual(new DirectiveMetadata( .toEqual(new Directive(
{selector: 'someDirective', inputs: [], outputs: [], host: {}, queries: {}})); {selector: 'someDirective', inputs: [], outputs: [], host: {}, queries: {}}));
}); });
@ -132,7 +132,7 @@ export function main() {
it('should not read parent class Directive metadata', function() { it('should not read parent class Directive metadata', function() {
var directiveMetadata = resolver.resolve(SomeChildDirective); var directiveMetadata = resolver.resolve(SomeChildDirective);
expect(directiveMetadata) expect(directiveMetadata)
.toEqual(new DirectiveMetadata( .toEqual(new Directive(
{selector: 'someChildDirective', inputs: [], outputs: [], host: {}, queries: {}})); {selector: 'someChildDirective', inputs: [], outputs: [], host: {}, queries: {}}));
}); });
@ -225,7 +225,7 @@ export function main() {
describe('view', () => { describe('view', () => {
it('should read out the template related metadata from the Component metadata', () => { it('should read out the template related metadata from the Component metadata', () => {
var compMetadata = <ComponentMetadata>resolver.resolve(ComponentWithTemplate); var compMetadata = <Component>resolver.resolve(ComponentWithTemplate);
expect(compMetadata.template).toEqual('some template'); expect(compMetadata.template).toEqual('some template');
expect(compMetadata.styles).toEqual(['some styles']); expect(compMetadata.styles).toEqual(['some styles']);
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Injector, NgModule, NgModuleMetadata} from '@angular/core'; import {Injector, NgModule} from '@angular/core';
import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal';
import {isBlank, stringify} from '../src/facade/lang'; import {isBlank, stringify} from '../src/facade/lang';
@ -29,7 +29,7 @@ export function main() {
it('should allow overriding the @NgModule', () => { it('should allow overriding the @NgModule', () => {
ngModuleResolver.setNgModule( ngModuleResolver.setNgModule(
SomeNgModule, new NgModuleMetadata({declarations: [SomeOtherDirective]})); SomeNgModule, new NgModule({declarations: [SomeOtherDirective]}));
var ngModule = ngModuleResolver.resolve(SomeNgModule); var ngModule = ngModuleResolver.resolve(SomeNgModule);
expect(ngModule.declarations).toEqual([SomeOtherDirective]); expect(ngModule.declarations).toEqual([SomeOtherDirective]);
}); });

View File

@ -7,7 +7,7 @@
*/ */
import {NgModuleResolver} from '@angular/compiler/src/ng_module_resolver'; import {NgModuleResolver} from '@angular/compiler/src/ng_module_resolver';
import {NgModule, NgModuleMetadata} from '@angular/core/src/metadata'; import {NgModule} from '@angular/core/src/metadata';
import {stringify} from '../src/facade/lang'; import {stringify} from '../src/facade/lang';
class SomeClass1 {} class SomeClass1 {}
@ -36,7 +36,7 @@ export function main() {
it('should read out the metadata from the class', () => { it('should read out the metadata from the class', () => {
var moduleMetadata = resolver.resolve(SomeModule); var moduleMetadata = resolver.resolve(SomeModule);
expect(moduleMetadata).toEqual(new NgModuleMetadata({ expect(moduleMetadata).toEqual(new NgModule({
declarations: [SomeClass1], declarations: [SomeClass1],
imports: [SomeClass2], imports: [SomeClass2],
exports: [SomeClass3], exports: [SomeClass3],

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Injector, Pipe, PipeMetadata} from '@angular/core'; import {Injector, Pipe} from '@angular/core';
import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal'; import {beforeEach, ddescribe, describe, expect, iit, inject, it} from '@angular/core/testing/testing_internal';
import {isBlank, stringify} from '../src/facade/lang'; import {isBlank, stringify} from '../src/facade/lang';
@ -26,7 +26,7 @@ export function main() {
}); });
it('should allow overriding the @Pipe', () => { it('should allow overriding the @Pipe', () => {
pipeResolver.setPipe(SomePipe, new PipeMetadata({name: 'someOtherName'})); pipeResolver.setPipe(SomePipe, new Pipe({name: 'someOtherName'}));
var pipe = pipeResolver.resolve(SomePipe); var pipe = pipeResolver.resolve(SomePipe);
expect(pipe.name).toEqual('someOtherName'); expect(pipe.name).toEqual('someOtherName');
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {DirectiveResolver} from '@angular/compiler'; import {DirectiveResolver} from '@angular/compiler';
import {AnimationEntryMetadata, Compiler, ComponentMetadata, DirectiveMetadata, Injectable, Injector, Provider, Type, resolveForwardRef} from '@angular/core'; import {AnimationEntryMetadata, Compiler, Component, Directive, Injectable, Injector, Provider, Type, resolveForwardRef} from '@angular/core';
import {Map} from './facade/collection'; import {Map} from './facade/collection';
import {isArray, isPresent} from './facade/lang'; import {isArray, isPresent} from './facade/lang';
@ -20,7 +20,7 @@ import {ViewMetadata} from './private_import_core';
*/ */
@Injectable() @Injectable()
export class MockDirectiveResolver extends DirectiveResolver { export class MockDirectiveResolver extends DirectiveResolver {
private _directives = new Map<Type<any>, DirectiveMetadata>(); private _directives = new Map<Type<any>, Directive>();
private _providerOverrides = new Map<Type<any>, any[]>(); private _providerOverrides = new Map<Type<any>, any[]>();
private _viewProviderOverrides = new Map<Type<any>, any[]>(); private _viewProviderOverrides = new Map<Type<any>, any[]>();
private _views = new Map<Type<any>, ViewMetadata>(); private _views = new Map<Type<any>, ViewMetadata>();
@ -33,7 +33,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); } private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata { resolve(type: Type<any>, throwIfNotFound = true): Directive {
let metadata = this._directives.get(type); let metadata = this._directives.get(type);
if (!metadata) { if (!metadata) {
metadata = super.resolve(type, throwIfNotFound); metadata = super.resolve(type, throwIfNotFound);
@ -52,7 +52,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
providers = originalViewProviders.concat(providerOverrides); providers = originalViewProviders.concat(providerOverrides);
} }
if (metadata instanceof ComponentMetadata) { if (metadata instanceof Component) {
let viewProviders = metadata.viewProviders; let viewProviders = metadata.viewProviders;
if (isPresent(viewProviderOverrides)) { if (isPresent(viewProviderOverrides)) {
const originalViewProviders: Provider[] = const originalViewProviders: Provider[] =
@ -80,7 +80,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
inlineTemplate = view.template; inlineTemplate = view.template;
} }
return new ComponentMetadata({ return new Component({
selector: metadata.selector, selector: metadata.selector,
inputs: metadata.inputs, inputs: metadata.inputs,
outputs: metadata.outputs, outputs: metadata.outputs,
@ -102,7 +102,7 @@ export class MockDirectiveResolver extends DirectiveResolver {
}); });
} }
return new DirectiveMetadata({ return new Directive({
selector: metadata.selector, selector: metadata.selector,
inputs: metadata.inputs, inputs: metadata.inputs,
outputs: metadata.outputs, outputs: metadata.outputs,
@ -114,9 +114,9 @@ export class MockDirectiveResolver extends DirectiveResolver {
} }
/** /**
* Overrides the {@link DirectiveMetadata} for a directive. * Overrides the {@link Directive} for a directive.
*/ */
setDirective(type: Type<any>, metadata: DirectiveMetadata): void { setDirective(type: Type<any>, metadata: Directive): void {
this._directives.set(type, metadata); this._directives.set(type, metadata);
this._clearCacheFor(type); this._clearCacheFor(type);
} }

View File

@ -26,7 +26,7 @@ export * from './directive_resolver_mock';
export * from './ng_module_resolver_mock'; export * from './ng_module_resolver_mock';
export * from './pipe_resolver_mock'; export * from './pipe_resolver_mock';
import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModuleMetadata, NgModule, ComponentMetadata, Component, DirectiveMetadata, Directive, Pipe, Type, PlatformRef} from '@angular/core'; import {createPlatformFactory, ModuleWithComponentFactories, Injectable, CompilerOptions, COMPILER_OPTIONS, CompilerFactory, NgModuleFactory, Injector, NgModule, Component, Directive, Pipe, Type, PlatformRef} from '@angular/core';
import {MetadataOverride} from '@angular/core/testing'; import {MetadataOverride} from '@angular/core/testing';
import {TestingCompilerFactory, TestingCompiler} from './private_import_core'; import {TestingCompilerFactory, TestingCompiler} from './private_import_core';
import {platformCoreDynamic, RuntimeCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler'; import {platformCoreDynamic, RuntimeCompiler, DirectiveResolver, NgModuleResolver, PipeResolver} from '@angular/compiler';
@ -73,17 +73,17 @@ export class TestingCompilerImpl implements TestingCompiler {
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void { overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void {
const oldMetadata = this._moduleResolver.resolve(ngModule, false); const oldMetadata = this._moduleResolver.resolve(ngModule, false);
this._moduleResolver.setNgModule( this._moduleResolver.setNgModule(
ngModule, this._overrider.overrideMetadata(NgModuleMetadata, oldMetadata, override)); ngModule, this._overrider.overrideMetadata(NgModule, oldMetadata, override));
} }
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void { overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void {
const oldMetadata = this._directiveResolver.resolve(directive, false); const oldMetadata = this._directiveResolver.resolve(directive, false);
this._directiveResolver.setDirective( this._directiveResolver.setDirective(
directive, this._overrider.overrideMetadata(DirectiveMetadata, oldMetadata, override)); directive, this._overrider.overrideMetadata(Directive, oldMetadata, override));
} }
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void { overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void {
const oldMetadata = this._directiveResolver.resolve(component, false); const oldMetadata = this._directiveResolver.resolve(component, false);
this._directiveResolver.setDirective( this._directiveResolver.setDirective(
component, this._overrider.overrideMetadata(ComponentMetadata, oldMetadata, override)); component, this._overrider.overrideMetadata(Component, oldMetadata, override));
} }
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void { overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void {
const oldMetadata = this._pipeResolver.resolve(pipe, false); const oldMetadata = this._pipeResolver.resolve(pipe, false);

View File

@ -7,13 +7,13 @@
*/ */
import {NgModuleResolver} from '@angular/compiler'; import {NgModuleResolver} from '@angular/compiler';
import {Compiler, Injectable, Injector, NgModuleMetadata, Type} from '@angular/core'; import {Compiler, Injectable, Injector, NgModule, Type} from '@angular/core';
import {Map} from './facade/collection'; import {Map} from './facade/collection';
@Injectable() @Injectable()
export class MockNgModuleResolver extends NgModuleResolver { export class MockNgModuleResolver extends NgModuleResolver {
private _ngModules = new Map<Type<any>, NgModuleMetadata>(); private _ngModules = new Map<Type<any>, NgModule>();
constructor(private _injector: Injector) { super(); } constructor(private _injector: Injector) { super(); }
@ -22,20 +22,20 @@ export class MockNgModuleResolver extends NgModuleResolver {
private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); } private _clearCacheFor(component: Type<any>) { this._compiler.clearCacheFor(component); }
/** /**
* Overrides the {@link NgModuleMetadata} for a module. * Overrides the {@link NgModule} for a module.
*/ */
setNgModule(type: Type<any>, metadata: NgModuleMetadata): void { setNgModule(type: Type<any>, metadata: NgModule): void {
this._ngModules.set(type, metadata); this._ngModules.set(type, metadata);
this._clearCacheFor(type); this._clearCacheFor(type);
} }
/** /**
* Returns the {@link NgModuleMetadata} for a module: * Returns the {@link NgModule} for a module:
* - Set the {@link NgModuleMetadata} to the overridden view when it exists or fallback to the * - Set the {@link NgModule} to the overridden view when it exists or fallback to the
* default * default
* `NgModuleResolver`, see `setNgModule`. * `NgModuleResolver`, see `setNgModule`.
*/ */
resolve(type: Type<any>, throwIfNotFound = true): NgModuleMetadata { resolve(type: Type<any>, throwIfNotFound = true): NgModule {
var metadata = this._ngModules.get(type); var metadata = this._ngModules.get(type);
if (!metadata) { if (!metadata) {
metadata = super.resolve(type, throwIfNotFound); metadata = super.resolve(type, throwIfNotFound);

View File

@ -7,13 +7,13 @@
*/ */
import {PipeResolver} from '@angular/compiler'; import {PipeResolver} from '@angular/compiler';
import {Compiler, Injectable, Injector, PipeMetadata, Type} from '@angular/core'; import {Compiler, Injectable, Injector, Pipe, Type} from '@angular/core';
import {Map} from './facade/collection'; import {Map} from './facade/collection';
@Injectable() @Injectable()
export class MockPipeResolver extends PipeResolver { export class MockPipeResolver extends PipeResolver {
private _pipes = new Map<Type<any>, PipeMetadata>(); private _pipes = new Map<Type<any>, Pipe>();
constructor(private _injector: Injector) { super(); } constructor(private _injector: Injector) { super(); }
@ -22,20 +22,20 @@ export class MockPipeResolver extends PipeResolver {
private _clearCacheFor(pipe: Type<any>) { this._compiler.clearCacheFor(pipe); } private _clearCacheFor(pipe: Type<any>) { this._compiler.clearCacheFor(pipe); }
/** /**
* Overrides the {@link PipeMetadata} for a pipe. * Overrides the {@link Pipe} for a pipe.
*/ */
setPipe(type: Type<any>, metadata: PipeMetadata): void { setPipe(type: Type<any>, metadata: Pipe): void {
this._pipes.set(type, metadata); this._pipes.set(type, metadata);
this._clearCacheFor(type); this._clearCacheFor(type);
} }
/** /**
* Returns the {@link PipeMetadata} for a pipe: * Returns the {@link Pipe} for a pipe:
* - Set the {@link PipeMetadata} to the overridden view when it exists or fallback to the * - Set the {@link Pipe} to the overridden view when it exists or fallback to the
* default * default
* `PipeResolver`, see `setPipe`. * `PipeResolver`, see `setPipe`.
*/ */
resolve(type: Type<any>, throwIfNotFound = true): PipeMetadata { resolve(type: Type<any>, throwIfNotFound = true): Pipe {
var metadata = this._pipes.get(type); var metadata = this._pipes.get(type);
if (!metadata) { if (!metadata) {
metadata = super.resolve(type, throwIfNotFound); metadata = super.resolve(type, throwIfNotFound);

View File

@ -132,7 +132,7 @@ export class AnimationGroupMetadata extends AnimationWithStepsMetadata {
* `animate` is an animation-specific function that is designed to be used inside of Angular2's * `animate` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `animate` specifies an animation step that will apply the provided `styles` data for a given * `animate` specifies an animation step that will apply the provided `styles` data for a given
@ -195,7 +195,7 @@ export function animate(
* `group` is an animation-specific function that is designed to be used inside of Angular2's * `group` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `group` specifies a list of animation steps that are all run in parallel. Grouped animations * `group` specifies a list of animation steps that are all run in parallel. Grouped animations
@ -237,7 +237,7 @@ export function group(steps: AnimationMetadata[]): AnimationGroupMetadata {
* `sequence` is an animation-specific function that is designed to be used inside of Angular2's * `sequence` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `sequence` Specifies a list of animation steps that are run one by one. (`sequence` is used * `sequence` Specifies a list of animation steps that are run one by one. (`sequence` is used
@ -280,7 +280,7 @@ export function sequence(steps: AnimationMetadata[]): AnimationSequenceMetadata
* `style` is an animation-specific function that is designed to be used inside of Angular2's * `style` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `style` declares a key/value object containing CSS properties/styles that can then * `style` declares a key/value object containing CSS properties/styles that can then
@ -350,7 +350,7 @@ export function style(
* `state` is an animation-specific function that is designed to be used inside of Angular2's * `state` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `state` declares an animation state within the given trigger. When a state is * `state` declares an animation state within the given trigger. When a state is
@ -409,7 +409,7 @@ export function state(
* `keyframes` is an animation-specific function that is designed to be used inside of Angular2's * `keyframes` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `keyframes` specifies a collection of {@link style style} entries each optionally characterized * `keyframes` specifies a collection of {@link style style} entries each optionally characterized
@ -462,7 +462,7 @@ export function keyframes(steps: AnimationStyleMetadata[]): AnimationKeyframesSe
* `transition` is an animation-specific function that is designed to be used inside of Angular2's * `transition` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `transition` declares the {@link sequence sequence of animation steps} that will be run when the * `transition` declares the {@link sequence sequence of animation steps} that will be run when the
@ -557,7 +557,7 @@ export function transition(stateChangeExpr: string, steps: AnimationMetadata | A
* `trigger` is an animation-specific function that is designed to be used inside of Angular2's * `trigger` is an animation-specific function that is designed to be used inside of Angular2's
* animation * animation
* DSL language. If this information is new, please navigate to the * DSL language. If this information is new, please navigate to the
* {@link ComponentMetadata#animations-anchor component animations metadata * {@link Component#animations-anchor component animations metadata
* page} to gain a better understanding of how animations in Angular2 are used. * page} to gain a better understanding of how animations in Angular2 are used.
* *
* `trigger` Creates an animation trigger which will a list of {@link state state} and {@link * `trigger` Creates an animation trigger which will a list of {@link state state} and {@link
@ -565,7 +565,7 @@ export function transition(stateChangeExpr: string, steps: AnimationMetadata | A
* entries that will be evaluated when the expression bound to the trigger changes. * entries that will be evaluated when the expression bound to the trigger changes.
* *
* Triggers are registered within the component annotation data under the * Triggers are registered within the component annotation data under the
* {@link ComponentMetadata#animations-anchor animations section}. An animation trigger can * {@link Component#animations-anchor animations section}. An animation trigger can
* be placed on an element within a template by referencing the name of the * be placed on an element within a template by referencing the name of the
* trigger followed by the expression value that the trigger is bound to * trigger followed by the expression value that the trigger is bound to
* (in the form of `[@triggerName]="expression"`. * (in the form of `[@triggerName]="expression"`.

View File

@ -29,7 +29,7 @@ export function devModeEqual(a: any, b: any): boolean {
} }
/** /**
* Indicates that the result of a {@link PipeMetadata} transformation has changed even though the * Indicates that the result of a {@link Pipe} transformation has changed even though the
* reference * reference
* has not changed. * has not changed.
* *

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {OptionalMetadata, Provider, SkipSelfMetadata} from '../../di'; import {Optional, Provider, SkipSelf} from '../../di';
import {ListWrapper} from '../../facade/collection'; import {ListWrapper} from '../../facade/collection';
import {getTypeNameForDebugging, isBlank, isPresent} from '../../facade/lang'; import {getTypeNameForDebugging, isBlank, isPresent} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref'; import {ChangeDetectorRef} from '../change_detector_ref';
@ -91,7 +91,7 @@ export class IterableDiffers {
return IterableDiffers.create(factories, parent); return IterableDiffers.create(factories, parent);
}, },
// Dependency technically isn't optional, but we can provide a better error message this way. // Dependency technically isn't optional, but we can provide a better error message this way.
deps: [[IterableDiffers, new SkipSelfMetadata(), new OptionalMetadata()]] deps: [[IterableDiffers, new SkipSelf(), new Optional()]]
}; };
} }

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {OptionalMetadata, Provider, SkipSelfMetadata} from '../../di'; import {Optional, Provider, SkipSelf} from '../../di';
import {ListWrapper} from '../../facade/collection'; import {ListWrapper} from '../../facade/collection';
import {isBlank, isPresent} from '../../facade/lang'; import {isBlank, isPresent} from '../../facade/lang';
import {ChangeDetectorRef} from '../change_detector_ref'; import {ChangeDetectorRef} from '../change_detector_ref';
@ -81,7 +81,7 @@ export class KeyValueDiffers {
return KeyValueDiffers.create(factories, parent); return KeyValueDiffers.create(factories, parent);
}, },
// Dependency technically isn't optional, but we can provide a better error message this way. // Dependency technically isn't optional, but we can provide a better error message this way.
deps: [[KeyValueDiffers, new SkipSelfMetadata(), new OptionalMetadata()]] deps: [[KeyValueDiffers, new SkipSelf(), new Optional()]]
}; };
} }

View File

@ -14,7 +14,7 @@ import {makeParamDecorator} from '../util/decorators';
* *
* @stable * @stable
*/ */
export interface InjectMetadataFactory { export interface InjectDecorator {
/** /**
* A parameter metadata that specifies a dependency. * A parameter metadata that specifies a dependency.
* *
@ -74,7 +74,7 @@ export interface Inject { token: any; }
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Inject: InjectMetadataFactory = makeParamDecorator([['token', undefined]]); export const Inject: InjectDecorator = makeParamDecorator([['token', undefined]]);
/** /**
@ -82,7 +82,7 @@ export const Inject: InjectMetadataFactory = makeParamDecorator([['token', undef
* *
* @stable * @stable
*/ */
export interface OptionalMetadataFactory { export interface OptionalDecorator {
/** /**
* A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if * A parameter metadata that marks a dependency as optional. {@link Injector} provides `null` if
* the dependency is not found. * the dependency is not found.
@ -122,14 +122,14 @@ export interface Optional {}
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Optional: OptionalMetadataFactory = makeParamDecorator([]); export const Optional: OptionalDecorator = makeParamDecorator([]);
/** /**
* Type of the Injectable decorator / constructor function. * Type of the Injectable decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface InjectableMetadataFactory { export interface InjectableDecorator {
/** /**
* A marker metadata that marks a class as available to {@link Injector} for creation. * A marker metadata that marks a class as available to {@link Injector} for creation.
* *
@ -179,14 +179,14 @@ export interface Injectable {}
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Injectable: InjectableMetadataFactory = makeParamDecorator([]); export const Injectable: InjectableDecorator = makeParamDecorator([]);
/** /**
* Type of the Self decorator / constructor function. * Type of the Self decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface SelfMetadataFactory { export interface SelfDecorator {
/** /**
* Specifies that an {@link Injector} should retrieve a dependency only from itself. * Specifies that an {@link Injector} should retrieve a dependency only from itself.
* *
@ -232,7 +232,7 @@ export interface Self {}
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Self: SelfMetadataFactory = makeParamDecorator([]); export const Self: SelfDecorator = makeParamDecorator([]);
/** /**
@ -240,7 +240,7 @@ export const Self: SelfMetadataFactory = makeParamDecorator([]);
* *
* @stable * @stable
*/ */
export interface SkipSelfMetadataFactory { export interface SkipSelfDecorator {
/** /**
* Specifies that the dependency resolution should start from the parent injector. * Specifies that the dependency resolution should start from the parent injector.
* *
@ -284,14 +284,14 @@ export interface SkipSelf {}
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const SkipSelf: SkipSelfMetadataFactory = makeParamDecorator([]); export const SkipSelf: SkipSelfDecorator = makeParamDecorator([]);
/** /**
* Type of the Host decorator / constructor function. * Type of the Host decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface HostMetadataFactory { export interface HostDecorator {
/** /**
* Specifies that an injector should retrieve a dependency from any injector until reaching the * Specifies that an injector should retrieve a dependency from any injector until reaching the
* closest host. * closest host.
@ -362,14 +362,4 @@ export interface Host {}
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Host: HostMetadataFactory = makeParamDecorator([]); export const Host: HostDecorator = makeParamDecorator([]);
// TODO(tbosch): remove this
export {
Host as HostMetadata,
Inject as InjectMetadata,
Injectable as InjectableMetadata,
Optional as OptionalMetadata,
Self as SelfMetadata,
SkipSelf as SkipSelfMetadata
};

View File

@ -11,7 +11,7 @@ import {unimplemented} from '../facade/errors';
import {Type} from '../type'; import {Type} from '../type';
import {Injector, THROW_IF_NOT_FOUND} from './injector'; import {Injector, THROW_IF_NOT_FOUND} from './injector';
import {SelfMetadata, SkipSelfMetadata} from './metadata'; import {Self, SkipSelf} from './metadata';
import {Provider} from './provider'; import {Provider} from './provider';
import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError} from './reflective_errors'; import {AbstractProviderError, CyclicDependencyError, InstantiationError, NoProviderError, OutOfBoundsError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key'; import {ReflectiveKey} from './reflective_key';
@ -807,7 +807,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
return this; return this;
} }
if (upperBoundVisibility instanceof SelfMetadata) { if (upperBoundVisibility instanceof Self) {
return this._getByKeySelf(key, notFoundValue); return this._getByKeySelf(key, notFoundValue);
} else { } else {
@ -834,7 +834,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
_getByKeyDefault(key: ReflectiveKey, notFoundValue: any, lowerBoundVisibility: Object): any { _getByKeyDefault(key: ReflectiveKey, notFoundValue: any, lowerBoundVisibility: Object): any {
var inj: Injector; var inj: Injector;
if (lowerBoundVisibility instanceof SkipSelfMetadata) { if (lowerBoundVisibility instanceof SkipSelf) {
inj = this._parent; inj = this._parent;
} else { } else {
inj = this; inj = this;

View File

@ -12,7 +12,7 @@ import {reflector} from '../reflection/reflection';
import {Type} from '../type'; import {Type} from '../type';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
import {HostMetadata, InjectMetadata, OptionalMetadata, SelfMetadata, SkipSelfMetadata} from './metadata'; import {Host, Inject, Optional, Self, SkipSelf} from './metadata';
import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './provider'; import {ClassProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ValueProvider} from './provider';
import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_errors'; import {InvalidProviderError, MixingMultiProvidersWithRegularProvidersError, NoAnnotationError} from './reflective_errors';
import {ReflectiveKey} from './reflective_key'; import {ReflectiveKey} from './reflective_key';
@ -226,7 +226,7 @@ function _extractToken(
var optional = false; var optional = false;
if (!isArray(metadata)) { if (!isArray(metadata)) {
if (metadata instanceof InjectMetadata) { if (metadata instanceof Inject) {
return _createDependency(metadata.token, optional, null, null, depProps); return _createDependency(metadata.token, optional, null, null, depProps);
} else { } else {
return _createDependency(metadata, optional, null, null, depProps); return _createDependency(metadata, optional, null, null, depProps);
@ -242,19 +242,19 @@ function _extractToken(
if (paramMetadata instanceof Type) { if (paramMetadata instanceof Type) {
token = paramMetadata; token = paramMetadata;
} else if (paramMetadata instanceof InjectMetadata) { } else if (paramMetadata instanceof Inject) {
token = paramMetadata.token; token = paramMetadata.token;
} else if (paramMetadata instanceof OptionalMetadata) { } else if (paramMetadata instanceof Optional) {
optional = true; optional = true;
} else if (paramMetadata instanceof SelfMetadata) { } else if (paramMetadata instanceof Self) {
upperBoundVisibility = paramMetadata; upperBoundVisibility = paramMetadata;
} else if (paramMetadata instanceof HostMetadata) { } else if (paramMetadata instanceof Host) {
upperBoundVisibility = paramMetadata; upperBoundVisibility = paramMetadata;
} else if (paramMetadata instanceof SkipSelfMetadata) { } else if (paramMetadata instanceof SkipSelf) {
lowerBoundVisibility = paramMetadata; lowerBoundVisibility = paramMetadata;
} }
} }

View File

@ -14,7 +14,7 @@ import {getSymbolIterator} from '../facade/lang';
* An unmodifiable list of items that Angular keeps up to date when the state * An unmodifiable list of items that Angular keeps up to date when the state
* of the application changes. * of the application changes.
* *
* The type of object that {@link QueryMetadata} and {@link ViewQueryMetadata} provide. * The type of object that {@link Query} and {@link ViewQueryMetadata} provide.
* *
* Implements an iterable interface, therefore it can be used in both ES6 * Implements an iterable interface, therefore it can be used in both ES6
* javascript `for (var i of items)` loops as well as in Angular templates with * javascript `for (var i of items)` loops as well as in Angular templates with

View File

@ -23,21 +23,3 @@ export {Component, Directive, HostBinding, HostListener, Input, Output, Pipe} fr
export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks'; export {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, DoCheck, OnChanges, OnDestroy, OnInit} from './metadata/lifecycle_hooks';
export {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module'; export {CUSTOM_ELEMENTS_SCHEMA, ModuleWithProviders, NO_ERRORS_SCHEMA, NgModule, SchemaMetadata} from './metadata/ng_module';
export {ViewEncapsulation} from './metadata/view'; export {ViewEncapsulation} from './metadata/view';
// TODO(vicb): delete ?
export {Directive as DirectiveMetadata};
export {Component as ComponentMetadata};
export {NgModule as NgModuleMetadata};
export {Pipe as PipeMetadata};
export {Output as OutputMetadata};
export {Input as InputMetadata};
export {HostBinding as HostBindingMetadata};
export {HostListener as HostListenerMetadata};
export {Attribute as AttributeMetadata};
export {ContentChildren as ContentChildrenMetadata};
export {ContentChild as ContentChildMetadata};
export {ViewChildren as ViewChildrenMetadata};
export {ViewChild as ViewChildMetadata};
export {Query as QueryMetadata};

View File

@ -54,7 +54,7 @@ export const ANALYZE_FOR_ENTRY_COMPONENTS = new OpaqueToken('AnalyzeForEntryComp
* *
* @stable * @stable
*/ */
export interface AttributeMetadataFactory { export interface AttributeDecorator {
/** /**
* Specifies that a constant attribute value should be injected. * Specifies that a constant attribute value should be injected.
* *
@ -122,8 +122,7 @@ export interface Attribute { attributeName?: string; }
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Attribute: AttributeMetadataFactory = export const Attribute: AttributeDecorator = makeParamDecorator([['attributeName', undefined]]);
makeParamDecorator([['attributeName', undefined]]);
/** /**
* Type of the Query metadata. * Type of the Query metadata.
@ -145,7 +144,7 @@ export abstract class Query {}
* *
* @stable * @stable
*/ */
export interface ContentChildrenMetadataFactory { export interface ContentChildrenDecorator {
/** /**
* Configures a content query. * Configures a content query.
* *
@ -187,7 +186,7 @@ export type ContentChildren = Query;
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const ContentChildren: ContentChildrenMetadataFactory = makePropDecorator( export const ContentChildren: ContentChildrenDecorator = makePropDecorator(
[ [
['selector', undefined], ['selector', undefined],
{first: false, isViewQuery: false, descendants: false, read: undefined} {first: false, isViewQuery: false, descendants: false, read: undefined}
@ -199,7 +198,7 @@ export const ContentChildren: ContentChildrenMetadataFactory = makePropDecorator
* *
* @stable * @stable
*/ */
export interface ContentChildMetadataFactory { export interface ContentChildDecorator {
/** /**
* Configures a content query. * Configures a content query.
* *
@ -246,7 +245,7 @@ export type ContentChild = Query;
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const ContentChild: ContentChildMetadataFactory = makePropDecorator( export const ContentChild: ContentChildDecorator = makePropDecorator(
[ [
['selector', undefined], { ['selector', undefined], {
first: true, first: true,
@ -258,11 +257,11 @@ export const ContentChild: ContentChildMetadataFactory = makePropDecorator(
Query); Query);
/** /**
* Type of the ViewChildrenMetadataFactory decorator / constructor function. * Type of the ViewChildren decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface ViewChildrenMetadataFactory { export interface ViewChildrenDecorator {
/** /**
* Declares a list of child element references. * Declares a list of child element references.
* *
@ -357,7 +356,7 @@ export type ViewChildren = Query;
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const ViewChildren: ViewChildrenMetadataFactory = makePropDecorator( export const ViewChildren: ViewChildrenDecorator = makePropDecorator(
[ [
['selector', undefined], { ['selector', undefined], {
first: false, first: false,
@ -370,11 +369,11 @@ export const ViewChildren: ViewChildrenMetadataFactory = makePropDecorator(
/** /**
* Type of the ViewChildMetadataFactory decorator / constructor function. * Type of the ViewChild decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface ViewChildMetadataFactory { export interface ViewChildDecorator {
/** /**
* *
* Declares a reference of child element. * Declares a reference of child element.
@ -462,7 +461,7 @@ export type ViewChild = Query;
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const ViewChild: ViewChildMetadataFactory = makePropDecorator( export const ViewChild: ViewChildDecorator = makePropDecorator(
[ [
['selector', undefined], { ['selector', undefined], {
first: true, first: true,

View File

@ -8,7 +8,7 @@
import {AnimationEntryMetadata} from '../animation/metadata'; import {AnimationEntryMetadata} from '../animation/metadata';
import {ChangeDetectionStrategy} from '../change_detection/constants'; import {ChangeDetectionStrategy} from '../change_detection/constants';
import {InjectableMetadata, Provider} from '../di'; import {Injectable, Provider} from '../di';
import {isPresent} from '../facade/lang'; import {isPresent} from '../facade/lang';
import {Type} from '../type'; import {Type} from '../type';
import {TypeDecorator, makeDecorator, makePropDecorator} from '../util/decorators'; import {TypeDecorator, makeDecorator, makePropDecorator} from '../util/decorators';
@ -21,11 +21,11 @@ import {ViewEncapsulation} from './view';
* *
* @stable * @stable
*/ */
export interface DirectiveMetadataFactory { export interface DirectiveDecorator {
/** /**
* Directives allow you to attach behavior to elements in the DOM. * Directives allow you to attach behavior to elements in the DOM.
* *
* {@link DirectiveMetadata}s with an embedded view are called {@link ComponentMetadata}s. * {@link Directive}s with an embedded view are called {@link Component}s.
* *
* A directive consists of a single directive annotation and a controller class. When the * A directive consists of a single directive annotation and a controller class. When the
* directive's `selector` matches * directive's `selector` matches
@ -59,7 +59,7 @@ export interface DirectiveMetadataFactory {
* *
* Angular then resolves dependencies as follows, according to the order in which they appear in * Angular then resolves dependencies as follows, according to the order in which they appear in
* the * the
* {@link ComponentMetadata}: * {@link Component}:
* *
* 1. Dependencies on the current element * 1. Dependencies on the current element
* 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM * 2. Dependencies on element injectors and their parents until it encounters a Shadow DOM
@ -85,7 +85,7 @@ export interface DirectiveMetadataFactory {
* To inject element-specific special objects, declare the constructor parameter as: * To inject element-specific special objects, declare the constructor parameter as:
* - `element: ElementRef` to obtain a reference to logical element in the view. * - `element: ElementRef` to obtain a reference to logical element in the view.
* - `viewContainer: ViewContainerRef` to control child template instantiation, for * - `viewContainer: ViewContainerRef` to control child template instantiation, for
* {@link DirectiveMetadata} directives only * {@link Directive} directives only
* - `bindingPropagation: BindingPropagation` to control change detection in a more granular way. * - `bindingPropagation: BindingPropagation` to control change detection in a more granular way.
* *
* ### Example * ### Example
@ -311,7 +311,7 @@ export interface DirectiveMetadataFactory {
* location in the current view * location in the current view
* where these actions are performed. * where these actions are performed.
* *
* Views are always created as children of the current {@link ComponentMetadata}, and as siblings * Views are always created as children of the current {@link Component}, and as siblings
* of * of
* the * the
* `<template>` element. Thus a * `<template>` element. Thus a
@ -770,7 +770,7 @@ export interface Directive {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Directive: DirectiveMetadataFactory = <DirectiveMetadataFactory>makeDecorator({ export const Directive: DirectiveDecorator = <DirectiveDecorator>makeDecorator({
selector: undefined, selector: undefined,
inputs: undefined, inputs: undefined,
outputs: undefined, outputs: undefined,
@ -785,7 +785,7 @@ export const Directive: DirectiveMetadataFactory = <DirectiveMetadataFactory>mak
* *
* @stable * @stable
*/ */
export interface ComponentMetadataFactory { export interface ComponentDecorator {
/** /**
* Declare reusable UI building blocks for an application. * Declare reusable UI building blocks for an application.
* *
@ -1050,7 +1050,7 @@ export interface Component extends Directive {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Component: ComponentMetadataFactory = <ComponentMetadataFactory>makeDecorator( export const Component: ComponentDecorator = <ComponentDecorator>makeDecorator(
{ {
selector: undefined, selector: undefined,
inputs: undefined, inputs: undefined,
@ -1078,7 +1078,7 @@ export const Component: ComponentMetadataFactory = <ComponentMetadataFactory>mak
* *
* @stable * @stable
*/ */
export interface PipeMetadataFactory { export interface PipeDecorator {
/** /**
* Declare reusable pipe function. * Declare reusable pipe function.
* *
@ -1110,7 +1110,7 @@ export interface Pipe {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Pipe: PipeMetadataFactory = <PipeMetadataFactory>makeDecorator({ export const Pipe: PipeDecorator = <PipeDecorator>makeDecorator({
name: undefined, name: undefined,
pure: true, pure: true,
}); });
@ -1121,13 +1121,13 @@ export const Pipe: PipeMetadataFactory = <PipeMetadataFactory>makeDecorator({
* *
* @stable * @stable
*/ */
export interface InputMetadataFactory { export interface InputDecorator {
/** /**
* Declares a data-bound input property. * Declares a data-bound input property.
* *
* Angular automatically updates data-bound properties during change detection. * Angular automatically updates data-bound properties during change detection.
* *
* `InputMetadata` takes an optional parameter that specifies the name * `Input` takes an optional parameter that specifies the name
* used when instantiating a component in the template. When not provided, * used when instantiating a component in the template. When not provided,
* the name of the decorated property is used. * the name of the decorated property is used.
* *
@ -1184,21 +1184,21 @@ export interface Input {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Input: InputMetadataFactory = makePropDecorator([['bindingPropertyName', undefined]]); export const Input: InputDecorator = makePropDecorator([['bindingPropertyName', undefined]]);
/** /**
* Type of the Output decorator / constructor function. * Type of the Output decorator / constructor function.
* *
* @stable * @stable
*/ */
export interface OutputMetadataFactory { export interface OutputDecorator {
/** /**
* Declares an event-bound output property. * Declares an event-bound output property.
* *
* When an output property emits an event, an event handler attached to that event * When an output property emits an event, an event handler attached to that event
* the template is invoked. * the template is invoked.
* *
* `OutputMetadata` takes an optional parameter that specifies the name * `Output` takes an optional parameter that specifies the name
* used when instantiating a component in the template. When not provided, * used when instantiating a component in the template. When not provided,
* the name of the decorated property is used. * the name of the decorated property is used.
* *
@ -1249,8 +1249,7 @@ export interface Output { bindingPropertyName?: string; }
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const Output: OutputMetadataFactory = export const Output: OutputDecorator = makePropDecorator([['bindingPropertyName', undefined]]);
makePropDecorator([['bindingPropertyName', undefined]]);
/** /**
@ -1258,14 +1257,14 @@ export const Output: OutputMetadataFactory =
* *
* @stable * @stable
*/ */
export interface HostBindingMetadataFactory { export interface HostBindingDecorator {
/** /**
* Declares a host property binding. * Declares a host property binding.
* *
* Angular automatically checks host property bindings during change detection. * Angular automatically checks host property bindings during change detection.
* If a binding changes, it will update the host element of the directive. * If a binding changes, it will update the host element of the directive.
* *
* `HostBindingMetadata` takes an optional parameter that specifies the property * `HostBinding` takes an optional parameter that specifies the property
* name of the host element that will be updated. When not provided, * name of the host element that will be updated. When not provided,
* the class property name is used. * the class property name is used.
* *
@ -1310,7 +1309,7 @@ export interface HostBinding { hostPropertyName?: string; }
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const HostBinding: HostBindingMetadataFactory = export const HostBinding: HostBindingDecorator =
makePropDecorator([['hostPropertyName', undefined]]); makePropDecorator([['hostPropertyName', undefined]]);
@ -1319,7 +1318,7 @@ export const HostBinding: HostBindingMetadataFactory =
* *
* @stable * @stable
*/ */
export interface HostListenerMetadataFactory { export interface HostListenerDecorator {
/** /**
* Declares a host listener. * Declares a host listener.
* *
@ -1374,5 +1373,5 @@ export interface HostListener {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const HostListener: HostListenerMetadataFactory = export const HostListener: HostListenerDecorator =
makePropDecorator([['eventName', undefined], ['args', []]]); makePropDecorator([['eventName', undefined], ['args', []]]);

View File

@ -236,7 +236,7 @@ export abstract class DoCheck { abstract ngDoCheck(): void; }
* *
* *
* To create a stateful Pipe, you should implement this interface and set the `pure` * To create a stateful Pipe, you should implement this interface and set the `pure`
* parameter to `false` in the {@link PipeMetadata}. * parameter to `false` in the {@link Pipe}.
* *
* A stateful pipe may produce different output, given the same input. It is * A stateful pipe may produce different output, given the same input. It is
* likely that a stateful pipe may contain state that should be cleaned up when * likely that a stateful pipe may contain state that should be cleaned up when

View File

@ -54,7 +54,7 @@ export const NO_ERRORS_SCHEMA: SchemaMetadata = {
* *
* @stable * @stable
*/ */
export interface NgModuleMetadataFactory { export interface NgModuleDecorator {
/** /**
* Defines an NgModule. * Defines an NgModule.
*/ */
@ -191,7 +191,7 @@ export interface NgModule {
* @stable * @stable
* @Annotation * @Annotation
*/ */
export const NgModule: NgModuleMetadataFactory = <NgModuleMetadataFactory>makeDecorator({ export const NgModule: NgModuleDecorator = <NgModuleDecorator>makeDecorator({
providers: undefined, providers: undefined,
declarations: undefined, declarations: undefined,
imports: undefined, imports: undefined,

View File

@ -53,7 +53,7 @@ export var VIEW_ENCAPSULATION_VALUES =
* When a component is instantiated, the template is loaded into the component's shadow root, and * When a component is instantiated, the template is loaded into the component's shadow root, and
* the expressions and statements in the template are evaluated against the component. * the expressions and statements in the template are evaluated against the component.
* *
* For details on the `@Component` annotation, see {@link ComponentMetadata}. * For details on the `@Component` annotation, see {@link Component}.
* *
* ### Example * ### Example
* *
@ -72,7 +72,7 @@ export var VIEW_ENCAPSULATION_VALUES =
* } * }
* ``` * ```
* *
* @deprecated Use ComponentMetadata instead. * @deprecated Use Component instead.
*/ */
export class ViewMetadata { export class ViewMetadata {
/** /**

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Inject, InjectMetadata, Injectable, Injector, Optional, Provider, ReflectiveInjector, ReflectiveKey, SelfMetadata, forwardRef} from '@angular/core'; import {Inject, Injectable, Injector, Optional, Provider, ReflectiveInjector, ReflectiveKey, Self, forwardRef} from '@angular/core';
import {ReflectiveInjectorDynamicStrategy, ReflectiveInjectorInlineStrategy, ReflectiveInjector_, ReflectiveProtoInjector} from '@angular/core/src/di/reflective_injector'; import {ReflectiveInjectorDynamicStrategy, ReflectiveInjectorInlineStrategy, ReflectiveInjector_, ReflectiveProtoInjector} from '@angular/core/src/di/reflective_injector';
import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider'; import {ResolvedReflectiveProvider_} from '@angular/core/src/di/reflective_provider';
import {expect} from '@angular/platform-browser/testing/matchers'; import {expect} from '@angular/platform-browser/testing/matchers';
@ -423,11 +423,8 @@ export function main() {
describe('@Self()', () => { describe('@Self()', () => {
it('should return a dependency from self', () => { it('should return a dependency from self', () => {
var inj = ReflectiveInjector.resolveAndCreate([ var inj = ReflectiveInjector.resolveAndCreate([
Engine, { Engine,
provide: Car, {provide: Car, useFactory: (e: Engine) => new Car(e), deps: [[Engine, new Self()]]}
useFactory: (e: Engine) => new Car(e),
deps: [[Engine, new SelfMetadata()]]
}
]); ]);
expect(inj.get(Car)).toBeAnInstanceOf(Car); expect(inj.get(Car)).toBeAnInstanceOf(Car);
@ -435,11 +432,9 @@ export function main() {
it('should throw when not requested provider on self', () => { it('should throw when not requested provider on self', () => {
var parent = ReflectiveInjector.resolveAndCreate([Engine]); var parent = ReflectiveInjector.resolveAndCreate([Engine]);
var child = parent.resolveAndCreateChild([{ var child = parent.resolveAndCreateChild([
provide: Car, {provide: Car, useFactory: (e: Engine) => new Car(e), deps: [[Engine, new Self()]]}
useFactory: (e: Engine) => new Car(e), ]);
deps: [[Engine, new SelfMetadata()]]
}]);
expect(() => child.get(Car)) expect(() => child.get(Car))
.toThrowError(`No provider for Engine! (${stringify(Car)} -> ${stringify(Engine)})`); .toThrowError(`No provider for Engine! (${stringify(Car)} -> ${stringify(Engine)})`);
@ -536,7 +531,7 @@ export function main() {
var providers = ReflectiveInjector.resolve([{ var providers = ReflectiveInjector.resolve([{
provide: 'token', provide: 'token',
useFactory: (e: any /** TODO #9100 */) => 'result', useFactory: (e: any /** TODO #9100 */) => 'result',
deps: [[new InjectMetadata('dep')]] deps: [[new Inject('dep')]]
}]); }]);
var provider = providers[0]; var provider = providers[0];
@ -546,9 +541,9 @@ export function main() {
it('should allow declaring dependencies with flat arrays', () => { it('should allow declaring dependencies with flat arrays', () => {
var resolved = ReflectiveInjector.resolve( var resolved = ReflectiveInjector.resolve(
[{provide: 'token', useFactory: (e: any) => e, deps: [new InjectMetadata('dep')]}]); [{provide: 'token', useFactory: (e: any) => e, deps: [new Inject('dep')]}]);
var nestedResolved = ReflectiveInjector.resolve( var nestedResolved = ReflectiveInjector.resolve(
[{provide: 'token', useFactory: (e: any) => e, deps: [[new InjectMetadata('dep')]]}]); [{provide: 'token', useFactory: (e: any) => e, deps: [[new Inject('dep')]]}]);
expect(resolved[0].resolvedFactories[0].dependencies[0].key.token) expect(resolved[0].resolvedFactories[0].dependencies[0].key.token)
.toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token); .toEqual(nestedResolved[0].resolvedFactories[0].dependencies[0].key.token);
}); });

View File

@ -8,7 +8,7 @@
import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry'; import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry';
import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/test_bindings'; import {TEST_COMPILER_PROVIDERS} from '@angular/compiler/testing/test_bindings';
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ComponentMetadata, DebugElement, Directive, DoCheck, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewContainerRef, WrappedValue, forwardRef} from '@angular/core'; import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, DoCheck, Injectable, Input, OnChanges, OnDestroy, OnInit, Output, Pipe, PipeTransform, RenderComponentType, Renderer, RootRenderer, SimpleChange, SimpleChanges, TemplateRef, Type, ViewContainerRef, WrappedValue, forwardRef} from '@angular/core';
import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer'; import {DebugDomRenderer} from '@angular/core/src/debug/debug_renderer';
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {By} from '@angular/platform-browser/src/dom/debug/by'; import {By} from '@angular/platform-browser/src/dom/debug/by';
@ -29,7 +29,7 @@ export function main() {
function createCompFixture<T>(template: string, compType: Type<T>): ComponentFixture<T>; function createCompFixture<T>(template: string, compType: Type<T>): ComponentFixture<T>;
function createCompFixture<T>( function createCompFixture<T>(
template: string, compType: Type<T> = <any>TestComponent): ComponentFixture<T> { template: string, compType: Type<T> = <any>TestComponent): ComponentFixture<T> {
TestBed.overrideComponent(compType, {set: new ComponentMetadata({template})}); TestBed.overrideComponent(compType, {set: new Component({template})});
initHelpers(); initHelpers();
@ -655,7 +655,7 @@ export function main() {
describe('lifecycle', () => { describe('lifecycle', () => {
function createCompWithContentAndViewChild(): ComponentFixture<any> { function createCompWithContentAndViewChild(): ComponentFixture<any> {
TestBed.overrideComponent(AnotherComponent, { TestBed.overrideComponent(AnotherComponent, {
set: new ComponentMetadata({ set: new Component({
selector: 'other-cmp', selector: 'other-cmp',
template: '<div testDirective="viewChild"></div>', template: '<div testDirective="viewChild"></div>',
}) })
@ -1003,7 +1003,7 @@ export function main() {
it('should be called after processing the content and view children', fakeAsync(() => { it('should be called after processing the content and view children', fakeAsync(() => {
TestBed.overrideComponent(AnotherComponent, { TestBed.overrideComponent(AnotherComponent, {
set: new ComponentMetadata( set: new Component(
{selector: 'other-cmp', template: '<div testDirective="viewChild"></div>'}) {selector: 'other-cmp', template: '<div testDirective="viewChild"></div>'})
}); });

View File

@ -7,7 +7,7 @@
*/ */
import {CommonModule} from '@angular/common'; import {CommonModule} from '@angular/common';
import {ComponentFactory, Host, Inject, Injectable, Injector, NO_ERRORS_SCHEMA, NgModule, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf, SkipSelfMetadata} from '@angular/core'; import {ComponentFactory, Host, Inject, Injectable, Injector, NO_ERRORS_SCHEMA, NgModule, OnDestroy, OpaqueToken, ReflectiveInjector, SkipSelf} from '@angular/core';
import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection'; import {ChangeDetectionStrategy, ChangeDetectorRef, PipeTransform} from '@angular/core/src/change_detection/change_detection';
import {ComponentFactoryResolver} from '@angular/core/src/linker/component_factory_resolver'; import {ComponentFactoryResolver} from '@angular/core/src/linker/component_factory_resolver';
import {ElementRef} from '@angular/core/src/linker/element_ref'; import {ElementRef} from '@angular/core/src/linker/element_ref';
@ -2045,9 +2045,7 @@ function createParentBus(peb: EventBus) {
@Component({ @Component({
selector: 'parent-providing-event-bus', selector: 'parent-providing-event-bus',
providers: [ providers: [{provide: EventBus, useFactory: createParentBus, deps: [[EventBus, new SkipSelf()]]}],
{provide: EventBus, useFactory: createParentBus, deps: [[EventBus, new SkipSelfMetadata()]]}
],
template: `<child-consuming-event-bus></child-consuming-event-bus>` template: `<child-consuming-event-bus></child-consuming-event-bus>`
}) })
class ParentProvidingEventBus { class ParentProvidingEventBus {

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, SelfMetadata, Type, forwardRef, getModuleFactory} from '@angular/core'; import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, Self, Type, forwardRef, getModuleFactory} from '@angular/core';
import {Console} from '@angular/core/src/console'; import {Console} from '@angular/core/src/console';
import {ComponentFixture, TestBed, inject} from '@angular/core/testing'; import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers'; import {expect} from '@angular/platform-browser/testing/matchers';
@ -833,11 +833,8 @@ function declareTests({useJit}: {useJit: boolean}) {
describe('@Self()', () => { describe('@Self()', () => {
it('should return a dependency from self', () => { it('should return a dependency from self', () => {
var inj = createInjector([ var inj = createInjector([
Engine, { Engine,
provide: Car, {provide: Car, useFactory: (e: Engine) => new Car(e), deps: [[Engine, new Self()]]}
useFactory: (e: Engine) => new Car(e),
deps: [[Engine, new SelfMetadata()]]
}
]); ]);
expect(inj.get(Car)).toBeAnInstanceOf(Car); expect(inj.get(Car)).toBeAnInstanceOf(Car);
@ -847,7 +844,7 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(() => createInjector([{ expect(() => createInjector([{
provide: Car, provide: Car,
useFactory: (e: Engine) => new Car(e), useFactory: (e: Engine) => new Car(e),
deps: [[Engine, new SelfMetadata()]] deps: [[Engine, new Self()]]
}])) }]))
.toThrowError(/No provider for Engine/g); .toThrowError(/No provider for Engine/g);
}); });

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, InjectMetadata, Input, Optional, Pipe, PipeTransform, Provider, Self, SkipSelfMetadata, TemplateRef, Type, ViewContainerRef, forwardRef} from '@angular/core'; import {Attribute, ChangeDetectionStrategy, ChangeDetectorRef, Component, DebugElement, Directive, ElementRef, Host, Inject, Input, Optional, Pipe, PipeTransform, Provider, Self, SkipSelf, TemplateRef, Type, ViewContainerRef, forwardRef} from '@angular/core';
import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing'; import {ComponentFixture, TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal'; import {beforeEach, beforeEachProviders, ddescribe, describe, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter'; import {getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
@ -266,7 +266,7 @@ export function main() {
{provide: 'injectable1', useValue: 'new-injectable1'}, { {provide: 'injectable1', useValue: 'new-injectable1'}, {
provide: 'injectable2', provide: 'injectable2',
useFactory: (val: any) => `${val}-injectable2`, useFactory: (val: any) => `${val}-injectable2`,
deps: [[new InjectMetadata('injectable1'), new SkipSelfMetadata()]] deps: [[new Inject('injectable1'), new SkipSelf()]]
} }
] ]
} }

View File

@ -7,7 +7,7 @@
*/ */
import {DirectiveResolver} from '@angular/compiler'; import {DirectiveResolver} from '@angular/compiler';
import {DirectiveMetadata, Type} from '@angular/core'; import {Directive, Type} from '@angular/core';
var COMPONENT_SELECTOR = /^[\w|-]*$/; var COMPONENT_SELECTOR = /^[\w|-]*$/;
var SKEWER_CASE = /-(\w)/g; var SKEWER_CASE = /-(\w)/g;
@ -32,7 +32,7 @@ export interface ComponentInfo {
} }
export function getComponentInfo(type: Type<any>): ComponentInfo { export function getComponentInfo(type: Type<any>): ComponentInfo {
var resolvedMetadata: DirectiveMetadata = directiveResolver.resolve(type); var resolvedMetadata: Directive = directiveResolver.resolve(type);
var selector = resolvedMetadata.selector; var selector = resolvedMetadata.selector;
if (!selector.match(COMPONENT_SELECTOR)) { if (!selector.match(COMPONENT_SELECTOR)) {
throw new Error('Only selectors matching element names are supported, got: ' + selector); throw new Error('Only selectors matching element names are supported, got: ' + selector);