8000 fix(compiler): `this.a` should always refer to class property `a` by dylhunn · Pull Request #55183 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

fix(compiler): this.a should always refer to class property a #55183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

dylhunn
Copy link
Contributor
@dylhunn dylhunn commented Apr 2, 2024

Consider a template with a context variable a:

<ng-template let-a>{{this.a}}</ng-template>

An interpolation inside that template to this.a should intuitively read the class variable a. However, today, it refers to the context variable a, both in the TCB and the generated code.

In this commit, the above interpolation now refers to the class field a.

Fixes #55115

@dylhunn dylhunn added type: bug/fix area: compiler Issues related to `ngc`, Angular's template compiler labels Apr 2, 2024
@ngbot ngbot bot modified the milestone: Backlog Apr 2, 2024
@dylhunn dylhunn added the target: major This PR is targeted for the next major release label Apr 2, 2024
@dylhunn dylhunn marked this pull request as ready for review April 2, 2024 22:19
@dylhunn dylhunn requested review from alxhub, crisbeto and mmalerba April 2, 2024 22:19
@dylhunn
Copy link
Contributor Author
dylhunn commented Apr 2, 2024

I am running a TGP to determine whether any breakages in g3 exist.

@dylhunn dylhunn force-pushed the this-shadow branch 2 times, most recently from c866bdd to a4a0494 Compare April 2, 2024 22:25
@angular-robot angular-robot bot added the detected: breaking change PR contains a commit with a breaking change label Apr 2, 2024
@JoostK
Copy link
Member
JoostK commented Apr 14, 2024

I just stumbled across

private maybeMap(ast: PropertyRead|SafePropertyRead|PropertyWrite, name: string): void {
// If the receiver of the expression isn't the `ImplicitReceiver`, this isn't the root of an
// `AST` expression that maps to a `Variable` or `Reference`.
if (!(ast.receiver instanceof ImplicitReceiver)) {
return;
}

in the binder which also seems like it inhibits the broken behavior.

@crisbeto
Copy link
Member

@JoostK
Copy link
Member
JoostK commented Apr 15, 2024

On that note, should we also update the TCB here? https://github.com/angular/angular/blob/main/packages/compiler-cli/src/ngtsc/typecheck/src/type_check_block.ts#L2289

That one was cross referenced from the template pipeline comment so it's already been updated in this PR.

@dylhunn
Copy link
Contributor Author
dylhunn commented Apr 22, 2024

Status update: this has a failing TGP (link). It mostly seems to be people referring to template local variables with this.. We'd need to fix the breakages forward in order to land this fix.

I will start sending fix CLs. They are very simple fixes, but there are quite a lot of breakage sites.

Also removing from v18, since we need some time to send and land all the g3 fixes.

@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Sep 17, 2024
@ngbot ngbot bot modified the milestone: Backlog Sep 17, 2024
dylhunn and others added 2 commits October 7, 2024 21:51
Consider a template with a context variable `a`:
```
<ng-template let-a>{{this.a}}</ng-template>
```

t push -fAn interpolation inside that template to `this.a` should intuitively read the class variable `a`. However, today, it refers to the context variable `a`, both in the TCB and the generated code.

In this commit, the above interpolation now refers to the class field `a`.

BREAKING CHANGE: `this.foo` property reads no longer refer to template context variables. If you intended to read the template variable, do not use `this.`.
Fixes angular#55115
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler and removed area: compiler Issues related to `ngc`, Angular's template compiler labels Oct 7, 2024
@ngbot ngbot bot modified the milestones: v19 Feature Freeze Candidates, Backlog Oct 7, 2024
@crisbeto
Copy link
Member
crisbeto commented Oct 8, 2024

Passing TGP

@JoostK JoostK added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Oct 8, 2024
@JoostK
Copy link
Member
JoostK commented Oct 8, 2024

caretaker note: it is advised to sync on its own, to more easily identify potential failures; this change has been heaviliy subject to backsliding.

@crisbeto
Copy link
Member
crisbeto commented Oct 8, 2024

Removing the merge label since I still haven't submitted the fixes. Will re-apply once they're submitted.

@crisbeto crisbeto removed the action: merge The PR is ready for merge by the caretaker label Oct 8, 2024
@crisbeto
Copy link
Member
crisbeto commented Oct 8, 2024

Another passing TGP after fixing a handful more failures.

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Oct 8, 2024
@crisbeto
Copy link
Member
crisbeto commented Oct 8, 2024

Ready to go now.

@devversion
Copy link
Member

This PR was merged into the repository by commit 09f589f.

The changes were merged into the following branches: main

@angular-automatic-lock-bot
Copy link

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 Nov 8, 2024
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 compiler: template pipeline compiler: template type-checking detected: breaking change PR contains a commit with a breaking change 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 type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using this keyword in templates will use template varibales instead of component variables.
9 participants
0