Skip to content

feat(ivy): translate type-check diagnostics to their original source - #30181

Closed
JoostK wants to merge 4 commits into
angular:masterfrom
JoostK:ngtsc-tcb-positions
Closed

JoostK wants to merge 4 commits into
angular:masterfrom
JoostK:ngtsc-tcb-positions

Conversation

@JoostK

@JoostK JoostK commented Apr 28, 2019 •

Copy link
Copy Markdown
Member

Currently, the template type checking that is done by the Ivy compiler
reports diagnostics that refer to a synthetic __ng_typecheck__.ts file,
so interpreting the diagnostics and finding the root cause is quite a
challenge.

This PR enables the ability to translate the diagnostics from the type-check
phase back to their original source location.


TODO:

  • Translate positions to include line/cols information
  • Properly handle external template files vs inline templates
  • Check whether current 0-based line offsets are correct, or if they need to be 1-based

KNOWN ISSUE:
Computing the start of an AST expression with respect to a ParseSourceSpan has turned out to be inaccurate. The problem is that source spans are computed with trivia skipping (since #30095) whereas the parsed AST still includes the whitespace. Moreover, the whitespace removal of text nodes messes up the offsets of interpolations, affecting the parse spans of expression AST nodes.

As an example, consider the following template:

<div>
    {{person.name}}
</div>

Here, the source span of the Text node would start at 2:4. The text node itself however would originally start at 1:5 with the AST expression having an offset of 7, and after whitespace removal will have an offset of 3 (one space remains plus the width of the interpolation opening {{). When the AST's offset of 3 is applied to the source span 2:4, the reconstructed span is computed to start at 2:7 which should be 2:6. With whitespace removal disabled it would be even further off.

@JoostK JoostK added feature Label used to distinguish feature request from other issues state: WIP target: major This PR is targeted for the next major release comp: ivy labels Apr 28, 2019
@ngbot ngbot Bot added this to the needsTriage milestone Apr 28, 2019
@JoostK
JoostK force-pushed the ngtsc-tcb-positions branch 12 times, most recently from 5984d25 to 9554fcc Compare May 7, 2019 19:28
@JoostK
JoostK force-pushed the ngtsc-tcb-positions branch 2 times, most recently from b4d3e38 to 6ad4eaa Compare May 21, 2019 19:57
@JoostK
JoostK force-pushed the ngtsc-tcb-positions branch 3 times, most recently from 4ece719 to d5abb83 Compare June 13, 2019 20:19
@JoostK
JoostK force-pushed the ngtsc-tcb-positions branch 3 times, most recently from 9a86513 to fa50663 Compare July 11, 2019 21:01
JoostK added 3 commits July 25, 2019 22:27
The type check blocks (TCB) that ngtsc generates for achieving type
checking of Angular templates needs to be annotated with positional
information in order to translate TypeScript's diagnostics for the TCB
code back to the location in the user's template. This commit augments
the TCB by attaching trailing comments with AST nodes, such that a node
can be traced back to its source location.
Template AST nodes for (bound) attributes, variables and references will
now retain a reference to the source span of their value, which allows
for more accurate type check diagnostics.
@JoostK
JoostK force-pushed the ngtsc-tcb-positions branch from e43832e to dd11406 Compare July 25, 2019 20:27
@googlebot

Copy link
Copy Markdown

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@JoostK JoostK added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed state: blocked labels Jul 25, 2019
@JoostK
JoostK marked this pull request as ready for review July 25, 2019 21:10
@JoostK
JoostK requested a review from a team July 25, 2019 21:10
@alxhub

alxhub commented Jul 25, 2019

Copy link
Copy Markdown
Member

Presubmit

@alxhub alxhub 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 25, 2019
@alxhub

alxhub commented Jul 25, 2019

Copy link
Copy Markdown
Member

Caretaker: it won't accept a force green of the g3 bit (too many statuses?) but the failure is a flake - please merge anyway.

@mhevery mhevery closed this in 8f3dd85 Jul 25, 2019
JoostK added a commit to JoostK/angular that referenced this pull request Jul 26, 2019
In angular#30181, several testcases were added that were failing in Windows.
The reason was that a recent rebase missed a required change to interact
with the compiler's virtualized filesystems. This commit introduces the
required usage of the VFS layer to fix the testcase.
AndrewKushnir pushed a commit that referenced this pull request Jul 26, 2019
In #30181, several testcases were added that were failing in Windows.
The reason was that a recent rebase missed a required change to interact
with the compiler's virtualized filesystems. This commit introduces the
required usage of the VFS layer to fix the testcase.

PR Close #31860
AndrewKushnir pushed a commit that referenced this pull request Jul 26, 2019
In #30181, several testcases were added that were failing in Windows.
The reason was that a recent rebase missed a required change to interact
with the compiler's virtualized filesystems. This commit introduces the
required usage of the VFS layer to fix the testcase.

PR Close #31860
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
…angular#30181)

The type check blocks (TCB) that ngtsc generates for achieving type
checking of Angular templates needs to be annotated with positional
information in order to translate TypeScript's diagnostics for the TCB
code back to the location in the user's template. This commit augments
the TCB by attaching trailing comments with AST nodes, such that a node
can be traced back to its source location.

PR Close angular#30181
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
…es (angular#30181)

Template AST nodes for (bound) attributes, variables and references will
now retain a reference to the source span of their value, which allows
for more accurate type check diagnostics.

PR Close angular#30181
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
sabeersulaiman pushed a commit to sabeersulaiman/angular that referenced this pull request Sep 6, 2019
In angular#30181, several testcases were added that were failing in Windows.
The reason was that a recent rebase missed a required change to interact
with the compiler's virtualized filesystems. This commit introduces the
required usage of the VFS layer to fix the testcase.

PR Close angular#31860
@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 action: presubmit The PR is in need of a google3 presubmit 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.

3 participants