Permalink
Browse files

refactor(core): remove `…Metadata` for all decorators and use the dec…

…orator 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.
  • Loading branch information...
tbosch authored and IgorMinar committed Sep 13, 2016
1 parent 1b15170 commit 63e15ffaec239fffc7e7df7b49222d4111a9a5c7
Showing with 229 additions and 279 deletions.
  1. +3 −3 modules/@angular/compiler-cli/src/codegen.ts
  2. +3 −3 modules/@angular/compiler-cli/src/extract_i18n.ts
  3. +24 −31 modules/@angular/compiler-cli/src/static_reflector.ts
  4. +2 −2 modules/@angular/compiler-cli/test/static_reflector_spec.ts
  5. +3 −3 modules/@angular/compiler/src/compiler.ts
  6. +21 −21 modules/@angular/compiler/src/directive_resolver.ts
  7. +17 −18 modules/@angular/compiler/src/metadata_resolver.ts
  8. +6 −7 modules/@angular/compiler/src/ng_module_resolver.ts
  9. +5 −5 modules/@angular/compiler/src/pipe_resolver.ts
  10. +1 −1 modules/@angular/compiler/src/runtime_compiler.ts
  11. +1 −1 modules/@angular/compiler/test/directive_lifecycle_spec.ts
  12. +8 −9 modules/@angular/compiler/test/directive_resolver_mock_spec.ts
  13. +4 −4 modules/@angular/compiler/test/directive_resolver_spec.ts
  14. +2 −2 modules/@angular/compiler/test/ng_module_resolver_mock_spec.ts
  15. +2 −2 modules/@angular/compiler/test/ng_module_resolver_spec.ts
  16. +2 −2 modules/@angular/compiler/test/pipe_resolver_mock_spec.ts
  17. +8 −8 modules/@angular/compiler/testing/directive_resolver_mock.ts
  18. +4 −4 modules/@angular/compiler/testing/index.ts
  19. +7 −7 modules/@angular/compiler/testing/ng_module_resolver_mock.ts
  20. +7 −7 modules/@angular/compiler/testing/pipe_resolver_mock.ts
  21. +9 −9 modules/@angular/core/src/animation/metadata.ts
  22. +1 −1 modules/@angular/core/src/change_detection/change_detection_util.ts
  23. +2 −2 modules/@angular/core/src/change_detection/differs/iterable_differs.ts
  24. +2 −2 modules/@angular/core/src/change_detection/differs/keyvalue_differs.ts
  25. +12 −22 modules/@angular/core/src/di/metadata.ts
  26. +3 −3 modules/@angular/core/src/di/reflective_injector.ts
  27. +7 −7 modules/@angular/core/src/di/reflective_provider.ts
  28. +1 −1 modules/@angular/core/src/linker/query_list.ts
  29. +0 −18 modules/@angular/core/src/metadata.ts
  30. +12 −13 modules/@angular/core/src/metadata/di.ts
  31. +22 −23 modules/@angular/core/src/metadata/directives.ts
  32. +1 −1 modules/@angular/core/src/metadata/lifecycle_hooks.ts
  33. +2 −2 modules/@angular/core/src/metadata/ng_module.ts
  34. +2 −2 modules/@angular/core/src/metadata/view.ts
  35. +9 −14 modules/@angular/core/test/di/reflective_injector_spec.ts
  36. +4 −4 modules/@angular/core/test/linker/change_detection_integration_spec.ts
  37. +2 −4 modules/@angular/core/test/linker/integration_spec.ts
  38. +4 −7 modules/@angular/core/test/linker/ng_module_integration_spec.ts
  39. +2 −2 modules/@angular/core/test/linker/view_injector_integration_spec.ts
  40. +2 −2 modules/@angular/upgrade/src/metadata.ts
@@ -11,7 +11,7 @@
* Intended to be used in a build step.
*/
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 * as path from 'path';
import * as ts from 'typescript';
@@ -62,9 +62,9 @@ export class CodeGenerator {
const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath);
const annotations = this.staticReflector.annotations(staticType);
annotations.forEach((annotation) => {
- if (annotation instanceof NgModuleMetadata) {
+ if (annotation instanceof NgModule) {
result.ngModules.push(staticType);
- } else if (annotation instanceof ComponentMetadata) {
+ } else if (annotation instanceof Component) {
result.components.push(staticType);
}
});
@@ -17,7 +17,7 @@
import 'reflect-metadata';
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 ts from 'typescript';
import * as tsc from '@angular/tsc-wrapped';
@@ -87,9 +87,9 @@ export class Extractor {
const staticType = this.reflectorHost.findDeclaration(absSourcePath, symbol, absSourcePath);
const annotations = this.staticReflector.annotations(staticType);
annotations.forEach((annotation) => {
- if (annotation instanceof NgModuleMetadata) {
+ if (annotation instanceof NgModule) {
result.ngModules.push(staticType);
- } else if (annotation instanceof ComponentMetadata) {
+ } else if (annotation instanceof Component) {
result.components.push(staticType);
}
});
@@ -6,7 +6,7 @@
* 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';
@@ -181,54 +181,47 @@ export class StaticReflector implements ReflectorReader {
this.host.angularImportLocations();
this.opaqueToken = this.host.findDeclaration(diOpaqueToken, 'OpaqueToken');
+ this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Host'), Host);
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.host.findDeclaration(diDecorators, 'Injectable'), InjectableMetadata);
+ this.host.findDeclaration(diDecorators, 'SkipSelf'), SkipSelf);
+ this.registerDecoratorOrConstructor(this.host.findDeclaration(diDecorators, 'Inject'), Inject);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diDecorators, 'Self'), SelfMetadata);
+ this.host.findDeclaration(diDecorators, 'Optional'), Optional);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diDecorators, 'SkipSelf'), SkipSelfMetadata);
+ this.host.findDeclaration(coreDecorators, 'Attribute'), Attribute);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diDecorators, 'Inject'), InjectMetadata);
+ this.host.findDeclaration(coreDecorators, 'ContentChild'), ContentChild);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diDecorators, 'Optional'), OptionalMetadata);
+ this.host.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildren);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'Attribute'), AttributeMetadata);
+ this.host.findDeclaration(coreDecorators, 'ViewChild'), ViewChild);
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.host.findDeclaration(coreDecorators, 'ContentChildren'), ContentChildrenMetadata);
+ this.host.findDeclaration(coreDecorators, 'Output'), Output);
+ this.registerDecoratorOrConstructor(this.host.findDeclaration(coreDecorators, 'Pipe'), Pipe);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'ViewChild'), ViewChildMetadata);
+ this.host.findDeclaration(coreDecorators, 'HostBinding'), HostBinding);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'ViewChildren'), ViewChildrenMetadata);
+ this.host.findDeclaration(coreDecorators, 'HostListener'), HostListener);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'Input'), InputMetadata);
+ this.host.findDeclaration(coreDecorators, 'Directive'), Directive);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'Output'), OutputMetadata);
+ this.host.findDeclaration(coreDecorators, 'Component'), Component);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(coreDecorators, 'Pipe'), PipeMetadata);
- 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);
+ this.host.findDeclaration(coreDecorators, 'NgModule'), NgModule);
// 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.host.findDeclaration(diMetadata, 'HostMetadata'), HostMetadata);
- this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diMetadata, 'SelfMetadata'), SelfMetadata);
- this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diMetadata, 'SkipSelfMetadata'), SkipSelfMetadata);
+ this.host.findDeclaration(diMetadata, 'SkipSelf'), SkipSelf);
this.registerDecoratorOrConstructor(
- this.host.findDeclaration(diMetadata, 'OptionalMetadata'), OptionalMetadata);
+ this.host.findDeclaration(diMetadata, 'Optional'), Optional);
this.registerFunction(this.host.findDeclaration(animationMetadata, 'trigger'), trigger);
this.registerFunction(this.host.findDeclaration(animationMetadata, 'state'), state);
@@ -7,7 +7,7 @@
*/
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 {isBlank} from '@angular/facade/src/lang';
import {MetadataCollector} from '@angular/tsc-wrapped';
@@ -92,7 +92,7 @@ describe('StaticReflector', () => {
host.findDeclaration('src/app/hero-detail.component', 'HeroDetailComponent');
let props = reflector.propMetadata(HeroDetailComponent);
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', () => {
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
-import {COMPILER_OPTIONS, ClassProvider, Compiler, CompilerFactory, CompilerOptions, Component, ExistingProvider, FactoryProvider, Inject, Injectable, OptionalMetadata, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, TypeProvider, ValueProvider, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
+import {COMPILER_OPTIONS, ClassProvider, Compiler, CompilerFactory, CompilerOptions, Component, ExistingProvider, FactoryProvider, Inject, Injectable, Optional, PLATFORM_INITIALIZER, PlatformRef, Provider, ReflectiveInjector, TRANSLATIONS, TRANSLATIONS_FORMAT, Type, TypeProvider, ValueProvider, ViewEncapsulation, createPlatformFactory, isDevMode, platformCore} from '@angular/core';
export * from './template_parser/template_ast';
export {TEMPLATE_TRANSFORMS} from './template_parser/template_parser';
@@ -66,8 +66,8 @@ export const COMPILER_PROVIDERS: Array<any|Type<any>|{[k: string]: any}|any[]> =
new i18n.I18NHtmlParser(parser, translations, format),
deps: [
HtmlParser,
- [new OptionalMetadata(), new Inject(TRANSLATIONS)],
- [new OptionalMetadata(), new Inject(TRANSLATIONS_FORMAT)],
+ [new Optional(), new Inject(TRANSLATIONS)],
+ [new Optional(), new Inject(TRANSLATIONS_FORMAT)],
]
},
TemplateParser,
@@ -6,19 +6,19 @@
* found in the LICENSE file at https://angular.io/license
*/
-import {ComponentMetadata, DirectiveMetadata, HostBindingMetadata, HostListenerMetadata, Injectable, InputMetadata, OutputMetadata, QueryMetadata, Type, resolveForwardRef} from '@angular/core';
+import {Component, Directive, HostBinding, HostListener, Injectable, Input, Output, Query, Type, resolveForwardRef} from '@angular/core';
import {StringMapWrapper} from './facade/collection';
import {isPresent, stringify} from './facade/lang';
import {ReflectorReader, reflector} from './private_import_core';
import {splitAtColon} from './util';
-function _isDirectiveMetadata(type: any): type is DirectiveMetadata {
- return type instanceof DirectiveMetadata;
+function _isDirectiveMetadata(type: any): type is Directive {
+ return type instanceof Directive;
}
/*
- * Resolve a `Type` for {@link DirectiveMetadata}.
+ * Resolve a `Type` for {@link Directive}.
*
* This interface can be overridden by the application developer to create custom behavior.
*
@@ -29,9 +29,9 @@ export class DirectiveResolver {
constructor(private _reflector: ReflectorReader = reflector) {}
/**
- * Return {@link DirectiveMetadata} for a given `Type`.
+ * Return {@link Directive} for a given `Type`.
*/
- resolve(type: Type<any>, throwIfNotFound = true): DirectiveMetadata {
+ resolve(type: Type<any>, throwIfNotFound = true): Directive {
var typeMetadata = this._reflector.annotations(resolveForwardRef(type));
if (isPresent(typeMetadata)) {
var metadata = typeMetadata.find(_isDirectiveMetadata);
@@ -47,40 +47,40 @@ export class DirectiveResolver {
}
private _mergeWithPropertyMetadata(
- dm: DirectiveMetadata, propertyMetadata: {[key: string]: any[]},
- directiveType: Type<any>): DirectiveMetadata {
+ dm: Directive, propertyMetadata: {[key: string]: any[]},
+ directiveType: Type<any>): Directive {
var inputs: string[] = [];
var outputs: string[] = [];
var host: {[key: string]: string} = {};
var queries: {[key: string]: any} = {};
StringMapWrapper.forEach(propertyMetadata, (metadata: any[], propName: string) => {
metadata.forEach(a => {
- if (a instanceof InputMetadata) {
+ if (a instanceof Input) {
if (isPresent(a.bindingPropertyName)) {
inputs.push(`${propName}: ${a.bindingPropertyName}`);
} else {
inputs.push(propName);
}
- } else if (a instanceof OutputMetadata) {
- const output: OutputMetadata = a;
+ } else if (a instanceof Output) {
+ const output: Output = a;
if (isPresent(output.bindingPropertyName)) {
outputs.push(`${propName}: ${output.bindingPropertyName}`);
} else {
outputs.push(propName);
}
- } else if (a instanceof HostBindingMetadata) {
- const hostBinding: HostBindingMetadata = a;
+ } else if (a instanceof HostBinding) {
+ const hostBinding: HostBinding = a;
if (isPresent(hostBinding.hostPropertyName)) {
host[`[${hostBinding.hostPropertyName}]`] = propName;
} else {
host[`[${propName}]`] = propName;
}
- } else if (a instanceof HostListenerMetadata) {
- const hostListener: HostListenerMetadata = a;
+ } else if (a instanceof HostListener) {
+ const hostListener: HostListener = a;
var args = isPresent(hostListener.args) ? (<any[]>hostListener.args).join(', ') : '';
host[`(${hostListener.eventName})`] = `${propName}(${args})`;
- } else if (a instanceof QueryMetadata) {
+ } else if (a instanceof Query) {
queries[propName] = a;
}
});
@@ -91,8 +91,8 @@ export class DirectiveResolver {
private _extractPublicName(def: string) { return splitAtColon(def, [null, def])[1].trim(); }
private _merge(
- dm: DirectiveMetadata, inputs: string[], outputs: string[], host: {[key: string]: string},
- queries: {[key: string]: any}, directiveType: Type<any>): DirectiveMetadata {
+ dm: Directive, inputs: string[], outputs: string[], host: {[key: string]: string},
+ queries: {[key: string]: any}, directiveType: Type<any>): Directive {
let mergedInputs: string[];
if (isPresent(dm.inputs)) {
@@ -132,8 +132,8 @@ export class DirectiveResolver {
var mergedQueries =
isPresent(dm.queries) ? StringMapWrapper.merge(dm.queries, queries) : queries;
- if (dm instanceof ComponentMetadata) {
- return new ComponentMetadata({
+ if (dm instanceof Component) {
+ return new Component({
selector: dm.selector,
inputs: mergedInputs,
outputs: mergedOutputs,
@@ -155,7 +155,7 @@ export class DirectiveResolver {
});
} else {
- return new DirectiveMetadata({
+ return new Directive({
selector: dm.selector,
inputs: mergedInputs,
outputs: mergedOutputs,
Oops, something went wrong.

0 comments on commit 63e15ff

Please sign in to comment.