@@ -9,7 +9,7 @@ import type { Node } from '@babel/types'
9
9
import type { Options } from '../types'
10
10
import { transformVIf } from './v-if'
11
11
import { transformVFor } from './v-for'
12
- import { isConditionalExpression , isJSXElement , isJSXExpression , isLogicalExpression , isMapCallExpression } from './common'
12
+ import { isConditionalExpression , isFunctionExpression , isJSXElement , isJSXExpression , isLogicalExpression , isMapCallExpression } from './common'
13
13
14
14
export type RootNodes = {
15
15
node : Node
@@ -39,20 +39,6 @@ export function transformVueJsxVapor(
39
39
} )
40
40
postCallbacks = rootNodes [ 0 ] . postCallbacks !
41
41
}
42
- else if (
43
- parent ?. type === 'JSXAttribute'
44
- && node . type === 'JSXExpressionContainer'
45
- && / ( " | < .* ?\/ .* ?> ) / . test ( s . sliceNode ( node . expression ) )
46
- ) {
47
- rootNodes . unshift ( {
48
- node : parent . name . name === 'v-for' && node . expression . type === 'BinaryExpression'
49
- ? node . expression . right
50
- : node . expression ,
51
- postCallbacks : [ ] ,
52
- isAttributeValue : true ,
53
- } )
54
- postCallbacks = rootNodes [ 0 ] . postCallbacks !
55
- }
56
42
57
43
if (
58
44
node . type === 'JSXElement'
@@ -80,21 +66,32 @@ export function transformVueJsxVapor(
80
66
}
81
67
else if ( node . type === 'JSXAttribute' ) {
82
68
let name = s . sliceNode ( node . name )
83
- if ( / ^ o n [ A - Z ] / . test ( name ) ) {
84
- name = name . replace ( / ^ (?: o n ) ( [ A - Z ] ) / , ( _ , $1 ) => `@${ $1 . toLowerCase ( ) } ` )
85
- }
86
- else if ( ! name . startsWith ( 'v-' ) && node . value ?. type === 'JSXExpressionContainer' ) {
87
- name = `:${ name } `
88
- }
69
+ if ( node . value ?. type === 'JSXExpressionContainer' ) {
70
+ if ( / ^ o n [ A - Z ] / . test ( name ) ) {
71
+ name = name . replace ( / ^ (?: o n ) ( [ A - Z ] ) / , ( _ , $1 ) => `@${ $1 . toLowerCase ( ) } ` )
89
72
90
- if ( name . startsWith ( 'v-' ) && node . value ?. type === 'StringLiteral' ) {
91
- s . overwrite ( node . value . start ! , node . value . start ! + 1 , `"'` )
92
- s . overwrite ( node . value . end ! - 1 , node . value . end ! , `'"` )
93
- }
73
+ if ( ! isFunctionExpression ( node . value . expression ) )
74
+ s . appendRight ( node . value . expression . start ! , '($event) =>' )
75
+ }
76
+ else if ( ! name . startsWith ( 'v-' ) ) {
77
+ name = `:${ name } `
78
+ }
94
79
95
- if ( node . value ?. type === 'JSXExpressionContainer' ) {
96
80
s . overwrite ( node . value . start ! , node . value . start ! + 1 , '"' )
97
81
s . overwrite ( node . value . end ! - 1 , node . value . end ! , '"' )
82
+
83
+ rootNodes . unshift ( {
84
+ node : name === 'v-for' && node . value . expression . type === 'BinaryExpression'
85
+ ? node . value . expression . right
86
+ : node . value . expression ,
87
+ postCallbacks : [ ] ,
88
+ isAttributeValue : true ,
89
+ } )
90
+ postCallbacks = rootNodes [ 0 ] . postCallbacks !
91
+ }
92
+ else if ( node . value ?. type === 'StringLiteral' && name . startsWith ( 'v-' ) ) {
93
+ s . overwrite ( node . value . start ! , node . value . start ! + 1 , `"'` )
94
+ s . overwrite ( node . value . end ! - 1 , node . value . end ! , `'"` )
98
95
}
99
96
100
97
postCallbacks . unshift ( ( ) =>
@@ -131,14 +128,10 @@ export function transformVueJsxVapor(
131
128
s . overwrite ( node . start ! , node . start ! + 1 , '<component :is="__createTextVNode(' )
132
129
s . overwrite ( node . end ! - 1 , node . end ! , ')" />' )
133
130
134
- if (
135
- / ( " | < .* ?\/ .* ?> ) / . test ( s . sliceNode ( node . expression ) )
136
- ) {
137
- rootNodes . unshift ( {
138
- node : node . expression ,
139
- isAttributeValue : true ,
140
- } )
141
- }
131
+ rootNodes . unshift ( {
132
+ node : node . expression ,
133
+ isAttributeValue : true ,
134
+ } )
142
135
hasTextNode = true
143
136
}
144
137
}
0 commit comments