From b2c66949b22f7921e48e984ad1ef07b7bd14af47 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Tue, 16 Jun 2015 16:13:31 -0700 Subject: [PATCH] feat: allow Type.annotations = Component(...).View(...) Closes #2577 --- .../src/reflection/reflection_capabilities.ts | 15 +++++++++++++-- .../test/core/annotations/decorators_spec.ts | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/modules/angular2/src/reflection/reflection_capabilities.ts b/modules/angular2/src/reflection/reflection_capabilities.ts index 5e3d1de9bb..a80b67a13b 100644 --- a/modules/angular2/src/reflection/reflection_capabilities.ts +++ b/modules/angular2/src/reflection/reflection_capabilities.ts @@ -1,4 +1,11 @@ -import {Type, isPresent, global, stringify, BaseException} from 'angular2/src/facade/lang'; +import { + Type, + isPresent, + isFunction, + global, + stringify, + BaseException +} from 'angular2/src/facade/lang'; import {List, ListWrapper} from 'angular2/src/facade/collection'; import {GetterFn, SetterFn, MethodFn} from './types'; import {PlatformReflectionCapabilities} from 'platform_reflection_capabilities'; @@ -118,7 +125,11 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities { annotations(typeOfFunc): List { // Prefer the direct API. if (isPresent(typeOfFunc.annotations)) { - return typeOfFunc.annotations; + var annotations = typeOfFunc.annotations; + if (isFunction(annotations) && annotations.annotations) { + annotations = annotations.annotations; + } + return annotations; } if (isPresent(this._reflect) && isPresent(this._reflect.getMetadata)) { var annotations = this._reflect.getMetadata('annotations', typeOfFunc); diff --git a/modules/angular2/test/core/annotations/decorators_spec.ts b/modules/angular2/test/core/annotations/decorators_spec.ts index 92b33b90f9..888567a513 100644 --- a/modules/angular2/test/core/annotations/decorators_spec.ts +++ b/modules/angular2/test/core/annotations/decorators_spec.ts @@ -11,6 +11,7 @@ import { } from 'angular2/test_lib'; import {Component, View, Directive} from 'angular2/angular2'; +import {reflector} from 'angular2/src/reflection/reflection'; export function main() { describe('es5 decorators', () => { @@ -24,5 +25,12 @@ export function main() { Component({}).View({}).View({}).Class({constructor: function() { this.works = true; }}); expect(new MyComponent().works).toEqual(true); }); + + it('should create type in ES5', () => { + function MyComponent(){}; + var as; + (MyComponent).annotations = as = Component({}).View({}); + expect(reflector.annotations(MyComponent)).toEqual(as.annotations); + }); }); }