feat(compiler-cli): add extended diagnostic for template reference shadowing class member#67226
Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Open
Conversation
…adowing class member Add a new extended template diagnostic that warns when a template reference variable (#name) has the same name as a property or method on the component class. This can cause confusion since the template reference takes precedence over the class member within the template. The diagnostic covers: - Direct class properties and methods - Inherited properties from base classes - Private, protected, and public members Fixes angular#45227
Member
|
While I get the purpose of this check, I'm afraid it's in the scope of "very breaking" to "too breaking for us to land" (as shown by our internal tests). |
|
Isn't it fine as you can access with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Feature (new extended template diagnostic)
What is the current behavior?
When a template reference variable (
#name) has the same name as a component class property or method, there is no warning. This can lead to confusion, because inside the template the reference variable takes precedence over the class member.For example:
Here
{{ name }}resolves to the template reference (the<div>element), not the string'Angular'.Closes #45227
What is the new behavior?
A new extended template diagnostic (
templateReferenceShadowsClassMember, NG8119) warns when a template reference variable shadows a component class member. The warning covers:The diagnostic is emitted as a warning (not an error), consistent with other extended diagnostics.
Additional context
A previous PR (#48658) attempted this but was closed due to missing cases (inherited properties, template variable scoping). This implementation:
TypeChecker.getTypeAtLocation()+getProperty()which automatically resolves inherited memberskeySpanof the reference for precise source mapping