From 93556a57202a043e601c424d35bff1ebc98d45bb Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 6 Dec 2016 09:56:30 -0800 Subject: [PATCH] fix(language-service): avoid throwing for invalid class declarations (#13257) Fixes #13253 --- modules/@angular/language-service/src/typescript_host.ts | 2 +- modules/@angular/language-service/test/diagnostics_spec.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/@angular/language-service/src/typescript_host.ts b/modules/@angular/language-service/src/typescript_host.ts index ff58a9f2fc..f5a852d8fb 100644 --- a/modules/@angular/language-service/src/typescript_host.ts +++ b/modules/@angular/language-service/src/typescript_host.ts @@ -325,7 +325,7 @@ export class TypeScriptServiceHost implements LanguageServiceHost { case this.ts.SyntaxKind.StringLiteral: let [declaration, decorator] = this.getTemplateClassDeclFromNode(node); let queryCache: SymbolQuery|undefined = undefined; - if (declaration) { + if (declaration && declaration.name) { const sourceFile = this.getSourceFile(fileName); return this.getSourceFromDeclaration( fileName, version, this.stringOf(node), shrink(spanOf(node)), diff --git a/modules/@angular/language-service/test/diagnostics_spec.ts b/modules/@angular/language-service/test/diagnostics_spec.ts index a92f519029..823f989149 100644 --- a/modules/@angular/language-service/test/diagnostics_spec.ts +++ b/modules/@angular/language-service/test/diagnostics_spec.ts @@ -115,6 +115,12 @@ describe('diagnostics', () => { }); }); + it('should not throw for an invalid class', () => { + const code = ` @Component({template: ''}) class`; + addCode( + code, fileName => { expect(() => ngService.getDiagnostics(fileName)).not.toThrow(); }); + }); + function addCode(code: string, cb: (fileName: string, content?: string) => void) { const fileName = '/app/app.component.ts'; const originalContent = mockHost.getFileContent(fileName);