From 38a7e0d1c77399f3fa9db5883eb2447e41e2641a Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Fri, 14 Apr 2017 09:02:32 -0700 Subject: [PATCH] fix(compiler): ignore calls to unresolved symbols in metadata This only shows up in the language service. Calls to symbols that are not resolve resulted in null instead of being resolved causing the language service to see exceptions when the null was not expected such as in the animations array. Fixes #15969 --- packages/compiler/src/aot/static_reflector.ts | 2 +- .../test/aot/static_reflector_spec.ts | 24 +++++++++++++++++++ .../test/aot/static_symbol_resolver_spec.ts | 3 +++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/compiler/src/aot/static_reflector.ts b/packages/compiler/src/aot/static_reflector.ts index bb97bd1676..9eb7134836 100644 --- a/packages/compiler/src/aot/static_reflector.ts +++ b/packages/compiler/src/aot/static_reflector.ts @@ -584,7 +584,7 @@ export class StaticReflector implements ɵReflectorReader { return simplifyCall(staticSymbol, targetFunction, argExpressions); } } - break; + return IGNORE; case 'error': let message = produceErrorMessage(expression); if (expression['line']) { diff --git a/packages/compiler/test/aot/static_reflector_spec.ts b/packages/compiler/test/aot/static_reflector_spec.ts index dd6fc683b3..9ea0ffda15 100644 --- a/packages/compiler/test/aot/static_reflector_spec.ts +++ b/packages/compiler/test/aot/static_reflector_spec.ts @@ -546,6 +546,30 @@ describe('StaticReflector', () => { expect(annotation.providers).toEqual([1, 2, 3, 4, 5, 6, 7]); }); + it('should ignore unresolved calls', () => { + const data = Object.create(DEFAULT_TEST_DATA); + const file = '/tmp/src/invalid-component.ts'; + data[file] = ` + import {Component} from '@angular/core'; + import {unknown} from 'unresolved'; + + @Component({ + selector: 'tmp', + template: () => {}, + providers: [triggers()] + }) + export class BadComponent { + + } + `; + init(data, [], () => {}, {verboseInvalidExpression: true}); + + const badComponent = reflector.getStaticSymbol(file, 'BadComponent'); + const annotations = reflector.annotations(badComponent); + const annotation = annotations[0]; + expect(annotation.providers).toEqual([]); + }); + describe('inheritance', () => { class ClassDecorator { constructor(public value: any) {} diff --git a/packages/compiler/test/aot/static_symbol_resolver_spec.ts b/packages/compiler/test/aot/static_symbol_resolver_spec.ts index 9adfc0ebdf..944d6c503c 100644 --- a/packages/compiler/test/aot/static_symbol_resolver_spec.ts +++ b/packages/compiler/test/aot/static_symbol_resolver_spec.ts @@ -436,6 +436,9 @@ export class MockStaticSymbolResolverHost implements StaticSymbolResolverHost { } return baseName + '.d.ts'; } + if (modulePath == 'unresolved') { + return undefined; + } return '/tmp/' + modulePath + '.d.ts'; }