@@ -36,6 +36,14 @@ const ATTRS = {
36
36
function isVBind ( node ) {
37
37
return Boolean ( node && node . directive && node . key . name . name === 'bind' )
38
38
}
39
+ /**
40
+ * Check whether the given attribute is `v-model` directive.
41
+ * @param {VAttribute | VDirective | undefined | null } node
42
+ * @returns { node is VDirective }
43
+ */
44
+ function isVModel ( node ) {
45
+ return Boolean ( node && node . directive && node . key . name . name === 'model' )
46
+ }
39
47
/**
40
48
* Check whether the given attribute is plain attribute.
41
49
* @param {VAttribute | VDirective | undefined | null } node
@@ -45,12 +53,12 @@ function isVAttribute(node) {
45
53
return Boolean ( node && ! node . directive )
46
54
}
47
55
/**
48
- * Check whether the given attribute is plain attribute or `v-bind ` directive.
56
+ * Check whether the given attribute is plain attribute, `v-bind` directive or `v-model ` directive.
49
57
* @param {VAttribute | VDirective | undefined | null } node
50
58
* @returns { node is VAttribute }
51
59
*/
52
- function isVAttributeOrVBind ( node ) {
53
- return isVAttribute ( node ) || isVBind ( node )
60
+ function isVAttributeOrVBindOrVModel ( node ) {
61
+ return isVAttribute ( node ) || isVBind ( node ) || isVModel ( node )
54
62
}
55
63
56
64
/**
@@ -235,8 +243,8 @@ function create(context) {
235
243
236
244
if ( isVBindObject ( node ) ) {
237
245
// prev, v-bind:foo, v-bind -> v-bind:foo, v-bind, prev
238
- isMoveUp = isVAttributeOrVBind
239
- } else if ( isVAttributeOrVBind ( node ) ) {
246
+ isMoveUp = isVAttributeOrVBindOrVModel
247
+ } else if ( isVAttributeOrVBindOrVModel ( node ) ) {
240
248
// prev, v-bind, v-bind:foo -> v-bind, v-bind:foo, prev
241
249
isMoveUp = isVBindObject
242
250
} else {
@@ -298,11 +306,13 @@ function create(context) {
298
306
const attributes = node . attributes . filter ( ( node , index , attributes ) => {
299
307
if (
300
308
isVBindObject ( node ) &&
301
- ( isVAttributeOrVBind ( attributes [ index - 1 ] ) ||
302
- isVAttributeOrVBind ( attributes [ index + 1 ] ) )
309
+ ( isVAttributeOrVBindOrVModel ( attributes [ index - 1 ] ) ||
310
+ isVAttributeOrVBindOrVModel ( attributes [ index + 1 ] ) )
303
311
) {
304
- // In Vue 3, ignore the `v-bind:foo=" ... "` and `v-bind ="object"` syntax
305
- // as they behave differently if you change the order.
312
+ // In Vue 3, ignore `v-bind="object"`, which is
313
+ // a pair of `v-bind:foo="..."` and `v-bind="object"` and
314
+ // a pair of `v-model="..."` and `v-bind="object"`,
315
+ // because changing the order behaves differently.
306
316
return false
307
317
}
308
318
return true
@@ -330,14 +340,14 @@ function create(context) {
330
340
if ( isVBindObject ( node ) ) {
331
341
// node is `v-bind ="object"` syntax
332
342
333
- // In Vue 3, if change the order of `v-bind:foo=" ... " ` and `v-bind ="object"`,
343
+ // In Vue 3, if change the order of `v-bind:foo="..."`, `v-model="..." ` and `v-bind="object"`,
334
344
// the behavior will be different, so adjust so that there is no change in behavior.
335
345
336
346
const len = attributes . length
337
347
for ( let nextIndex = index + 1 ; nextIndex < len ; nextIndex ++ ) {
338
348
const next = attributes [ nextIndex ]
339
349
340
- if ( isVAttributeOrVBind ( next ) && ! isVBindObject ( next ) ) {
350
+ if ( isVAttributeOrVBindOrVModel ( next ) && ! isVBindObject ( next ) ) {
341
351
// It is considered to be in the same order as the next bind prop node.
342
352
return getPositionFromAttrIndex ( nextIndex )
343
353
}
0 commit comments