Skip to content

fix(compiler-dom): handle v-model + v-bind shorthand type edge case #13170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -48,6 +48,22 @@ return function render(_ctx, _cache) {
}"
`;

exports[`compiler: transform v-model > input with v-bind shorthand type should use dynamic model 1`] = `
"const _Vue = Vue
return function render(_ctx, _cache) {
with (_ctx) {
const { vModelDynamic: _vModelDynamic, withDirectives: _withDirectives, openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue
return _withDirectives((_openBlock(), _createElementBlock("input", {
"onUpdate:modelValue": $event => ((model) = $event)
}, null, 8 /* PROPS */, ["onUpdate:modelValue"])), [
[_vModelDynamic, model]
])
}
}"
`;

exports[`compiler: transform v-model > modifiers > .lazy 1`] = `
"const _Vue = Vue
7 changes: 7 additions & 0 deletions packages/compiler-dom/__tests__/transforms/vModel.spec.ts
Original file line number Diff line number Diff line change
@@ -63,6 +63,13 @@ describe('compiler: transform v-model', () => {
expect(generate(root).code).toMatchSnapshot()
})

test('input with v-bind shorthand type should use dynamic model', () => {
const root = transformWithModel('<input :type v-model="model" />')

expect(root.helpers).toContain(V_MODEL_DYNAMIC)
expect(generate(root).code).toMatchSnapshot()
})

test('input w/ dynamic v-bind', () => {
const root = transformWithModel('<input v-bind="obj" v-model="model" />')

2 changes: 1 addition & 1 deletion packages/compiler-dom/src/transforms/vModel.ts
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
let directiveToUse = V_MODEL_TEXT
let isInvalidType = false
if (tag === 'input' || isCustomElement) {
const type = findProp(node, `type`)
const type = findProp(node, `type`, false, true)
if (type) {
if (type.type === NodeTypes.DIRECTIVE) {
// :type="foo"