Skip to content

Commit

Permalink
fix(v-model): fix incorrect codegen for non-ref bindings
Browse files Browse the repository at this point in the history
fix #6241
  • Loading branch information
yyx990803 committed Nov 10, 2022
1 parent f793faa commit 15e889a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/compiler-core/src/transforms/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
const maybeRef =
!__BROWSER__ &&
context.inline &&
bindingType &&
bindingType !== BindingTypes.SETUP_CONST
(bindingType === BindingTypes.SETUP_LET ||
bindingType === BindingTypes.SETUP_REF ||
bindingType === BindingTypes.SETUP_MAYBE_REF)

if (
!expString.trim() ||
Expand Down
20 changes: 20 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,26 @@ defineExpose({ foo: 123 })
assertCode(content)
})

test('v-model should not generate ref assignment code for non-setup bindings', () => {
const { content } = compile(
`<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>
<script>
export default {
data() { return { foo: 123 } }
}
</script>
<template>
<input v-model="foo">
</template>
`,
{ inlineTemplate: true }
)
expect(content).not.toMatch(`_isRef(foo)`)
})

test('template assignment expression codegen', () => {
const { content } = compile(
`<script setup>
Expand Down

0 comments on commit 15e889a

Please sign in to comment.