mirror of https://github.com/vuejs/core.git
fix(v-model): unnecessary value binding error should apply to dynamic instead of static binding
close #3596
This commit is contained in:
parent
f18a174979
commit
2859b653c9
|
@ -137,6 +137,27 @@ describe('compiler: transform v-model', () => {
|
|||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('should error on dynamic value binding alongside v-model', () => {
|
||||
const onError = vi.fn()
|
||||
transformWithModel(`<input v-model="test" :value="test" />`, {
|
||||
onError
|
||||
})
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
code: DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
// #3596
|
||||
test('should NOT error on static value binding alongside v-model', () => {
|
||||
const onError = vi.fn()
|
||||
transformWithModel(`<input v-model="test" value="test" />`, {
|
||||
onError
|
||||
})
|
||||
expect(onError).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('modifiers', () => {
|
||||
|
|
|
@ -4,7 +4,9 @@ import {
|
|||
ElementTypes,
|
||||
findProp,
|
||||
NodeTypes,
|
||||
hasDynamicKeyVBind
|
||||
hasDynamicKeyVBind,
|
||||
findDir,
|
||||
isStaticArgOf
|
||||
} from '@vue/compiler-core'
|
||||
import { createDOMCompilerError, DOMErrorCodes } from '../errors'
|
||||
import {
|
||||
|
@ -32,8 +34,8 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
|
|||
}
|
||||
|
||||
function checkDuplicatedValue() {
|
||||
const value = findProp(node, 'value')
|
||||
if (value) {
|
||||
const value = findDir(node, 'bind')
|
||||
if (value && isStaticArgOf(value.arg, 'value')) {
|
||||
context.onError(
|
||||
createDOMCompilerError(
|
||||
DOMErrorCodes.X_V_MODEL_UNNECESSARY_VALUE,
|
||||
|
|
Loading…
Reference in New Issue