fix(language-service): avoid throwing for invalid class declarations (#13257)
Fixes #13253
This commit is contained in:
parent
5614c4ff0f
commit
93556a5720
|
@ -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)),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue