Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler): ignore errors when evaluating base classes #15560

Merged
merged 1 commit into from Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/compiler/src/aot/static_reflector.ts
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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);
}
Expand All @@ -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) => {
Expand Down
25 changes: 25 additions & 0 deletions packages/compiler/test/aot/static_reflector_spec.ts
Expand Up @@ -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';
Expand Down