Skip to content

Commit

Permalink
fix(volar/jsx-directive): v-if and v-slot co-usage (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiyuanzmj committed May 7, 2024
1 parent fc27519 commit 1e91ca0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-laws-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-macros/volar": patch
---

v-if and v-slot co-usage
12 changes: 12 additions & 0 deletions packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ defineRender(() => (
{expectTypeOf<string>(foo)}
</span>,}}></Child>
<Child scopedSlots={{...(show) ? {'bottom': ({ foo }) => <span>
{foo}
</span>,} : null,}}
></Child>
<Child<number> scopedSlots={{...(show) ? {'title': ({ foo }) => <span>
{expectTypeOf<number>(foo)}
{show}
Expand Down Expand Up @@ -97,6 +103,12 @@ defineRender(() => (
{expectTypeOf<string>(foo)}
</>,}}></Child>
<Child v-slots={{...(show) ? {'bottom': ({ foo }) => <>
{foo}
</>,} : null,}}
></Child>
<Child<number> v-slots={{...(show) ? {'title': ({ foo }) => <>
{expectTypeOf<number>(foo)}
{show}
Expand Down
6 changes: 6 additions & 0 deletions packages/jsx-directive/tests/fixtures/v-slot/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ defineRender(() => (
{expectTypeOf<string>(foo)}
</Child>
<Child>
<template v-if={show} v-slot:bottom={{ foo }}>
{foo}
</template>
</Child>
<Child<number>>
default
<template v-if={show} v-slot:title={{ foo }}>
Expand Down
7 changes: 3 additions & 4 deletions packages/volar/src/jsx-directive/v-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ export function transformVSlot(
if (vIfAttribute && vIfAttributeName) {
if (['v-if', 'v-else-if'].includes(vIfAttributeName)) {
const nextIndex = index + (attributes[index + 1]?.[0] ? 1 : 2)
const nextAttribute = attributes[nextIndex]?.[1].vIfAttribute
result.push(
'}',
`${getText(
attributes[nextIndex]?.[1].vIfAttribute!.name,
options,
)}`.startsWith('v-else')
nextAttribute &&
`${getText(nextAttribute.name, options)}`.startsWith('v-else')
? ' : '
: ' : null,',
)
Expand Down

0 comments on commit 1e91ca0

Please sign in to comment.