@@ -36,6 +36,14 @@ const ATTRS = {
3636function isVBind ( node ) {
3737 return Boolean ( node && node . directive && node . key . name . name === 'bind' )
3838}
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+ }
3947/**
4048 * Check whether the given attribute is plain attribute.
4149 * @param {VAttribute | VDirective | undefined | null } node
@@ -45,12 +53,12 @@ function isVAttribute(node) {
4553 return Boolean ( node && ! node . directive )
4654}
4755/**
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.
4957 * @param {VAttribute | VDirective | undefined | null } node
5058 * @returns { node is VAttribute }
5159 */
52- function isVAttributeOrVBind ( node ) {
53- return isVAttribute ( node ) || isVBind ( node )
60+ function isVAttributeOrVBindOrVModel ( node ) {
61+ return isVAttribute ( node ) || isVBind ( node ) || isVModel ( node )
5462}
5563
5664/**
@@ -235,8 +243,8 @@ function create(context) {
235243
236244 if ( isVBindObject ( node ) ) {
237245 // 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 ) ) {
240248 // prev, v-bind, v-bind:foo -> v-bind, v-bind:foo, prev
241249 isMoveUp = isVBindObject
242250 } else {
@@ -298,11 +306,13 @@ function create(context) {
298306 const attributes = node . attributes . filter ( ( node , index , attributes ) => {
299307 if (
300308 isVBindObject ( node ) &&
301- ( isVAttributeOrVBind ( attributes [ index - 1 ] ) ||
302- isVAttributeOrVBind ( attributes [ index + 1 ] ) )
309+ ( isVAttributeOrVBindOrVModel ( attributes [ index - 1 ] ) ||
310+ isVAttributeOrVBindOrVModel ( attributes [ index + 1 ] ) )
303311 ) {
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.
306316 return false
307317 }
308318 return true
@@ -330,14 +340,14 @@ function create(context) {
330340 if ( isVBindObject ( node ) ) {
331341 // node is `v-bind ="object"` syntax
332342
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"`,
334344 // the behavior will be different, so adjust so that there is no change in behavior.
335345
336346 const len = attributes . length
337347 for ( let nextIndex = index + 1 ; nextIndex < len ; nextIndex ++ ) {
338348 const next = attributes [ nextIndex ]
339349
340- if ( isVAttributeOrVBind ( next ) && ! isVBindObject ( next ) ) {
350+ if ( isVAttributeOrVBindOrVModel ( next ) && ! isVBindObject ( next ) ) {
341351 // It is considered to be in the same order as the next bind prop node.
342352 return getPositionFromAttrIndex ( nextIndex )
343353 }
0 commit comments