From abc2d8ed9cec13fbf55197313e1f41dccd4d90f9 Mon Sep 17 00:00:00 2001 From: Kael Date: Thu, 30 Mar 2023 03:16:08 +1100 Subject: [PATCH] fix: add slotFlags for implicit default slots --- packages/babel-plugin-jsx/src/transform-vue-jsx.ts | 14 +++++++++++--- .../test/__snapshots__/snapshot.test.ts.snap | 3 ++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts index 6b02ac94..adf0661b 100644 --- a/packages/babel-plugin-jsx/src/transform-vue-jsx.ts +++ b/packages/babel-plugin-jsx/src/transform-vue-jsx.ts @@ -459,7 +459,11 @@ const transformJSXElement = ( t.identifier('default'), child, ), - ]); + optimize && t.objectProperty( + t.identifier('_'), + t.numericLiteral(slotFlag), + ) as any, + ].filter(Boolean)); } else if (t.isObjectExpression(child)) { VNodeChild = t.objectExpression([ ...child.properties, @@ -472,9 +476,13 @@ const transformJSXElement = ( VNodeChild = isComponent ? t.objectExpression([ t.objectProperty( t.identifier('default'), - t.arrowFunctionExpression([], t.arrayExpression([child])), + t.arrowFunctionExpression([], child), ), - ]) : t.arrayExpression([child]); + optimize && t.objectProperty( + t.identifier('_'), + t.numericLiteral(slotFlag), + ) as any, + ].filter(Boolean)) : t.arrayExpression([child]); } } diff --git a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap index 27e0d216..e2c666bc 100644 --- a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap +++ b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap @@ -158,7 +158,8 @@ _createVNode(_resolveComponent(\\"A\\"), null, { exports[`passing object slots via JSX children single expression, function expression: single expression, function expression 1`] = ` "import { createVNode as _createVNode, resolveComponent as _resolveComponent } from \\"vue\\"; _createVNode(_resolveComponent(\\"A\\"), null, { - default: () => \\"foo\\" + default: () => \\"foo\\", + _: 1 });" `;