@@ -18,6 +18,7 @@ export function transformVueJsxVapor(
18
18
) {
19
19
const s = new MagicString ( code )
20
20
const exclude : Node [ ] = [ ]
21
+ let hasTextNode = false
21
22
const rootNodes : {
22
23
node : Node
23
24
postCallbacks : ( ( ( ) => void ) | undefined ) [ ]
@@ -27,28 +28,6 @@ export function transformVueJsxVapor(
27
28
walkAST < Node > ( babelParse ( code , getLang ( id ) ) , {
28
29
enter ( node , parent ) {
29
30
if (
30
- parent ?. type === 'JSXAttribute'
31
- && node . type === 'JSXExpressionContainer'
32
- ) {
33
- if ( isJSXExpression ( node . expression ) ) {
34
- rootNodes . unshift ( {
35
- node : node . expression ,
36
- postCallbacks : [ ] ,
37
- isAttributeValue : true ,
38
- } )
39
- postCallbacks = rootNodes [ 0 ] . postCallbacks
40
- }
41
- else if (
42
- / ( " | < .* ?\/ .* ?> ) / . test ( s . sliceNode ( node . expression ) )
43
- ) {
44
- rootNodes . unshift ( {
45
- node : node . expression ,
46
- postCallbacks : [ ] ,
47
- isAttributeValue : true ,
48
- } )
49
- }
50
- }
51
- else if (
52
31
parent ?. type !== 'JSXExpressionContainer'
53
32
&& ! isJSXExpression ( parent )
54
33
&& isJSXExpression ( node )
@@ -60,6 +39,18 @@ export function transformVueJsxVapor(
60
39
} )
61
40
postCallbacks = rootNodes [ 0 ] . postCallbacks
62
41
}
42
+ else if (
43
+ ( parent ?. type === 'JSXAttribute' )
44
+ && node . type === 'JSXExpressionContainer'
45
+ && / ( " | < .* ?\/ .* ?> ) / . test ( s . sliceNode ( node . expression ) )
46
+ ) {
47
+ rootNodes . unshift ( {
48
+ node : node . expression ,
49
+ postCallbacks : [ ] ,
50
+ isAttributeValue : true ,
51
+ } )
52
+ postCallbacks = rootNodes [ 0 ] . postCallbacks
53
+ }
63
54
64
55
if (
65
56
node . type === 'JSXElement'
@@ -130,9 +121,19 @@ export function transformVueJsxVapor(
130
121
s . removeNode ( node ) ,
131
122
)
132
123
}
133
- else {
134
- s . appendRight ( node . start ! , '{' )
135
- s . appendLeft ( node . end ! , '}' )
124
+ else if ( ! isJSXExpression ( node . expression ) ) {
125
+ s . overwrite ( node . start ! , node . start ! + 1 , '<component :is="__createTextVNode(' )
126
+ s . overwrite ( node . end ! - 1 , node . end ! , ')" />' )
127
+ if (
128
+ / ( " | < .* ?\/ .* ?> ) / . test ( s . sliceNode ( node . expression ) )
129
+ ) {
130
+ rootNodes . unshift ( {
131
+ node : node . expression ,
132
+ postCallbacks : [ ] ,
133
+ isAttributeValue : true ,
134
+ } )
135
+ }
136
+ hasTextNode = true
136
137
}
137
138
}
138
139
} ,
@@ -182,6 +183,14 @@ export function transformVueJsxVapor(
182
183
}
183
184
}
184
185
186
+ if ( hasTextNode ) {
187
+ importSet . add ( 'createTextVNode as _createTextVNode' )
188
+ importSet . add ( 'toDisplayString as _toDisplayString' )
189
+ s . prepend (
190
+ `const __createTextVNode = (node) => node?.__v_isVNode || typeof node ==='function' ? node: _createTextVNode(_toDisplayString(node));` ,
191
+ )
192
+ }
193
+
185
194
s . prepend (
186
195
`import { ${ Array . from ( importSet ) . join ( ', ' ) } } from ${ runtime } ;` ,
187
196
)
0 commit comments