diff --git a/modules/@angular/compiler/src/aot/static_reflector.ts b/modules/@angular/compiler/src/aot/static_reflector.ts index da7cda759d..4a0d66fe82 100644 --- a/modules/@angular/compiler/src/aot/static_reflector.ts +++ b/modules/@angular/compiler/src/aot/static_reflector.ts @@ -86,7 +86,7 @@ export class StaticReflector implements ReflectorReader { annotations = []; const classMetadata = this.getTypeMetadata(type); if (classMetadata['extends']) { - const parentType = this.simplify(type, classMetadata['extends']); + const parentType = this.trySimplify(type, classMetadata['extends']); if (parentType && (parentType instanceof StaticSymbol)) { const parentAnnotations = this.annotations(parentType); annotations.push(...parentAnnotations); @@ -303,6 +303,17 @@ export class StaticReflector implements ReflectorReader { } } + /** + * Simplify but discard any errors + */ + private trySimplify(context: StaticSymbol, value: any): any { + const originalRecorder = this.errorRecorder; + this.errorRecorder = (error: any, fileName: string) => {}; + const result = this.simplify(context, value); + this.errorRecorder = originalRecorder; + return result; + } + /** @internal */ public simplify(context: StaticSymbol, value: any): any { const self = this; diff --git a/modules/@angular/compiler/test/aot/static_reflector_spec.ts b/modules/@angular/compiler/test/aot/static_reflector_spec.ts index 4d7d657980..7946dee738 100644 --- a/modules/@angular/compiler/test/aot/static_reflector_spec.ts +++ b/modules/@angular/compiler/test/aot/static_reflector_spec.ts @@ -679,6 +679,30 @@ describe('StaticReflector', () => { 'hook1', 'hook2', 'hook3' ])).toEqual([false, false, false]); }); + + it('should allow inheritance from expressions', () => { + initWithDecorator({ + '/tmp/src/main.ts': ` + export function metaClass() { return null; }; + export class Child extends metaClass() {} + ` + }); + + expect(reflector.annotations(reflector.getStaticSymbol('/tmp/src/main.ts', 'Child'))) + .toEqual([]); + }); + + it('should allow inheritance from functions', () => { + initWithDecorator({ + '/tmp/src/main.ts': ` + export let ctor: {new(): T} = function() { return null; } + export class Child extends ctor {} + ` + }); + + expect(reflector.annotations(reflector.getStaticSymbol('/tmp/src/main.ts', 'Child'))) + .toEqual([]); + }); }); });