Skip to content

Commit 7ceb873

Browse files
committed
wip: v-bind.sync compat
1 parent ad97bba commit 7ceb873

File tree

4 files changed

+48
-7
lines changed

4 files changed

+48
-7
lines changed

packages/compiler-core/src/compat/compatConfig.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export interface CompilerCompatOptions {
1616
export const enum CompilerDeprecationTypes {
1717
COMPILER_IS_ON_ELEMENT = 'COMPILER_IS_ON_ELEMENT',
1818
COMPILER_V_BIND_SYNC = 'COMPILER_V_BIND_SYNC',
19+
COMPILER_V_BIND_PROP = 'COMPILER_V_BIND_PROP',
1920
COMPILER_V_BIND_OBJECT_ORDER = 'COMPILER_V_BIND_OBJECT_ORDER',
20-
COMPILER_V_ON_NATIVE_MODIFIER = 'COMPILER_V_ON_NATIVE_MODIFIER',
21+
COMPILER_V_ON_NATIVE = 'COMPILER_V_ON_NATIVE',
2122
COMPILER_KEY_V_IF = 'COMPILER_KEY_V_IF',
2223
COMPILER_KEY_V_FOR_TEMPLATE = 'COMPILER_KEY_V_FOR_TEMPLATE',
2324
COMPILER_V_IF_V_FOR_PRECEDENCE = 'COMPILER_V_IF_V_FOR_PRECEDENCE',
@@ -46,6 +47,12 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
4647
link: `https://v3.vuejs.org/guide/migration/v-model.html`
4748
},
4849

50+
[CompilerDeprecationTypes.COMPILER_V_BIND_PROP]: {
51+
message:
52+
`.prop modifier for v-bind has been removed and no longer necessary. ` +
53+
`Vue 3 will automatically set a binding as DOM property when appropriate.`
54+
},
55+
4956
[CompilerDeprecationTypes.COMPILER_V_BIND_OBJECT_ORDER]: {
5057
message:
5158
`v-bind="obj" usage is now order sensitive and behaves like JavaScript ` +
@@ -56,7 +63,7 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
5663
link: `https://v3.vuejs.org/guide/migration/v-bind.html`
5764
},
5865

59-
[CompilerDeprecationTypes.COMPILER_V_ON_NATIVE_MODIFIER]: {
66+
[CompilerDeprecationTypes.COMPILER_V_ON_NATIVE]: {
6067
message: `.native modifier for v-on has been removed as is no longer necessary.`,
6168
link: `https://v3.vuejs.org/guide/migration/v-on-native-modifier-removed.html`
6269
},

packages/compiler-core/src/parse.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,9 @@ function parseAttribute(
650650
name
651651
)!
652652

653-
const dirName =
653+
let dirName =
654654
match[1] ||
655655
(startsWith(name, ':') ? 'bind' : startsWith(name, '@') ? 'on' : 'slot')
656-
657656
let arg: ExpressionNode | undefined
658657

659658
if (match[2]) {
@@ -708,6 +707,25 @@ function parseAttribute(
708707
valueLoc.source = valueLoc.source.slice(1, -1)
709708
}
710709

710+
const modifiers = match[3] ? match[3].substr(1).split('.') : []
711+
712+
// 2.x compat v-bind:foo.sync -> v-model:foo
713+
if (
714+
__COMPAT__ &&
715+
dirName === 'bind' &&
716+
arg &&
717+
modifiers.includes('sync') &&
718+
checkCompatEnabled(
719+
CompilerDeprecationTypes.COMPILER_V_BIND_SYNC,
720+
context,
721+
loc,
722+
arg.loc.source
723+
)
724+
) {
725+
dirName = 'model'
726+
modifiers.splice(modifiers.indexOf('sync'), 1)
727+
}
728+
711729
return {
712730
type: NodeTypes.DIRECTIVE,
713731
name: dirName,
@@ -721,7 +739,7 @@ function parseAttribute(
721739
loc: value.loc
722740
},
723741
arg,
724-
modifiers: match[3] ? match[3].substr(1).split('.') : [],
742+
modifiers,
725743
loc
726744
}
727745
}

packages/compiler-core/src/transforms/vBind.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { createObjectProperty, createSimpleExpression, NodeTypes } from '../ast'
33
import { createCompilerError, ErrorCodes } from '../errors'
44
import { camelize } from '@vue/shared'
55
import { CAMELIZE } from '../runtimeHelpers'
6+
import {
7+
checkCompatEnabled,
8+
CompilerDeprecationTypes
9+
} from '../compat/compatConfig'
610

711
// v-bind without arg is handled directly in ./transformElements.ts due to it affecting
812
// codegen for the entire props object. This transform here is only for v-bind
913
// *with* args.
10-
export const transformBind: DirectiveTransform = (dir, node, context) => {
14+
export const transformBind: DirectiveTransform = (dir, _node, context) => {
1115
const { exp, modifiers, loc } = dir
1216
const arg = dir.arg!
1317

@@ -33,6 +37,18 @@ export const transformBind: DirectiveTransform = (dir, node, context) => {
3337
}
3438
}
3539

40+
if (__COMPAT__) {
41+
if (modifiers.includes('prop')) {
42+
checkCompatEnabled(
43+
CompilerDeprecationTypes.COMPILER_V_BIND_PROP,
44+
context,
45+
loc
46+
)
47+
}
48+
// .sync handling is performed directly in the parse phase to transform
49+
// it into v-model:arg equivalent.
50+
}
51+
3652
if (
3753
!exp ||
3854
(exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())

packages/compiler-dom/src/transforms/vOn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
9696

9797
if (__COMPAT__ && __DEV__ && modifiers.includes('native')) {
9898
warnDeprecation(
99-
CompilerDeprecationTypes.COMPILER_V_ON_NATIVE_MODIFIER,
99+
CompilerDeprecationTypes.COMPILER_V_ON_NATIVE,
100100
context,
101101
dir.loc
102102
)

0 commit comments

Comments
 (0)