fix(no-dupe-keys): detect locals aliasing a different prop - #3124
Open
ValentinYoushkevich wants to merge 1 commit into
Open
fix(no-dupe-keys): detect locals aliasing a different prop#3124ValentinYoushkevich wants to merge 1 commit into
ValentinYoushkevich wants to merge 1 commit into
Conversation
🦋 Changeset detectedLatest commit: 9279875 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
onDefinePropsEnterskips a local declaration that shadows a prop whenever the initializer mentions the props object anywhere (isInsideInitializer, added in #2189 soconst foo = toRef(props, 'foo')stays valid). The check only asks whether props is touched, not which prop is read, so it also hides real collisions:The template's
fooresolves toprops.barand propfoobecomes unreachable — exactly what the rule exists to catch.The exemption is now skipped when the declaration provably aliases a different prop:
props.bar,props['bar'],toRef(props, 'bar'),const { bar: foo } = propsandconst { bar: foo } = toRefs(props). Same-name aliases keep passing, and declarations whose source prop can't be resolved (toRef(props, key),computed(() => props.bar + 1)) are still left alone, so no new false positives.The exact snippet from the issue (
const foo = toRef(props, 'foo')) stays valid: it is a valid test from #2189, the setup binding wins in the template and unwraps to the same value the prop holds. Only the different-prop variants are reported. The Options APIsetup()path is untouched.Refs #3070
The literal snippet from the report stays valid, so this does not close the issue by itself. Making that one error means reverting #2189 and reporting
const { foo } = toRefs(props)andconst foo = props.fooalong with it — happy to redo it that way if that is what you want.