Skip to content

Commit bc9e482

Browse files
committed
fix: Class factory now adds annotations
1 parent cab1d0e commit bc9e482

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

modules/angular2/src/util/decorators.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export function Class(clsDef: ClassDefinition): Type {
7979
proto[key] = applyParams(clsDef[key], key);
8080
}
8181
}
82+
83+
if (this && this.annotations instanceof Array) {
84+
Reflect.defineMetadata('annotations', this.annotations, constructor);
85+
}
86+
8287
return <Type>constructor;
8388
}
8489

modules/angular2/test/util/decorators_spec.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,19 @@ export function main() {
5656
describe('Class', () => {
5757
it('should create a class', () => {
5858
var i0, i1;
59-
var MyClass = Class({
60-
extends: Class({
61-
constructor: function() {},
62-
extendWorks: function() { return 'extend ' + this.arg; }
63-
}),
64-
constructor: [String, function(arg) { this.arg = arg; }],
65-
methodA: [i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
66-
works: function() { return this.arg; },
67-
prototype: 'IGNORE'
68-
});
59+
var MyClass =
60+
(<any>TestDecorator('test-works'))
61+
.Class({
62+
extends: Class({
63+
constructor: function() {},
64+
extendWorks: function() { return 'extend ' + this.arg; }
65+
}),
66+
constructor: [String, function(arg) { this.arg = arg; }],
67+
methodA:
68+
[i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
69+
works: function() { return this.arg; },
70+
prototype: 'IGNORE'
71+
});
6972
var obj: any = new MyClass('WORKS');
7073
expect(obj.arg).toEqual('WORKS');
7174
expect(obj.works()).toEqual('WORKS');
@@ -76,6 +79,8 @@ export function main() {
7679
var proto = (<Function>MyClass).prototype;
7780
expect(proto.extends).toEqual(undefined);
7881
expect(proto.prototype).toEqual(undefined);
82+
83+
expect(reflector.annotations(MyClass)[0].arg).toEqual('test-works')
7984
});
8085

8186
describe('errors', () => {

0 commit comments

Comments
 (0)