From bd510ccdbbd14ce0833835128d845c35dcc8bd7b Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Wed, 24 Aug 2016 10:21:13 -0700 Subject: [PATCH] fix(core): assigns an overriden name to constructor named constructor (#11043) Fixes #10545 --- modules/@angular/core/src/util/decorators.ts | 3 ++- modules/@angular/core/test/util/decorators_spec.ts | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/@angular/core/src/util/decorators.ts b/modules/@angular/core/src/util/decorators.ts index ed8fe7b068..a9fcee2836 100644 --- a/modules/@angular/core/src/util/decorators.ts +++ b/modules/@angular/core/src/util/decorators.ts @@ -243,7 +243,8 @@ export function Class(clsDef: ClassDefinition): Type { Reflect.defineMetadata('annotations', this.annotations, constructor); } - if (!constructor['name']) { + const constructorName = constructor['name']; + if (!constructorName || constructorName === 'constructor') { (constructor as any)['overriddenName'] = `class${_nextClassId++}`; } diff --git a/modules/@angular/core/test/util/decorators_spec.ts b/modules/@angular/core/test/util/decorators_spec.ts index 5300a0d59a..9c220dd74a 100644 --- a/modules/@angular/core/test/util/decorators_spec.ts +++ b/modules/@angular/core/test/util/decorators_spec.ts @@ -132,6 +132,10 @@ export function main() { .toThrowError( 'Class definition \'extends\' property must be a constructor function was: non_type'); }); + + it('should assign an overridden name for anonymous constructor functions', () => { + expect((Class({constructor: function() {}}) as any).overriddenName).not.toBeUndefined(); + }); }); }); });