Skip to content

Commit 14adaa5

Browse files
committed
fix: using v-slots without children should not be spread
1 parent 1f0fcf1 commit 14adaa5

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

packages/babel-plugin-jsx/src/transform-vue-jsx.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,25 @@ const transformJSXElement = (
9090
---> {{ default: () => [a, b], ...slots }}
9191
---> {[a, b]}
9292
*/
93-
VNodeChild = isComponent ? t.objectExpression([
94-
!!children.length && t.objectProperty(
95-
t.identifier('default'),
96-
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
97-
),
98-
...(slots ? (
99-
t.isObjectExpression(slots)
100-
? (slots! as t.ObjectExpression).properties
101-
: [t.spreadElement(slots!)]
102-
) : []),
103-
optimize && t.objectProperty(
104-
t.identifier('_'),
105-
t.numericLiteral(slotFlag),
106-
),
107-
].filter(Boolean as any)) : t.arrayExpression(children);
93+
VNodeChild = isComponent
94+
? children.length
95+
? t.objectExpression([
96+
!!children.length && t.objectProperty(
97+
t.identifier('default'),
98+
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
99+
),
100+
...(slots ? (
101+
t.isObjectExpression(slots)
102+
? (slots! as t.ObjectExpression).properties
103+
: [t.spreadElement(slots!)]
104+
) : []),
105+
optimize && t.objectProperty(
106+
t.identifier('_'),
107+
t.numericLiteral(slotFlag),
108+
),
109+
].filter(Boolean as any))
110+
: slots
111+
: t.arrayExpression(children);
108112
} else if (children.length === 1) {
109113
/*
110114
<A>{a}</A> or <A>{() => a}</A>

packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ _createVNode(_resolveComponent(\\"C\\"), {
262262
}, null, 8, [\\"model\\", \\"onUpdate:model\\"]);"
263263
`;
264264

265+
exports[`using v-slots without children should not be spread: using v-slots without children should not be spread 1`] = `
266+
"import { createVNode as _createVNode, resolveDirective as _resolveDirective, resolveComponent as _resolveComponent } from \\"vue\\";
267+
268+
_createVNode(_resolveComponent(\\"A\\"), null, slots);"
269+
`;
270+
265271
exports[`v-model target value support variable: v-model target value support variable 1`] = `
266272
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, Fragment as _Fragment } from \\"vue\\";
267273
const foo = 'foo';

packages/babel-plugin-jsx/test/snapshot.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const transpile = (
2323
},
2424
));
2525

26-
const tests: Test[] = [
26+
[
2727
{
2828
name: 'input[type="checkbox"]',
2929
from: '<input type="checkbox" v-model={test} />',
@@ -188,9 +188,11 @@ const tests: Test[] = [
188188
</>
189189
`,
190190
},
191-
];
192-
193-
tests.forEach((
191+
{
192+
name: 'using v-slots without children should not be spread',
193+
from: '<A v-slots={slots} />',
194+
},
195+
].forEach((
194196
{ name, from },
195197
) => {
196198
test(

0 commit comments

Comments
 (0)