fix: using v-slots without children should not be spread

This commit is contained in:
Amour1688 2021-04-18 11:00:35 +08:00
parent 1f0fcf1049
commit 14adaa5f3a
3 changed files with 31 additions and 19 deletions

View File

@ -90,21 +90,25 @@ const transformJSXElement = (
---> {{ default: () => [a, b], ...slots }}
---> {[a, b]}
*/
VNodeChild = isComponent ? t.objectExpression([
!!children.length && t.objectProperty(
t.identifier('default'),
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
),
...(slots ? (
t.isObjectExpression(slots)
? (slots! as t.ObjectExpression).properties
: [t.spreadElement(slots!)]
) : []),
optimize && t.objectProperty(
t.identifier('_'),
t.numericLiteral(slotFlag),
),
].filter(Boolean as any)) : t.arrayExpression(children);
VNodeChild = isComponent
? children.length
? t.objectExpression([
!!children.length && t.objectProperty(
t.identifier('default'),
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
),
...(slots ? (
t.isObjectExpression(slots)
? (slots! as t.ObjectExpression).properties
: [t.spreadElement(slots!)]
) : []),
optimize && t.objectProperty(
t.identifier('_'),
t.numericLiteral(slotFlag),
),
].filter(Boolean as any))
: slots
: t.arrayExpression(children);
} else if (children.length === 1) {
/*
<A>{a}</A> or <A>{() => a}</A>

View File

@ -262,6 +262,12 @@ _createVNode(_resolveComponent(\\"C\\"), {
}, null, 8, [\\"model\\", \\"onUpdate:model\\"]);"
`;
exports[`using v-slots without children should not be spread: using v-slots without children should not be spread 1`] = `
"import { createVNode as _createVNode, resolveDirective as _resolveDirective, resolveComponent as _resolveComponent } from \\"vue\\";
_createVNode(_resolveComponent(\\"A\\"), null, slots);"
`;
exports[`v-model target value support variable: v-model target value support variable 1`] = `
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, Fragment as _Fragment } from \\"vue\\";
const foo = 'foo';

View File

@ -23,7 +23,7 @@ const transpile = (
},
));
const tests: Test[] = [
[
{
name: 'input[type="checkbox"]',
from: '<input type="checkbox" v-model={test} />',
@ -188,9 +188,11 @@ const tests: Test[] = [
</>
`,
},
];
tests.forEach((
{
name: 'using v-slots without children should not be spread',
from: '<A v-slots={slots} />',
},
].forEach((
{ name, from },
) => {
test(