Skip to content

Leading whitespace in input value causes incorrect source span #63069

@reduckted

Description

@reduckted

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

When an input's value has leading whitespace, the source span of that value is increased by twice the length of the whitespace.

Using the repository linked below, run npm start. A template will be parsed and the location of the PropertyRead in the element's input will be found. It will then print the template and the location of where the PropertyRead was found.

When there is no leading whitespace, the span of the value is correct. With one leading space, the value is reported as being one characters further into the string. With two leading spaces, the value is reported as being two characters further into the string, and so on.

This reproduction uses a PropertyRead for simplicity, but the problem applies to anything in an ASTWithSource.

Please provide a link to a minimal reproduction of the bug

https://github.com/reduckted/repro-angular-compiler-whitespace

Please provide the exception or error you saw

<a [b]="c"></a>
________^______ : 8-9

<a [b]=" c"></a>
__________^_____ : 10-11

<a [b]="  c"></a>
____________^____ : 12-13

<a [b]="   c"></a>
______________^___ : 14-15

<a [b]="    c"></a>
________________^__ : 16-17

Please provide the environment you discovered this bug in (run ng version)

@angular/compiler 20.1.6

Anything else?

This is causing problems in angular-eslint because the location of ESLint warnings are not reported correctly, meaning the fixes change the wrong span of code.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions