Skip to content

Commit 5919124

Browse files
committed
fix(compiler): prevent handle comment node for v-slot
1 parent 9c9d44c commit 5919124

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

.changeset/flat-snakes-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vue-jsx-vapor/compiler': patch
3+
---
4+
5+
prevent handle comment node for v-slot

packages/compiler/src/transforms/vSlot.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from '../ir'
1818
import {
1919
findProp,
20+
isEmptyText,
2021
isJSXComponent,
2122
isTemplate,
2223
resolveDirectiveNode,
@@ -70,8 +71,7 @@ function transformComponentSlot(
7071
const arg = dir && dir.arg
7172
const nonSlotTemplateChildren = children.filter(
7273
(n) =>
73-
isNonWhitespaceContent(n) &&
74-
!(n.type === 'JSXElement' && findProp(n, 'v-slot')),
74+
!isEmptyText(n) && !(n.type === 'JSXElement' && findProp(n, 'v-slot')),
7575
)
7676

7777
const [block, onExit] = createSlotBlock(node, dir, context)
@@ -242,10 +242,3 @@ function createSlotBlock(
242242
const exitBlock = context.enterBlock(block)
243243
return [block, exitBlock]
244244
}
245-
246-
export function isNonWhitespaceContent(
247-
node: JSXElement['children'][0],
248-
): boolean {
249-
if (node.type !== 'JSXText') return true
250-
return !!node.value.trim()
251-
}

packages/compiler/test/transforms/__snapshots__/vSlot.spec.ts.snap

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ exports[`compiler: transform slot > implicit default slot 1`] = `
7979
"
8080
`;
8181

82+
exports[`compiler: transform slot > named slots w/ comment 1`] = `
83+
"
84+
const n6 = _createComponent(Comp, null, {
85+
"one": () => {
86+
const n3 = t0()
87+
return n3
88+
}
89+
})
90+
return n6
91+
"
92+
`;
93+
8294
exports[`compiler: transform slot > named slots w/ implicit default slot 1`] = `
8395
"
8496
const n6 = _createComponent(Comp, null, {

packages/compiler/test/transforms/vSlot.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ describe('compiler: transform slot', () => {
199199
])
200200
})
201201

202+
test('named slots w/ comment', () => {
203+
const { ir, code } = compileWithSlots(
204+
`<Comp>
205+
{/* foo */}
206+
<template v-slot:one>foo</template>
207+
</Comp>`,
208+
)
209+
expect(code).toMatchSnapshot()
210+
expect(ir.block.operation[0].slots.length).toEqual(1)
211+
})
212+
202213
test('nested slots scoping', () => {
203214
const { ir, code } = compileWithSlots(
204215
`<Comp>

0 commit comments

Comments
 (0)