File tree 3 files changed +51
-7
lines changed
3 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,26 @@ return { modelValue }
103
103
} )"
104
104
` ;
105
105
106
+ exports [` defineModel() > w/ Boolean And Function types, production mode 1` ] = `
107
+ "import { useModel as _useModel , defineComponent as _defineComponent } from 'vue'
108
+
109
+ export default /*#__PURE__*/_defineComponent({
110
+ props : {
111
+ " modelValue" : { type: [Boolean , String ] },
112
+ " modelModifiers" : {},
113
+ },
114
+ emits : [" update:modelValue" ],
115
+ setup (__props , { expose: __expose }) {
116
+ __expose();
117
+
118
+ const modelValue = _useModel<boolean | string >(__props , "modelValue ")
119
+
120
+ return { modelValue }
121
+ }
122
+
123
+ } )"
124
+ ` ;
125
+
106
126
exports [` defineModel() > w/ array props 1` ] = `
107
127
"import { useModel as _useModel , mergeModels as _mergeModels } from 'vue'
108
128
Original file line number Diff line number Diff line change @@ -221,4 +221,24 @@ describe('defineModel()', () => {
221
221
assertCode ( content )
222
222
expect ( content ) . toMatch ( `set: (v) => { return v + __props.x }` )
223
223
} )
224
+
225
+ test ( 'w/ Boolean And Function types, production mode' , ( ) => {
226
+ const { content, bindings } = compile (
227
+ `
228
+ <script setup lang="ts">
229
+ const modelValue = defineModel<boolean | string>()
230
+ </script>
231
+ ` ,
232
+ { isProd : true } ,
233
+ )
234
+ assertCode ( content )
235
+ expect ( content ) . toMatch ( '"modelValue": { type: [Boolean, String] }' )
236
+ expect ( content ) . toMatch ( 'emits: ["update:modelValue"]' )
237
+ expect ( content ) . toMatch (
238
+ `const modelValue = _useModel<boolean | string>(__props, "modelValue")` ,
239
+ )
240
+ expect ( bindings ) . toStrictEqual ( {
241
+ modelValue : BindingTypes . SETUP_REF ,
242
+ } )
243
+ } )
224
244
} )
Original file line number Diff line number Diff line change @@ -129,15 +129,19 @@ export function genModelProps(ctx: ScriptCompileContext) {
129
129
130
130
let runtimeTypes = type && inferRuntimeType ( ctx , type )
131
131
if ( runtimeTypes ) {
132
+ const hasBoolean = runtimeTypes . includes ( 'Boolean' )
132
133
const hasUnknownType = runtimeTypes . includes ( UNKNOWN_TYPE )
133
134
134
- runtimeTypes = runtimeTypes . filter ( el => {
135
- if ( el === UNKNOWN_TYPE ) return false
136
- return isProd
137
- ? el === 'Boolean' || ( el === 'Function' && options )
138
- : true
139
- } )
140
- skipCheck = ! isProd && hasUnknownType && runtimeTypes . length > 0
135
+ if ( isProd || hasUnknownType ) {
136
+ runtimeTypes = runtimeTypes . filter (
137
+ t =>
138
+ t === 'Boolean' ||
139
+ ( hasBoolean && t === 'String' ) ||
140
+ ( t === 'Function' && options ) ,
141
+ )
142
+
143
+ skipCheck = ! isProd && hasUnknownType && runtimeTypes . length > 0
144
+ }
141
145
}
142
146
143
147
let runtimeType =
You can’t perform that action at this time.
0 commit comments