@@ -23,8 +23,6 @@ export function transformVueJsxVapor(
2323 options : Options ,
2424) {
2525 const s = new MagicString ( code )
26- let hasTextNode = false
27- let hasSlots = false
2826 const rootNodes : RootNodes = [ ]
2927 let postCallbacks : ( ( ( ) => void ) | undefined ) [ ] = [ ]
3028 walkAST < Node > ( babelParse ( code , getLang ( id ) ) , {
@@ -133,8 +131,7 @@ export function transformVueJsxVapor(
133131 node : node . expression ,
134132 isAttributeValue : true ,
135133 } )
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(` )
138135 s . overwrite ( node . expression . end ! , node . end ! , `)" v-slot:[slotName]="scope" :key="slotName"><component :is="slot" v-bind="scope" /></template>` )
139136 }
140137 else if ( ! isJSXExpression ( node . expression ) ) {
@@ -145,7 +142,6 @@ export function transformVueJsxVapor(
145142 node : node . expression ,
146143 isAttributeValue : true ,
147144 } )
148- hasTextNode = true
149145 }
150146 }
151147 } ,
@@ -193,16 +189,16 @@ export function transformVueJsxVapor(
193189 }
194190 }
195191
196- if ( hasTextNode ) {
192+ const result = s . toString ( )
193+ if ( result . includes ( '_resolveJSXExpression' ) ) {
197194 importSet . add ( 'createTextVNode as _createTextVNode' )
198195 importSet . add ( 'toDisplayString as _toDisplayString' )
199196 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));` ,
201198 )
202199 }
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 };` )
206202 }
207203
208204 s . prepend (
0 commit comments