fix(ivy): record correct absolute source span for ngForOf expressions (#31813)

Expressions in an inline template binding are improperly recorded as
spaning an offset calculated from the start of the template binding
attribute key, whereas they should be calculated from the start of the
attribute value, which contains the actual binding AST.

PR Close #31813
This commit is contained in:
Ayaz Hafiz
2019-07-23 15:51:42 -07:00
committed by Kara Erickson
parent c9172cf1df
commit 931cb5ecd4
4 changed files with 47 additions and 10 deletions

View File

@ -322,4 +322,18 @@ describe('expression AST absolute source spans', () => {
'a:b', new AbsoluteSourceSpan(13, 16)
]);
});
describe('absolute offsets for template expressions', () => {
it('should work for simple cases', () => {
expect(
humanizeExpressionSource(parse('<div *ngFor="let item of items">{{item}}</div>').nodes))
.toContain(['items', new AbsoluteSourceSpan(25, 30)]);
});
it('should work with multiple bindings', () => {
expect(humanizeExpressionSource(parse('<div *ngFor="let a of As; let b of Bs"></div>').nodes))
.toEqual(jasmine.arrayContaining(
[['As', new AbsoluteSourceSpan(22, 24)], ['Bs', new AbsoluteSourceSpan(35, 37)]]));
});
});
});