@@ -24,6 +24,7 @@ export function transformVueJsxVapor(
2424) {
2525 const s = new MagicString ( code )
2626 let hasTextNode = false
27+ let hasSlots = false
2728 const rootNodes : RootNodes = [ ]
2829 let postCallbacks : ( ( ( ) => void ) | undefined ) [ ] = [ ]
2930 walkAST < Node > ( babelParse ( code , getLang ( id ) ) , {
@@ -124,12 +125,15 @@ export function transformVueJsxVapor(
124125 else if ( parent ?. type === 'JSXElement'
125126 && isComponent ( parent . openingElement )
126127 && parent . children . filter ( child => s . sliceNode ( child ) . trim ( ) ) . length === 1
128+ && ! ( isMapCallExpression ( node . expression )
129+ || isConditionalExpression ( node )
130+ || isLogicalExpression ( node ) )
127131 ) {
128132 rootNodes . unshift ( {
129133 node : node . expression ,
130134 isAttributeValue : true ,
131135 } )
132- s . prepend ( `const _toSlots = s => (Object.prototype.toString.call(s) === '[object Object]' && !s?.__v_isVNode) ? s : { default: typeof s === 'function' ? s: () => s };` )
136+ hasSlots = true
133137 s . overwrite ( node . start ! , node . expression . start ! , `<template v-for="(slot, slotName) in _toSlots(` )
134138 s . overwrite ( node . expression . end ! , node . end ! , `)" v-slot:[slotName]="scope" :key="slotName"><component :is="slot" v-bind="scope" /></template>` )
135139 }
@@ -197,6 +201,10 @@ export function transformVueJsxVapor(
197201 )
198202 }
199203
204+ if ( hasSlots ) {
205+ s . prepend ( `const _toSlots = s => (Object.prototype.toString.call(s) === '[object Object]' && !s?.__v_isVNode) ? s : { default: typeof s === 'function' ? s: () => s };` )
206+ }
207+
200208 s . prepend (
201209 `import { ${ Array . from ( importSet ) . join ( ', ' ) } } from ${ runtime } ;` ,
202210 )
0 commit comments