diff --git a/packages/compiler/src/render3/r3_template_transform.ts b/packages/compiler/src/render3/r3_template_transform.ts index 0018a68481..92d652d16d 100644 --- a/packages/compiler/src/render3/r3_template_transform.ts +++ b/packages/compiler/src/render3/r3_template_transform.ts @@ -157,7 +157,7 @@ class HtmlAstToIvyAst implements html.Visitor { this.bindingParser.parseInlineTemplateBinding( templateKey, templateValue, attribute.sourceSpan, absoluteValueOffset, [], - templateParsedProperties, parsedVariables); + templateParsedProperties, parsedVariables, true /* isIvyAst */); templateVariables.push(...parsedVariables.map( v => new t.Variable(v.name, v.value, v.sourceSpan, v.keySpan, v.valueSpan))); } else { diff --git a/packages/compiler/src/template_parser/binding_parser.ts b/packages/compiler/src/template_parser/binding_parser.ts index 1cbe4530ab..bc4ccf9cd1 100644 --- a/packages/compiler/src/template_parser/binding_parser.ts +++ b/packages/compiler/src/template_parser/binding_parser.ts @@ -141,8 +141,8 @@ export class BindingParser { */ parseInlineTemplateBinding( tplKey: string, tplValue: string, sourceSpan: ParseSourceSpan, absoluteValueOffset: number, - targetMatchableAttrs: string[][], targetProps: ParsedProperty[], - targetVars: ParsedVariable[]) { + targetMatchableAttrs: string[][], targetProps: ParsedProperty[], targetVars: ParsedVariable[], + isIvyAst: boolean) { const absoluteKeyOffset = sourceSpan.start.offset + TEMPLATE_ATTR_PREFIX.length; const bindings = this._parseTemplateBindings( tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset); @@ -159,9 +159,10 @@ export class BindingParser { binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined; targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan)); } else if (binding.value) { + const srcSpan = isIvyAst ? bindingSpan : sourceSpan; const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan); this._parsePropertyAst( - key, binding.value, sourceSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps); + key, binding.value, srcSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps); } else { targetMatchableAttrs.push([key, '' /* value */]); // Since this is a literal attribute with no RHS, source span should be diff --git a/packages/compiler/src/template_parser/template_parser.ts b/packages/compiler/src/template_parser/template_parser.ts index 5c6bd78918..19dfe8f384 100644 --- a/packages/compiler/src/template_parser/template_parser.ts +++ b/packages/compiler/src/template_parser/template_parser.ts @@ -317,7 +317,7 @@ class TemplateParseVisitor implements html.Visitor { const absoluteOffset = (attr.valueSpan || attr.sourceSpan).start.offset; this._bindingParser.parseInlineTemplateBinding( templateKey!, templateValue!, attr.sourceSpan, absoluteOffset, templateMatchableAttrs, - templateElementOrDirectiveProps, parsedVariables); + templateElementOrDirectiveProps, parsedVariables, false /* isIvyAst */); templateElementVars.push(...parsedVariables.map(v => t.VariableAst.fromParsedVariable(v))); } diff --git a/packages/compiler/test/render3/r3_ast_spans_spec.ts b/packages/compiler/test/render3/r3_ast_spans_spec.ts index e74722c109..1f82c8a78b 100644 --- a/packages/compiler/test/render3/r3_ast_spans_spec.ts +++ b/packages/compiler/test/render3/r3_ast_spans_spec.ts @@ -285,7 +285,7 @@ describe('R3 AST source spans', () => { '' ], ['TextAttribute', 'ngFor', ''], - ['BoundAttribute', '*ngFor="let item of items"', 'of', 'items'], + ['BoundAttribute', 'of items', 'of', 'items'], ['Variable', 'let item ', 'item', ''], [ 'Element', '
', '
', @@ -303,8 +303,8 @@ describe('R3 AST source spans', () => { [ 'Template', '
', '
', '
' ], - ['BoundAttribute', '*ngFor="item of items"', 'ngFor', 'item'], - ['BoundAttribute', '*ngFor="item of items"', 'of', 'items'], + ['BoundAttribute', 'ngFor="item ', 'ngFor', 'item'], + ['BoundAttribute', 'of items', 'of', 'items'], ['Element', '
', '
', '
'], ]); @@ -314,10 +314,8 @@ describe('R3 AST source spans', () => { '
', '
' ], ['TextAttribute', 'ngFor', ''], - ['BoundAttribute', '*ngFor="let item of items; trackBy: trackByFn"', 'of', 'items'], - [ - 'BoundAttribute', '*ngFor="let item of items; trackBy: trackByFn"', 'trackBy', 'trackByFn' - ], + ['BoundAttribute', 'of items; ', 'of', 'items'], + ['BoundAttribute', 'trackBy: trackByFn', 'trackBy', 'trackByFn'], ['Variable', 'let item ', 'item', ''], [ 'Element', '
', @@ -339,7 +337,7 @@ describe('R3 AST source spans', () => { it('is correct for variables via as ...', () => { expectFromHtml('
').toEqual([ ['Template', '
', '
', '
'], - ['BoundAttribute', '*ngIf="expr as local"', 'ngIf', 'expr'], + ['BoundAttribute', 'ngIf="expr ', 'ngIf', 'expr'], ['Variable', 'ngIf="expr as local', 'local', 'ngIf'], ['Element', '
', '
', '
'], ]);