fix(language-service): Should not crash if expr ends unexpectedly (#33524)
If there is any parser errors when parsing template, we should stop
immediately and not proceed with template expression diagnostics.
This regression is caused by 6d11154652
and affected v9.0.0-next.4 onwards.
PR closes https://github.com/angular/vscode-ng-language-service/issues/436
PR Close #33524
This commit is contained in:
@ -21,26 +21,23 @@ import {findPropertyValueOfType, findTightestNode, offsetSpan, spanOf} from './u
|
||||
* @param ast contains HTML and template AST
|
||||
*/
|
||||
export function getTemplateDiagnostics(ast: AstResult): ng.Diagnostic[] {
|
||||
const results: ng.Diagnostic[] = [];
|
||||
const {parseErrors, templateAst, htmlAst, template} = ast;
|
||||
if (parseErrors) {
|
||||
results.push(...parseErrors.map(e => {
|
||||
if (parseErrors && parseErrors.length) {
|
||||
return parseErrors.map(e => {
|
||||
return {
|
||||
kind: ng.DiagnosticKind.Error,
|
||||
span: offsetSpan(spanOf(e.span), template.span.start),
|
||||
message: e.msg,
|
||||
};
|
||||
}));
|
||||
});
|
||||
}
|
||||
const expressionDiagnostics = getTemplateExpressionDiagnostics({
|
||||
return getTemplateExpressionDiagnostics({
|
||||
templateAst: templateAst,
|
||||
htmlAst: htmlAst,
|
||||
offset: template.span.start,
|
||||
query: template.query,
|
||||
members: template.members,
|
||||
});
|
||||
results.push(...expressionDiagnostics);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user