Skip to content
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

fix(no-deprecated-slot-attribute): handle v-for with dynamic slot #2529

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

privatenumber
Copy link
Contributor

Fixes an edge-case where the slot is dynamic derived from a v-for.

Previously, it would move the slot directive in a new <template> above the v-for, which broke it.

Now, it also moves the v-for to the new <template>.

const vForText = vFor ? `${sourceCode.getText(vFor)} ` : ''
if (vFor) {
yield fixer.remove(vFor)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also considered the case for v-if—would an empty template still cause the parent to think it received an empty slot?

But I confirmed in Vue 2 that these are identical in terms of the parent's this.$slots:

<Parent>
  <div v-if="false" slot="name">
  	slot value
  </div>

  <template slot="name">
    <div v-if="false">
      slot value
    </div>
  </template>
</Parent>

const slotName = sourceCode.getText(slotAttr.value.expression).trim()
// If non-Latin characters are included it can not be converted.
// It does not check the space only because `a>b?c:d` should be rejected.
return !/[^a-z]/i.test(slotName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was confused about why it's doing this.

I felt like we just want to confirm it's a single Identifier so I went ahead and changed it and it didn't seem to break any tests, but I'm happy to revert this if we want to keep the scope small.

Copy link
Member

@FloEdelmann FloEdelmann left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks for your contribution!

Copy link
Member

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

@ota-meshi ota-meshi merged commit b08273c into vuejs:master Sep 2, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants