mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-04-24 10:32:33 +08:00
fix: using v-slots without children should not be spread
This commit is contained in:
parent
1f0fcf1049
commit
14adaa5f3a
@ -90,21 +90,25 @@ const transformJSXElement = (
|
|||||||
---> {{ default: () => [a, b], ...slots }}
|
---> {{ default: () => [a, b], ...slots }}
|
||||||
---> {[a, b]}
|
---> {[a, b]}
|
||||||
*/
|
*/
|
||||||
VNodeChild = isComponent ? t.objectExpression([
|
VNodeChild = isComponent
|
||||||
!!children.length && t.objectProperty(
|
? children.length
|
||||||
t.identifier('default'),
|
? t.objectExpression([
|
||||||
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
|
!!children.length && t.objectProperty(
|
||||||
),
|
t.identifier('default'),
|
||||||
...(slots ? (
|
t.arrowFunctionExpression([], t.arrayExpression(buildIIFE(path, children))),
|
||||||
t.isObjectExpression(slots)
|
),
|
||||||
? (slots! as t.ObjectExpression).properties
|
...(slots ? (
|
||||||
: [t.spreadElement(slots!)]
|
t.isObjectExpression(slots)
|
||||||
) : []),
|
? (slots! as t.ObjectExpression).properties
|
||||||
optimize && t.objectProperty(
|
: [t.spreadElement(slots!)]
|
||||||
t.identifier('_'),
|
) : []),
|
||||||
t.numericLiteral(slotFlag),
|
optimize && t.objectProperty(
|
||||||
),
|
t.identifier('_'),
|
||||||
].filter(Boolean as any)) : t.arrayExpression(children);
|
t.numericLiteral(slotFlag),
|
||||||
|
),
|
||||||
|
].filter(Boolean as any))
|
||||||
|
: slots
|
||||||
|
: t.arrayExpression(children);
|
||||||
} else if (children.length === 1) {
|
} else if (children.length === 1) {
|
||||||
/*
|
/*
|
||||||
<A>{a}</A> or <A>{() => a}</A>
|
<A>{a}</A> or <A>{() => a}</A>
|
||||||
|
@ -262,6 +262,12 @@ _createVNode(_resolveComponent(\\"C\\"), {
|
|||||||
}, null, 8, [\\"model\\", \\"onUpdate:model\\"]);"
|
}, 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`] = `
|
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\\";
|
"import { createVNode as _createVNode, resolveComponent as _resolveComponent, Fragment as _Fragment } from \\"vue\\";
|
||||||
const foo = 'foo';
|
const foo = 'foo';
|
||||||
|
@ -23,7 +23,7 @@ const transpile = (
|
|||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
const tests: Test[] = [
|
[
|
||||||
{
|
{
|
||||||
name: 'input[type="checkbox"]',
|
name: 'input[type="checkbox"]',
|
||||||
from: '<input type="checkbox" v-model={test} />',
|
from: '<input type="checkbox" v-model={test} />',
|
||||||
@ -188,9 +188,11 @@ const tests: Test[] = [
|
|||||||
</>
|
</>
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
];
|
{
|
||||||
|
name: 'using v-slots without children should not be spread',
|
||||||
tests.forEach((
|
from: '<A v-slots={slots} />',
|
||||||
|
},
|
||||||
|
].forEach((
|
||||||
{ name, from },
|
{ name, from },
|
||||||
) => {
|
) => {
|
||||||
test(
|
test(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user