Skip to content

fix(compiler): incorrect spans for AST inside input value with leading space#63082

Closed
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:63069/value-ast-spans
Closed

fix(compiler): incorrect spans for AST inside input value with leading space#63082
crisbeto wants to merge 1 commit intoangular:mainfrom
crisbeto:63069/value-ast-spans

Conversation

@crisbeto
Copy link
Copy Markdown
Member

When parsing expressions inside a bound attribute, we offset all of its spans by an absoluteOffset in order to get the right spans in the source file. The offset was incorrect when parsing an attribute with leading spaces during the construction of the Ivy AST, because of the combination of:

  1. We were setting the offset by looking at valueSpan.start.
  2. The Ivy parser sets leadingTriviaChars: [' ', '\n'] which means that spaces and new lines will be ignored in the sourceSpan.start.

These changes resolve the issue by using valueSpan.fullStart which includes the leading spaces.

Fixes #63069.

…g space

When parsing expressions inside a bound attribute, we offset all of its spans by an `absoluteOffset` in order to get the right spans in the source file. The offset was incorrect when parsing an attribute with leading spaces during the construction of the Ivy AST, because of the combination of:
1. We were setting the offset by looking at `valueSpan.start`.
2. The Ivy parser sets `leadingTriviaChars: [' ', '\n']` which means that spaces and new lines will be ignored in the `sourceSpan.start`.

These changes resolve the issue by using `valueSpan.fullStart` which includes the leading spaces.

Fixes angular#63069.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Aug 11, 2025
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Aug 11, 2025
@ngbot ngbot bot added this to the Backlog milestone Aug 11, 2025
@crisbeto crisbeto requested a review from devversion August 11, 2025 08:44
@crisbeto crisbeto removed the request for review from devversion August 11, 2025 08:51
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer action: merge The PR is ready for merge by the caretaker labels Aug 11, 2025
atscott pushed a commit that referenced this pull request Aug 11, 2025
…g space (#63082)

When parsing expressions inside a bound attribute, we offset all of its spans by an `absoluteOffset` in order to get the right spans in the source file. The offset was incorrect when parsing an attribute with leading spaces during the construction of the Ivy AST, because of the combination of:
1. We were setting the offset by looking at `valueSpan.start`.
2. The Ivy parser sets `leadingTriviaChars: [' ', '\n']` which means that spaces and new lines will be ignored in the `sourceSpan.start`.

These changes resolve the issue by using `valueSpan.fullStart` which includes the leading spaces.

Fixes #63069.

PR Close #63082
@atscott
Copy link
Copy Markdown
Contributor

atscott commented Aug 11, 2025

This PR was merged into the repository by commit d17555a.

The changes were merged into the following branches: main, 20.1.x, 20.2.x

@atscott atscott closed this in d17555a Aug 11, 2025
atscott pushed a commit that referenced this pull request Aug 11, 2025
…g space (#63082)

When parsing expressions inside a bound attribute, we offset all of its spans by an `absoluteOffset` in order to get the right spans in the source file. The offset was incorrect when parsing an attribute with leading spaces during the construction of the Ivy AST, because of the combination of:
1. We were setting the offset by looking at `valueSpan.start`.
2. The Ivy parser sets `leadingTriviaChars: [' ', '\n']` which means that spaces and new lines will be ignored in the `sourceSpan.start`.

These changes resolve the issue by using `valueSpan.fullStart` which includes the leading spaces.

Fixes #63069.

PR Close #63082
crisbeto added a commit to crisbeto/angular that referenced this pull request Aug 15, 2025
…te attribute

Similar fix as angular#63082, but for template attributes. The root cause is the same where we should be using `fullStart` instead of `start` in order to account for whitespaces being skipped.

Fixes angular#63157.
crisbeto added a commit that referenced this pull request Aug 15, 2025
…te attribute (#63175)

Similar fix as #63082, but for template attributes. The root cause is the same where we should be using `fullStart` instead of `start` in order to account for whitespaces being skipped.

Fixes #63157.

PR Close #63175
crisbeto added a commit that referenced this pull request Aug 15, 2025
…te attribute (#63175)

Similar fix as #63082, but for template attributes. The root cause is the same where we should be using `fullStart` instead of `start` in order to account for whitespaces being skipped.

Fixes #63157.

PR Close #63175
crisbeto added a commit that referenced this pull request Aug 15, 2025
…te attribute (#63175)

Similar fix as #63082, but for template attributes. The root cause is the same where we should be using `fullStart` instead of `start` in order to account for whitespaces being skipped.

Fixes #63157.

PR Close #63175
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Leading whitespace in input value causes incorrect source span

3 participants