Skip to content

Commit fe82150

Browse files
author
RicardoErii
committed
fix(compiler-sfc): adjusting the type compilation of defineModel in the prod
1 parent d6277b1 commit fe82150

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

packages/compiler-sfc/__tests__/compileScript/__snapshots__/defineModel.spec.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports[`defineModel() > w/ Boolean types, production mode 1`] = `
2828
2929
export default /*#__PURE__*/_defineComponent({
3030
props: {
31-
\\"modelValue\\": { type: [Boolean, String, Number] },
31+
\\"modelValue\\": { type: [Boolean, String] },
3232
},
3333
emits: [\\"update:modelValue\\"],
3434
setup(__props, { expose: __expose }) {

packages/compiler-sfc/__tests__/compileScript/defineModel.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('defineModel()', () => {
192192
{ defineModel: true, isProd: true }
193193
)
194194
assertCode(content)
195-
expect(content).toMatch('"modelValue": { type: [Boolean, String, Number] }')
195+
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
196196
expect(content).toMatch('emits: ["update:modelValue"]')
197197
expect(content).toMatch(
198198
`const modelValue = _useModel(__props, "modelValue")`

packages/compiler-sfc/src/script/defineModel.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ export function genModelProps(ctx: ScriptCompileContext) {
118118

119119
let runtimeTypes = type && inferRuntimeType(ctx, type)
120120
if (runtimeTypes) {
121+
const hasBoolean = runtimeTypes.includes('Boolean')
121122
const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE)
122123

123-
runtimeTypes = runtimeTypes.filter(el => el !== UNKNOWN_TYPE)
124-
125-
if (
126-
isProd &&
127-
!runtimeTypes.some(
128-
el => el === 'Boolean' || (el === 'Function' && options)
124+
if (isProd || hasUnknownType) {
125+
runtimeTypes = runtimeTypes.filter(
126+
t =>
127+
t === 'Boolean' ||
128+
(hasBoolean && t === 'String') ||
129+
(t === 'Function' && options)
129130
)
130-
) {
131-
runtimeTypes = []
131+
132+
skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0
132133
}
133-
skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0
134134
}
135135

136136
let runtimeType =

0 commit comments

Comments
 (0)