Skip to content

Commit

Permalink
fix(compiler-sfc): adjusting the type compilation of defineModel in t…
Browse files Browse the repository at this point in the history
…he prod
  • Loading branch information
RicardoErii committed Nov 15, 2023
1 parent d6277b1 commit fe82150
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`defineModel() > w/ Boolean types, production mode 1`] = `
export default /*#__PURE__*/_defineComponent({
props: {
\\"modelValue\\": { type: [Boolean, String, Number] },
\\"modelValue\\": { type: [Boolean, String] },
},
emits: [\\"update:modelValue\\"],
setup(__props, { expose: __expose }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('defineModel()', () => {
{ defineModel: true, isProd: true }
)
assertCode(content)
expect(content).toMatch('"modelValue": { type: [Boolean, String, Number] }')
expect(content).toMatch('"modelValue": { type: [Boolean, String] }')
expect(content).toMatch('emits: ["update:modelValue"]')
expect(content).toMatch(
`const modelValue = _useModel(__props, "modelValue")`
Expand Down
18 changes: 9 additions & 9 deletions packages/compiler-sfc/src/script/defineModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,19 @@ export function genModelProps(ctx: ScriptCompileContext) {

let runtimeTypes = type && inferRuntimeType(ctx, type)
if (runtimeTypes) {
const hasBoolean = runtimeTypes.includes('Boolean')
const hasUnknownType = runtimeTypes.includes(UNKNOWN_TYPE)

runtimeTypes = runtimeTypes.filter(el => el !== UNKNOWN_TYPE)

if (
isProd &&
!runtimeTypes.some(
el => el === 'Boolean' || (el === 'Function' && options)
if (isProd || hasUnknownType) {
runtimeTypes = runtimeTypes.filter(
t =>
t === 'Boolean' ||
(hasBoolean && t === 'String') ||
(t === 'Function' && options)
)
) {
runtimeTypes = []

skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0
}
skipCheck = !isProd && hasUnknownType && runtimeTypes.length > 0
}

let runtimeType =
Expand Down

0 comments on commit fe82150

Please sign in to comment.