@@ -24,6 +24,7 @@ export function transformVueJsxVapor(
24
24
) {
25
25
const s = new MagicString ( code )
26
26
let hasTextNode = false
27
+ let hasSlots = false
27
28
const rootNodes : RootNodes = [ ]
28
29
let postCallbacks : ( ( ( ) => void ) | undefined ) [ ] = [ ]
29
30
walkAST < Node > ( babelParse ( code , getLang ( id ) ) , {
@@ -124,12 +125,15 @@ export function transformVueJsxVapor(
124
125
else if ( parent ?. type === 'JSXElement'
125
126
&& isComponent ( parent . openingElement )
126
127
&& parent . children . filter ( child => s . sliceNode ( child ) . trim ( ) ) . length === 1
128
+ && ! ( isMapCallExpression ( node . expression )
129
+ || isConditionalExpression ( node )
130
+ || isLogicalExpression ( node ) )
127
131
) {
128
132
rootNodes . unshift ( {
129
133
node : node . expression ,
130
134
isAttributeValue : true ,
131
135
} )
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
133
137
s . overwrite ( node . start ! , node . expression . start ! , `<template v-for="(slot, slotName) in _toSlots(` )
134
138
s . overwrite ( node . expression . end ! , node . end ! , `)" v-slot:[slotName]="scope" :key="slotName"><component :is="slot" v-bind="scope" /></template>` )
135
139
}
@@ -197,6 +201,10 @@ export function transformVueJsxVapor(
197
201
)
198
202
}
199
203
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
+
200
208
s . prepend (
201
209
`import { ${ Array . from ( importSet ) . join ( ', ' ) } } from ${ runtime } ;` ,
202
210
)
0 commit comments