fix: Class factory now adds annotations
This commit is contained in:
parent
cab1d0ef0f
commit
bc9e482b39
|
@ -79,6 +79,11 @@ export function Class(clsDef: ClassDefinition): Type {
|
||||||
proto[key] = applyParams(clsDef[key], key);
|
proto[key] = applyParams(clsDef[key], key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this && this.annotations instanceof Array) {
|
||||||
|
Reflect.defineMetadata('annotations', this.annotations, constructor);
|
||||||
|
}
|
||||||
|
|
||||||
return <Type>constructor;
|
return <Type>constructor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,16 +56,19 @@ export function main() {
|
||||||
describe('Class', () => {
|
describe('Class', () => {
|
||||||
it('should create a class', () => {
|
it('should create a class', () => {
|
||||||
var i0, i1;
|
var i0, i1;
|
||||||
var MyClass = Class({
|
var MyClass =
|
||||||
extends: Class({
|
(<any>TestDecorator('test-works'))
|
||||||
constructor: function() {},
|
.Class({
|
||||||
extendWorks: function() { return 'extend ' + this.arg; }
|
extends: Class({
|
||||||
}),
|
constructor: function() {},
|
||||||
constructor: [String, function(arg) { this.arg = arg; }],
|
extendWorks: function() { return 'extend ' + this.arg; }
|
||||||
methodA: [i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
|
}),
|
||||||
works: function() { return this.arg; },
|
constructor: [String, function(arg) { this.arg = arg; }],
|
||||||
prototype: 'IGNORE'
|
methodA:
|
||||||
});
|
[i0 = new Inject(String), [i1 = Inject(String), Number], function(a, b) {}],
|
||||||
|
works: function() { return this.arg; },
|
||||||
|
prototype: 'IGNORE'
|
||||||
|
});
|
||||||
var obj: any = new MyClass('WORKS');
|
var obj: any = new MyClass('WORKS');
|
||||||
expect(obj.arg).toEqual('WORKS');
|
expect(obj.arg).toEqual('WORKS');
|
||||||
expect(obj.works()).toEqual('WORKS');
|
expect(obj.works()).toEqual('WORKS');
|
||||||
|
@ -76,6 +79,8 @@ export function main() {
|
||||||
var proto = (<Function>MyClass).prototype;
|
var proto = (<Function>MyClass).prototype;
|
||||||
expect(proto.extends).toEqual(undefined);
|
expect(proto.extends).toEqual(undefined);
|
||||||
expect(proto.prototype).toEqual(undefined);
|
expect(proto.prototype).toEqual(undefined);
|
||||||
|
|
||||||
|
expect(reflector.annotations(MyClass)[0].arg).toEqual('test-works')
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('errors', () => {
|
describe('errors', () => {
|
||||||
|
|
Loading…
Reference in New Issue