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:
@ -245,10 +245,18 @@ describe('expression AST absolute source spans', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should provide absolute offsets of a property read', () => {
|
||||
expect(humanizeExpressionSource(parse('<div>{{prop}}</div>').nodes)).toContain([
|
||||
'prop', new AbsoluteSourceSpan(7, 11)
|
||||
]);
|
||||
describe('property read', () => {
|
||||
it('should provide absolute offsets of a property read', () => {
|
||||
expect(humanizeExpressionSource(parse('<div>{{prop.obj}}<div>').nodes)).toContain([
|
||||
'prop.obj', new AbsoluteSourceSpan(7, 15)
|
||||
]);
|
||||
});
|
||||
|
||||
it('should provide absolute offsets of expressions in a property read', () => {
|
||||
expect(humanizeExpressionSource(parse('<div>{{prop.obj}}<div>').nodes)).toContain([
|
||||
'prop', new AbsoluteSourceSpan(7, 11)
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('property write', () => {
|
||||
@ -258,6 +266,11 @@ describe('expression AST absolute source spans', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should provide absolute offsets of an accessed property write', () => {
|
||||
expect(humanizeExpressionSource(parse('<div (click)="prop.inner = 0"></div>').nodes))
|
||||
.toContain(['prop.inner = 0', new AbsoluteSourceSpan(14, 28)]);
|
||||
});
|
||||
|
||||
it('should provide absolute offsets of expressions in a property write', () => {
|
||||
expect(humanizeExpressionSource(parse('<div (click)="prop = 0"></div>').nodes)).toContain([
|
||||
'0', new AbsoluteSourceSpan(21, 22)
|
||||
|
Reference in New Issue
Block a user