File tree 5 files changed +27
-6
lines changed
packages/language-core/lib/codegen/template
test-workspace/tsc/passedFixtures
5 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,11 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
242
242
yield endOfLine ;
243
243
}
244
244
} ,
245
+ generateConditionGuards : function * ( ) {
246
+ for ( const condition of blockConditions ) {
247
+ yield `if (!${ condition } ) return${ endOfLine } ` ;
248
+ }
249
+ } ,
245
250
ignoreError : function * ( ) : Generator < Code > {
246
251
if ( ! ignoredError ) {
247
252
ignoredError = true ;
Original file line number Diff line number Diff line change @@ -122,12 +122,9 @@ export function* generateEventExpression(
122
122
if ( _isCompoundExpression ) {
123
123
yield `(...[$event]) => {${ newLine } ` ;
124
124
ctx . addLocalVariable ( '$event' ) ;
125
-
125
+ yield * ctx . generateConditionGuards ( ) ;
126
126
prefix = `` ;
127
127
suffix = `` ;
128
- for ( const blockCondition of ctx . blockConditions ) {
129
- prefix += `if (!${ blockCondition } ) return${ endOfLine } ` ;
130
- }
131
128
}
132
129
133
130
yield * generateInterpolation (
@@ -178,7 +175,8 @@ export function* generateModelEventExpression(
178
175
prop : CompilerDOM . DirectiveNode
179
176
) : Generator < Code > {
180
177
if ( prop . exp ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
181
- yield `(...[$event]) => (` ;
178
+ yield `(...[$event]) => {${ newLine } ` ;
179
+ yield * ctx . generateConditionGuards ( ) ;
182
180
yield * generateInterpolation (
183
181
options ,
184
182
ctx ,
@@ -188,7 +186,8 @@ export function* generateModelEventExpression(
188
186
prop . exp . loc . start . offset ,
189
187
prop . exp . loc
190
188
) ;
191
- yield ` = $event)` ;
189
+ yield ` = $event${ endOfLine } ` ;
190
+ yield `}` ;
192
191
}
193
192
else {
194
193
yield `() => {}` ;
Original file line number Diff line number Diff line change 29
29
" ../vue3/#4822" ,
30
30
" ../vue3/#4826" ,
31
31
" ../vue3/#4828" ,
32
+ " ../vue3/#5225" ,
32
33
" ../vue3/attrs" ,
33
34
" ../vue3/components" ,
34
35
" ../vue3/defineEmits" ,
Original file line number Diff line number Diff line change
1
+ <script setup lang="ts">
2
+ defineModel <number >({ required: true });
3
+ </script >
Original file line number Diff line number Diff line change
1
+ <script setup lang="ts">
2
+ import Comp from ' ./comp.vue' ;
3
+
4
+ let foo! : {
5
+ bar? : number ;
6
+ };
7
+ </script >
8
+
9
+ <template >
10
+ <!-- @vue-expect-error -->
11
+ <Comp v-model =" foo.bar" />
12
+ <Comp v-if =" foo.bar" v-model =" foo.bar" />
13
+ </template >
You can’t perform that action at this time.
0 commit comments