feat(compiler): add name spans for property reads and method calls (#36826)
ASTs for property read and method calls contain information about the entire span of the expression, including its receiver. Use cases like a language service and compile error messages may be more interested in the span of the direct identifier for which the expression is constructed (i.e. an accessed property). To support this, this commit adds a `nameSpan` property on - `PropertyRead`s - `SafePropertyRead`s - `PropertyWrite`s - `MethodCall`s - `SafeMethodCall`s The `nameSpan` property already existed for `BindingPipe`s. This commit also updates usages of these expressions' `sourceSpan`s in Ngtsc and the langauge service to use `nameSpan`s where appropriate. PR Close #36826
This commit is contained in:
@ -457,8 +457,13 @@ class ExpressionVisitor extends NullTemplateVisitor {
|
||||
const absValueOffset = ast.sourceSpan.start.offset;
|
||||
const {templateBindings} = this.info.expressionParser.parseTemplateBindings(
|
||||
templateKey, templateValue, templateUrl, absKeyOffset, absValueOffset);
|
||||
// Find the template binding that contains the position.
|
||||
const templateBinding = templateBindings.find(b => inSpan(this.position, b.sourceSpan));
|
||||
// Find the nearest template binding to the position.
|
||||
const lastBindingEnd = templateBindings.length > 0 &&
|
||||
templateBindings[templateBindings.length - 1].sourceSpan.end;
|
||||
const normalizedPositionToBinding =
|
||||
lastBindingEnd && this.position > lastBindingEnd ? lastBindingEnd : this.position;
|
||||
const templateBinding =
|
||||
templateBindings.find(b => inSpan(normalizedPositionToBinding, b.sourceSpan));
|
||||
|
||||
if (!templateBinding) {
|
||||
return;
|
||||
|
Reference in New Issue
Block a user