Skip to content

feature(ivy): record absolute position of template expressions - #31391

Closed
ayazhafiz wants to merge 16 commits into
angular:masterfrom
ayazhafiz:feature/expr-absolute-span
Closed

ayazhafiz wants to merge 16 commits into
angular:masterfrom
ayazhafiz:feature/expr-absolute-span

Conversation

@ayazhafiz

Copy link
Copy Markdown
Contributor

Currently, template expressions and statements have their location
recorded relative to the HTML element they are in, with no handle to
absolute location in a source file except for a line/column location.
However, the line/column location is also not entirely accurate, as it
points an entire semantic expression, and not necessarily the start of
an expression recorded by the expression parser.

To support record of the source code expressions originate from, add a
new sourceSpan field to ASTWithSource that records the absolute byte
offset of an expression within a source code.

Implement part 2 of refactoring template parsing for
stability
.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Currently, template expressions and statements have their location
recorded relative to the HTML element they are in, with no handle to
absolute location in a source file except for a line/column location.
However, the line/column location is also not entirely accurate, as it
points an entire semantic expression, and not necessarily the start of
an expression recorded by the expression parser.

What is the new behavior?

To support record of the source code expressions originate from, add a
new sourceSpan field to ASTWithSource that records the absolute byte
offset of an expression within a source code.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

See the design doc for refactoring template parsing for stability.

@ayazhafiz
ayazhafiz requested review from a team July 2, 2019 22:33
@ayazhafiz ayazhafiz self-assigned this Jul 2, 2019
@ayazhafiz
ayazhafiz requested a review from alxhub July 2, 2019 22:33
@ayazhafiz ayazhafiz added area: compiler Issues related to `ngc`, Angular's template compiler target: major This PR is targeted for the next major release feature Label used to distinguish feature request from other issues labels Jul 2, 2019
@ngbot ngbot Bot modified the milestone: needsTriage Jul 2, 2019
@ayazhafiz

ayazhafiz commented Jul 2, 2019 •

Copy link
Copy Markdown
Contributor Author

Depends on #31347. Will rebase once merged.

Edit: Done.

@ayazhafiz ayazhafiz changed the title feature(compiler): feature(compiler): record absolute position of template expressions Jul 2, 2019
@ayazhafiz
ayazhafiz force-pushed the feature/expr-absolute-span branch 2 times, most recently from c5e180e to 95d4f41 Compare July 12, 2019 18:39
@ayazhafiz
ayazhafiz requested a review from kyliau July 12, 2019 18:41
@ayazhafiz
ayazhafiz force-pushed the feature/expr-absolute-span branch from 95d4f41 to 51bfb5b Compare July 15, 2019 17:08
@ayazhafiz
ayazhafiz requested a review from JoostK July 16, 2019 17:04

@alxhub alxhub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also make this a feat(ivy) as there's no need to announce this commit to the user, especially since it won't be useful in VE at all.

@ayazhafiz ayazhafiz changed the title feature(compiler): record absolute position of template expressions feature(ivy): record absolute position of template expressions Jul 16, 2019
@ayazhafiz
ayazhafiz force-pushed the feature/expr-absolute-span branch from f60f228 to 60d142d Compare July 16, 2019 19:19
@ayazhafiz
ayazhafiz requested review from JoostK and alxhub July 16, 2019 19:19
@ayazhafiz

ayazhafiz commented Jul 16, 2019 •

Copy link
Copy Markdown
Contributor Author

@JoostK, @alxhub PTAL with updated changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird! Even if the above guard uses === undefined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, here's a simpler example: playground.

I think this may be related to microsoft/TypeScript#11498

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooh, there's a closure involved. Then it makes sense :-)

@ayazhafiz
ayazhafiz requested a review from JoostK July 16, 2019 20:39
@ayazhafiz ayazhafiz added comp: ivy and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Jul 16, 2019
@ayazhafiz
ayazhafiz force-pushed the feature/expr-absolute-span branch from ca3d671 to 569dd72 Compare July 18, 2019 18:11
@ayazhafiz
ayazhafiz requested review from a team and alxhub July 18, 2019 18:11
@ayazhafiz
ayazhafiz removed the request for review from a team July 18, 2019 18:14
ayazhafiz added a commit to ayazhafiz/codelyzer that referenced this pull request Jul 18, 2019
angular/angular#31391 introduces a breaking
change to `parseAction`, which now requires at least three parameters.
This provides a fix-forward for when the change lands.
ayazhafiz added a commit to ayazhafiz/codelyzer that referenced this pull request Jul 18, 2019
angular/angular#31391 introduces a breaking
change to `parseAction`, which now requires at least three parameters.
This provides a fix-forward for when the change lands.
ayazhafiz added a commit to ayazhafiz/codelyzer that referenced this pull request Jul 18, 2019
angular/angular#31391 introduces a breaking
change to `parseAction`, which now requires at least three parameters.
This provides a fix-forward for when the change lands.
ParsedProperty[]|null {
createBoundHostProperties(
dirMeta: CompileDirectiveSummary, sourceSpan: ParseSourceSpan,
absoluteOffset: number = sourceSpan.start.offset): ParsedProperty[]|null {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a sensible default value? Under what circumstances will this be correct/not correct?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in this case, sourceSpan is a span of byte offsets in the source file, which is what we want from absoluteOffset (sourceSpan is later used to compute the line/column offset for error locations).

This is incorrect in places where users of the function pass arbitrary or incorrect values of sourceSpan, which unfortunately there is a fair amount of.

@ayazhafiz
ayazhafiz requested a review from alxhub July 18, 2019 21:15
@ayazhafiz ayazhafiz added the action: merge The PR is ready for merge by the caretaker label Jul 19, 2019
@ayazhafiz

Copy link
Copy Markdown
Contributor Author

@ayazhafiz ayazhafiz added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Jul 19, 2019
@mhevery mhevery closed this in f65db20 Jul 22, 2019
@ayazhafiz
ayazhafiz deleted the feature/expr-absolute-span branch July 22, 2019 17:03
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
…31391)

Currently, template expressions and statements have their location
recorded relative to the HTML element they are in, with no handle to
absolute location in a source file except for a line/column location.
However, the line/column location is also not entirely accurate, as it
points an entire semantic expression, and not necessarily the start of
an expression recorded by the expression parser.

To support record of the source code expressions originate from, add a
new `sourceSpan` field to `ASTWithSource` that records the absolute byte
offset of an expression within a source code.

Implement part 2 of [refactoring template parsing for
stability](https://hackmd.io/@X3ECPVy-RCuVfba-pnvIpw/BkDUxaW84/%2FMA1oxh6jRXqSmZBcLfYdyw?type=book).

PR Close angular#31391
@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 15, 2019
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 cla: yes feature Label used to distinguish feature request from other issues merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants