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);