@@ -23,8 +23,6 @@ export function transformVueJsxVapor(
23
23
options : Options ,
24
24
) {
25
25
const s = new MagicString ( code )
26
- let hasTextNode = false
27
- let hasSlots = false
28
26
const rootNodes : RootNodes = [ ]
29
27
let postCallbacks : ( ( ( ) => void ) | undefined ) [ ] = [ ]
30
28
walkAST < Node > ( babelParse ( code , getLang ( id ) ) , {
@@ -133,8 +131,7 @@ export function transformVueJsxVapor(
133
131
node : node . expression ,
134
132
isAttributeValue : true ,
135
133
} )
136
- hasSlots = true
137
- s . overwrite ( node . start ! , node . expression . start ! , `<template v-for="(slot, slotName) in _toSlots(` )
134
+ s . overwrite ( node . start ! , node . expression . start ! , `<template v-for="(slot, slotName) in _resolveSlots(` )
138
135
s . overwrite ( node . expression . end ! , node . end ! , `)" v-slot:[slotName]="scope" :key="slotName"><component :is="slot" v-bind="scope" /></template>` )
139
136
}
140
137
else if ( ! isJSXExpression ( node . expression ) ) {
@@ -145,7 +142,6 @@ export function transformVueJsxVapor(
145
142
node : node . expression ,
146
143
isAttributeValue : true ,
147
144
} )
148
- hasTextNode = true
149
145
}
150
146
}
151
147
} ,
@@ -193,16 +189,16 @@ export function transformVueJsxVapor(
193
189
}
194
190
}
195
191
196
- if ( hasTextNode ) {
192
+ const result = s . toString ( )
193
+ if ( result . includes ( '_resolveJSXExpression' ) ) {
197
194
importSet . add ( 'createTextVNode as _createTextVNode' )
198
195
importSet . add ( 'toDisplayString as _toDisplayString' )
199
196
s . prepend (
200
- `const _resolveJSXExpression = ( node) => node?.__v_isVNode || typeof node === 'function' || (Array.isArray(node) && node[0]?.__v_isVNode) ? node : _createTextVNode(_toDisplayString(node));` ,
197
+ `const _resolveJSXExpression = node => node?.__v_isVNode || typeof node === 'function' || (Array.isArray(node) && node[0]?.__v_isVNode) ? node : _createTextVNode(_toDisplayString(node));` ,
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 };` )
200
+ if ( result . includes ( '_resolveSlots' ) ) {
201
+ s . prepend ( `const _resolveSlots = s => (Object.prototype.toString.call(s) === '[object Object]' && !s?.__v_isVNode) ? s : { default: typeof s === 'function' ? s: () => s };` )
206
202
}
207
203
208
204
s . prepend (
0 commit comments