Skip to content

Commit b2c6694

Browse files
committed
feat: allow Type.annotations = Component(...).View(...)
Closes angular#2577
1 parent eb3586d commit b2c6694

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

modules/angular2/src/reflection/reflection_capabilities.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import {Type, isPresent, global, stringify, BaseException} from 'angular2/src/facade/lang';
1+
import {
2+
Type,
3+
isPresent,
4+
isFunction,
5+
global,
6+
stringify,
7+
BaseException
8+
} from 'angular2/src/facade/lang';
29
import {List, ListWrapper} from 'angular2/src/facade/collection';
310
import {GetterFn, SetterFn, MethodFn} from './types';
411
import {PlatformReflectionCapabilities} from 'platform_reflection_capabilities';
@@ -118,7 +125,11 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities {
118125
annotations(typeOfFunc): List<any> {
119126
// Prefer the direct API.
120127
if (isPresent(typeOfFunc.annotations)) {
121-
return typeOfFunc.annotations;
128+
var annotations = typeOfFunc.annotations;
129+
if (isFunction(annotations) && annotations.annotations) {
130+
annotations = annotations.annotations;
131+
}
132+
return annotations;
122133
}
123134
if (isPresent(this._reflect) && isPresent(this._reflect.getMetadata)) {
124135
var annotations = this._reflect.getMetadata('annotations', typeOfFunc);

modules/angular2/test/core/annotations/decorators_spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'angular2/test_lib';
1212

1313
import {Component, View, Directive} from 'angular2/angular2';
14+
import {reflector} from 'angular2/src/reflection/reflection';
1415

1516
export function main() {
1617
describe('es5 decorators', () => {
@@ -24,5 +25,12 @@ export function main() {
2425
Component({}).View({}).View({}).Class({constructor: function() { this.works = true; }});
2526
expect(new MyComponent().works).toEqual(true);
2627
});
28+
29+
it('should create type in ES5', () => {
30+
function MyComponent(){};
31+
var as;
32+
(<any>MyComponent).annotations = as = Component({}).View({});
33+
expect(reflector.annotations(MyComponent)).toEqual(as.annotations);
34+
});
2735
});
2836
}

0 commit comments

Comments
 (0)