From d438b88f19530eb556a7813dcb044b470d4180f7 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 28 Mar 2017 13:32:34 -0700 Subject: [PATCH] fix(compiler): ignore errors when evaluating base classes (#15560) Fixes #15536 --- packages/compiler/src/aot/static_reflector.ts | 6 ++--- .../test/aot/static_reflector_spec.ts | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/packages/compiler/src/aot/static_reflector.ts b/packages/compiler/src/aot/static_reflector.ts index ce816231ac..edbda293f5 100644 --- a/packages/compiler/src/aot/static_reflector.ts +++ b/packages/compiler/src/aot/static_reflector.ts @@ -118,7 +118,7 @@ export class StaticReflector implements ɵReflectorReader { const classMetadata = this.getTypeMetadata(type); propMetadata = {}; if (classMetadata['extends']) { - const parentType = this.simplify(type, classMetadata['extends']); + const parentType = this.trySimplify(type, classMetadata['extends']); if (parentType instanceof StaticSymbol) { const parentPropMetadata = this.propMetadata(parentType); Object.keys(parentPropMetadata).forEach((parentProp) => { @@ -176,7 +176,7 @@ export class StaticReflector implements ɵReflectorReader { parameters.push(nestedResult); }); } else if (classMetadata['extends']) { - const parentType = this.simplify(type, classMetadata['extends']); + const parentType = this.trySimplify(type, classMetadata['extends']); if (parentType instanceof StaticSymbol) { parameters = this.parameters(parentType); } @@ -199,7 +199,7 @@ export class StaticReflector implements ɵReflectorReader { const classMetadata = this.getTypeMetadata(type); methodNames = {}; if (classMetadata['extends']) { - const parentType = this.simplify(type, classMetadata['extends']); + const parentType = this.trySimplify(type, classMetadata['extends']); if (parentType instanceof StaticSymbol) { const parentMethodNames = this._methodNames(parentType); Object.keys(parentMethodNames).forEach((parentProp) => { diff --git a/packages/compiler/test/aot/static_reflector_spec.ts b/packages/compiler/test/aot/static_reflector_spec.ts index b931593287..b20769fbf9 100644 --- a/packages/compiler/test/aot/static_reflector_spec.ts +++ b/packages/compiler/test/aot/static_reflector_spec.ts @@ -495,6 +495,31 @@ describe('StaticReflector', () => { expect(() => reflector.propMetadata(appComponent)).not.toThrow(); }); + it('should not throw with an invalid extends', () => { + const data = Object.create(DEFAULT_TEST_DATA); + const file = '/tmp/src/invalid-component.ts'; + data[file] = ` + import {Component} from '@angular/core'; + + function InvalidParent() { + return InvalidParent; + } + + @Component({ + selector: 'tmp', + template: '', + }) + export class BadComponent extends InvalidParent() { + + } + `; + init(data); + const badComponent = reflector.getStaticSymbol(file, 'BadComponent'); + expect(reflector.propMetadata(badComponent)).toEqual({}); + expect(reflector.parameters(badComponent)).toEqual([]); + expect(reflector.hasLifecycleHook(badComponent, 'onDestroy')).toEqual(false); + }); + it('should produce a annotation even if it contains errors', () => { const data = Object.create(DEFAULT_TEST_DATA); const file = '/tmp/src/invalid-component.ts';