Skip to content

Commit

Permalink
fix(language-service): avoid throwing for invalid class declarations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckjaz authored and alxhub committed Dec 6, 2016
1 parent 5614c4f commit 93556a5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/@angular/language-service/src/typescript_host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
6 changes: 6 additions & 0 deletions modules/@angular/language-service/test/diagnostics_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 93556a5

Please sign in to comment.