@@ -122,23 +122,11 @@ export function* generateEventExpression(
122
122
prop : CompilerDOM . DirectiveNode ,
123
123
) : Generator < Code > {
124
124
if ( prop . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
125
- let prefix = `(` ;
126
- let suffix = `)` ;
127
125
let isFirstMapping = true ;
128
126
129
127
const ast = createTsAst ( options . ts , ctx . inlineTsAsts , prop . exp . content ) ;
130
128
const isCompound = isCompoundExpression ( options . ts , ast ) ;
131
-
132
- if ( isCompound ) {
133
- ctx . addLocalVariable ( '$event' ) ;
134
-
135
- yield `(...[$event]) => {${ newLine } ` ;
136
- yield * ctx . generateConditionGuards ( ) ;
137
- prefix = `` ;
138
- suffix = `` ;
139
- }
140
-
141
- yield * generateInterpolation (
129
+ const interpolation = generateInterpolation (
142
130
options ,
143
131
ctx ,
144
132
'template' ,
@@ -162,17 +150,23 @@ export function* generateEventExpression(
162
150
} ,
163
151
prop . exp . content ,
164
152
prop . exp . loc . start . offset ,
165
- prefix ,
166
- suffix ,
153
+ isCompound ? `` : `(` ,
154
+ isCompound ? `` : `)` ,
167
155
) ;
168
156
169
157
if ( isCompound ) {
170
- ctx . removeLocalVariable ( '$event' ) ;
171
-
158
+ yield `(...[$event]) => {${ newLine } ` ;
159
+ ctx . addLocalVariable ( '$event' ) ;
160
+ yield * ctx . generateConditionGuards ( ) ;
161
+ yield * interpolation ;
172
162
yield endOfLine ;
163
+ ctx . removeLocalVariable ( '$event' ) ;
173
164
yield * ctx . generateAutoImportCompletion ( ) ;
174
165
yield `}` ;
175
166
}
167
+ else {
168
+ yield * interpolation ;
169
+ }
176
170
}
177
171
else {
178
172
yield `() => {}` ;
@@ -186,6 +180,7 @@ export function* generateModelEventExpression(
186
180
) : Generator < Code > {
187
181
if ( prop . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
188
182
yield `(...[$event]) => {${ newLine } ` ;
183
+ ctx . addLocalVariable ( '$event' ) ;
189
184
yield * ctx . generateConditionGuards ( ) ;
190
185
yield * generateInterpolation (
191
186
options ,
@@ -196,6 +191,8 @@ export function* generateModelEventExpression(
196
191
prop . exp . loc . start . offset ,
197
192
) ;
198
193
yield ` = $event${ endOfLine } ` ;
194
+ ctx . removeLocalVariable ( '$event' ) ;
195
+ yield * ctx . generateAutoImportCompletion ( ) ;
199
196
yield `}` ;
200
197
}
201
198
else {
0 commit comments