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 12444a8afc
commit ddc229b69b
4 changed files with 47 additions and 10 deletions

View File

@ -151,10 +151,15 @@ class HtmlAstToIvyAst implements html.Visitor {
const templateKey = normalizedName.substring(TEMPLATE_ATTR_PREFIX.length);
const parsedVariables: ParsedVariable[] = [];
const absoluteOffset = attribute.valueSpan ? attribute.valueSpan.start.offset :
attribute.sourceSpan.start.offset;
const absoluteValueOffset = attribute.valueSpan ?
attribute.valueSpan.start.offset :
// If there is no value span the attribute does not have a value, like `attr` in
//`<div attr></div>`. In this case, point to one character beyond the last character of
// the attribute name.
attribute.sourceSpan.start.offset + attribute.name.length;
this.bindingParser.parseInlineTemplateBinding(
templateKey, templateValue, attribute.sourceSpan, absoluteOffset, [],
templateKey, templateValue, attribute.sourceSpan, absoluteValueOffset, [],
templateParsedProperties, parsedVariables);
templateVariables.push(
...parsedVariables.map(v => new t.Variable(v.name, v.value, v.sourceSpan)));