fix: Class factory now adds annotations

This commit is contained in:
Misko Hevery 2015-06-15 22:06:52 -07:00
parent cab1d0ef0f
commit bc9e482b39
2 changed files with 20 additions and 10 deletions

View File

@ -79,6 +79,11 @@ export function Class(clsDef: ClassDefinition): Type {
proto[key] = applyParams(clsDef[key], key);
}
}
if (this && this.annotations instanceof Array) {
Reflect.defineMetadata('annotations', this.annotations, constructor);
}
return <Type>constructor;
}

View File

@ -56,13 +56,16 @@ export function main() {
describe('Class', () => {
it('should create a class', () => {
var i0, i1;
var MyClass = Class({
var MyClass =
(<any>TestDecorator('test-works'))
.Class({
extends: Class({
constructor: function() {},
extendWorks: function() { return 'extend ' + this.arg; }
}),
constructor: [String, function(arg) { this.arg = arg; }],
methodA: [i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
methodA:
[i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
works: function() { return this.arg; },
prototype: 'IGNORE'
});
@ -76,6 +79,8 @@ export function main() {
var proto = (<Function>MyClass).prototype;
expect(proto.extends).toEqual(undefined);
expect(proto.prototype).toEqual(undefined);
expect(reflector.annotations(MyClass)[0].arg).toEqual('test-works')
});
describe('errors', () => {