fix(compiler): source span for microsyntax text att should be key span (#38766)

In a microsyntax expressions, some attributes are not bound after
desugaring. For example,
```html
<div *ngFor="let item of items">
</div>
```
gets desugared to
```html
<ng-template ngFor let-items [ngForOf]="items">
</ngtemplate>
```
In this case, `ngFor` should be a literal attribute with no RHS value.
Therefore, its source span should be just the `keySpan` and not the
source span of the original template node.
This allows language service to precisely pinpoint different spans in a
microsyntax to provide accurate information.

PR Close #38766
This commit is contained in:
Keen Yee Liau
2020-09-09 11:22:50 -07:00
committed by Andrew Kushnir
parent 19598b47ca
commit 8f349b2375
3 changed files with 14 additions and 11 deletions

View File

@ -157,10 +157,12 @@ export class BindingParser {
this._parsePropertyAst(
key, binding.value, sourceSpan, valueSpan, targetMatchableAttrs, targetProps);
} else {
targetMatchableAttrs.push([key, '']);
targetMatchableAttrs.push([key, '' /* value */]);
// Since this is a literal attribute with no RHS, source span should be
// just the key span.
this.parseLiteralAttr(
key, null, sourceSpan, absoluteValueOffset, undefined, targetMatchableAttrs,
targetProps);
key, null /* value */, keySpan, absoluteValueOffset, undefined /* valueSpan */,
targetMatchableAttrs, targetProps);
}
}
}