diff --git a/packages/compiler/src/render3/r3_template_transform.ts b/packages/compiler/src/render3/r3_template_transform.ts index 8991e9743b66..5ccefb2e547c 100644 --- a/packages/compiler/src/render3/r3_template_transform.ts +++ b/packages/compiler/src/render3/r3_template_transform.ts @@ -697,8 +697,8 @@ class HtmlAstToIvyAst implements html.Visitor { const value = attribute.value; const srcSpan = attribute.sourceSpan; const absoluteOffset = attribute.valueSpan - ? attribute.valueSpan.start.offset - : srcSpan.start.offset; + ? attribute.valueSpan.fullStart.offset + : srcSpan.fullStart.offset; function createKeySpan(srcSpan: ParseSourceSpan, prefix: string, identifier: string) { // We need to adjust the start location for the keySpan to account for the removed 'data-' diff --git a/packages/compiler/test/render3/r3_ast_spans_spec.ts b/packages/compiler/test/render3/r3_ast_spans_spec.ts index 4b2524475e24..0851bd8269c0 100644 --- a/packages/compiler/test/render3/r3_ast_spans_spec.ts +++ b/packages/compiler/test/render3/r3_ast_spans_spec.ts @@ -6,6 +6,7 @@ * found in the LICENSE file at https://angular.dev/license */ +import {ASTWithSource} from '../../src/expression_parser/ast'; import {ParseSourceSpan} from '../../src/parse_util'; import * as t from '../../src/render3/r3_ast'; @@ -409,6 +410,24 @@ describe('R3 AST source spans', () => { ['BoundAttribute', '@animation', 'animation', ''], ]); }); + + it('should not throw off span of value in bound attribute when leading spaces are present', () => { + const assertValueSpan = (template: string, start: number, end: number) => { + const result = parse(template); + const boundAttribute = (result.nodes[0] as t.Element).inputs[0]; + const span = (boundAttribute.value as ASTWithSource).ast.sourceSpan; + + expect(span.start).toBe(start); + expect(span.end).toBe(end); + }; + + assertValueSpan('', 8, 18); + assertValueSpan('', 9, 19); + assertValueSpan('', 10, 20); + assertValueSpan('', 11, 21); + assertValueSpan('', 12, 22); + assertValueSpan('', 50, 60); + }); }); describe('templates', () => {