fix(language-service): avoid throwing for invalid class declarations (#13257)

Fixes #13253
This commit is contained in:
Chuck Jazdzewski 2016-12-06 09:56:30 -08:00 committed by Alex Rickabaugh
parent 5614c4ff0f
commit 93556a5720
2 changed files with 7 additions and 1 deletions

View File

@ -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)),

View File

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