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:
Ayaz Hafiz
2020-04-27 18:54:30 -07:00
committed by Misko Hevery
parent 1142c378fd
commit eb34aa551a
20 changed files with 496 additions and 199 deletions

View File

@ -77,7 +77,7 @@ describe('definitions', () => {
it('should be able to find a method from a call', () => {
const fileName = mockHost.addCode(`
@Component({
template: '<div (click)="~{start-my}«myClick»()~{end-my};"></div>'
template: '<div (click)="«myClick»();"></div>'
})
export class MyComponent {
«ᐱmyClickᐱ() { }»
@ -88,7 +88,7 @@ describe('definitions', () => {
expect(result).toBeDefined();
const {textSpan, definitions} = result!;
expect(textSpan).toEqual(mockHost.getLocationMarkerFor(fileName, 'my'));
expect(textSpan).toEqual(marker);
expect(definitions).toBeDefined();
expect(definitions!.length).toBe(1);
const def = definitions![0];