fix(compiler): absolute source span for template attribute expressions (#33189)
Prior to this commit, the absolute spans (relative to template source file rather than the start of an expression) of expressions in a template attribute like `*ngIf` were generated incorrectly, equating to the relative spans. This fixes the bug by passing an `absoluteOffset` parameter when parsing template bindings. Through some levels of indirection, this is required for the Language Service to support text replacement in https://github.com/angular/angular/pull/33091. PR Close #33189
This commit is contained in:

committed by
Matias Niemelä

parent
422eb14dc0
commit
fd4fed14d8
@ -44,6 +44,12 @@ describe('expression AST absolute source spans', () => {
|
||||
.toContain(['condition ? true : false', new AbsoluteSourceSpan(22, 46)]);
|
||||
});
|
||||
|
||||
it('should provide absolute offsets of an expression in a template attribute', () => {
|
||||
expect(humanizeExpressionSource(parse('<div *ngIf="value | async"></div>').nodes)).toContain([
|
||||
'(value | async)', new AbsoluteSourceSpan(12, 25)
|
||||
]);
|
||||
});
|
||||
|
||||
describe('binary expression', () => {
|
||||
it('should provide absolute offsets of a binary expression', () => {
|
||||
expect(humanizeExpressionSource(parse('<div>{{1 + 2}}<div>').nodes)).toContain([
|
||||
|
@ -102,7 +102,10 @@ class ExpressionSourceHumanizer extends e.RecursiveAstVisitor implements t.Visit
|
||||
super.visitQuote(ast, null);
|
||||
}
|
||||
|
||||
visitTemplate(ast: t.Template) { t.visitAll(this, ast.children); }
|
||||
visitTemplate(ast: t.Template) {
|
||||
t.visitAll(this, ast.children);
|
||||
t.visitAll(this, ast.templateAttrs);
|
||||
}
|
||||
visitElement(ast: t.Element) {
|
||||
t.visitAll(this, ast.children);
|
||||
t.visitAll(this, ast.inputs);
|
||||
|
Reference in New Issue
Block a user