From bc9e482b394ce2641fb34ac9d9b11c1ead747bd4 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 15 Jun 2015 22:06:52 -0700 Subject: [PATCH] fix: Class factory now adds annotations --- modules/angular2/src/util/decorators.ts | 5 ++++ modules/angular2/test/util/decorators_spec.ts | 25 +++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/angular2/src/util/decorators.ts b/modules/angular2/src/util/decorators.ts index a6f53296cf..bccc3ebe43 100644 --- a/modules/angular2/src/util/decorators.ts +++ b/modules/angular2/src/util/decorators.ts @@ -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 constructor; } diff --git a/modules/angular2/test/util/decorators_spec.ts b/modules/angular2/test/util/decorators_spec.ts index a489915a27..1ef66461c2 100644 --- a/modules/angular2/test/util/decorators_spec.ts +++ b/modules/angular2/test/util/decorators_spec.ts @@ -56,16 +56,19 @@ export function main() { describe('Class', () => { it('should create a class', () => { var i0, i1; - var MyClass = 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) {}], - works: function() { return this.arg; }, - prototype: 'IGNORE' - }); + var MyClass = + (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) {}], + works: function() { return this.arg; }, + prototype: 'IGNORE' + }); var obj: any = new MyClass('WORKS'); expect(obj.arg).toEqual('WORKS'); expect(obj.works()).toEqual('WORKS'); @@ -76,6 +79,8 @@ export function main() { var proto = (MyClass).prototype; expect(proto.extends).toEqual(undefined); expect(proto.prototype).toEqual(undefined); + + expect(reflector.annotations(MyClass)[0].arg).toEqual('test-works') }); describe('errors', () => {