wip: refactor

This commit is contained in:
Evan You 2021-04-17 22:50:16 -04:00
parent 505269405e
commit 1390ece04f
3 changed files with 24 additions and 33 deletions

View File

@ -748,20 +748,27 @@ function parseAttribute(
const modifiers = match[3] ? match[3].substr(1).split('.') : [] const modifiers = match[3] ? match[3].substr(1).split('.') : []
// 2.x compat v-bind:foo.sync -> v-model:foo // 2.x compat v-bind:foo.sync -> v-model:foo
if ( if (__COMPAT__ && dirName === 'bind' && arg) {
__COMPAT__ && if (
dirName === 'bind' && modifiers.includes('sync') &&
arg && checkCompatEnabled(
modifiers.includes('sync') && CompilerDeprecationTypes.COMPILER_V_BIND_SYNC,
checkCompatEnabled( context,
CompilerDeprecationTypes.COMPILER_V_BIND_SYNC, loc,
context, arg.loc.source
loc, )
arg.loc.source ) {
) dirName = 'model'
) { modifiers.splice(modifiers.indexOf('sync'), 1)
dirName = 'model' }
modifiers.splice(modifiers.indexOf('sync'), 1)
if (__DEV__ && modifiers.includes('prop')) {
checkCompatEnabled(
CompilerDeprecationTypes.COMPILER_V_BIND_PROP,
context,
loc
)
}
} }
return { return {

View File

@ -92,6 +92,7 @@ export const transformElement: NodeTransform = (node, context) => {
? resolveComponentType(node as ComponentNode, context) ? resolveComponentType(node as ComponentNode, context)
: `"${tag}"` : `"${tag}"`
// 2.x <template> with no directives compat
if ( if (
__COMPAT__ && __COMPAT__ &&
tag === 'template' && tag === 'template' &&
@ -261,9 +262,7 @@ export function resolveComponentType(
// if not <component>, only is value that starts with "vue:" will be // if not <component>, only is value that starts with "vue:" will be
// treated as component by the parse phase and reach here, unless it's // treated as component by the parse phase and reach here, unless it's
// compat mode where all is values are considered components // compat mode where all is values are considered components
tag = __COMPAT__ tag = isProp.value!.content.replace(/^vue:/, '')
? isProp.value!.content.replace(/^vue:/, '')
: isProp.value!.content.slice(4)
} else { } else {
const exp = const exp =
isProp.type === NodeTypes.ATTRIBUTE isProp.type === NodeTypes.ATTRIBUTE
@ -509,6 +508,7 @@ export function buildProps(
} }
if (isVBind) { if (isVBind) {
if (__COMPAT__) { if (__COMPAT__) {
// 2.x v-bind object order compat
if (__DEV__) { if (__DEV__) {
const hasOverridableKeys = mergeArgs.some(arg => { const hasOverridableKeys = mergeArgs.some(arg => {
if (arg.type === NodeTypes.JS_OBJECT_EXPRESSION) { if (arg.type === NodeTypes.JS_OBJECT_EXPRESSION) {

View File

@ -3,10 +3,6 @@ import { createObjectProperty, createSimpleExpression, NodeTypes } from '../ast'
import { createCompilerError, ErrorCodes } from '../errors' import { createCompilerError, ErrorCodes } from '../errors'
import { camelize } from '@vue/shared' import { camelize } from '@vue/shared'
import { CAMELIZE } from '../runtimeHelpers' import { CAMELIZE } from '../runtimeHelpers'
import {
checkCompatEnabled,
CompilerDeprecationTypes
} from '../compat/compatConfig'
// v-bind without arg is handled directly in ./transformElements.ts due to it affecting // v-bind without arg is handled directly in ./transformElements.ts due to it affecting
// codegen for the entire props object. This transform here is only for v-bind // codegen for the entire props object. This transform here is only for v-bind
@ -37,18 +33,6 @@ export const transformBind: DirectiveTransform = (dir, _node, context) => {
} }
} }
if (__COMPAT__) {
if (modifiers.includes('prop')) {
checkCompatEnabled(
CompilerDeprecationTypes.COMPILER_V_BIND_PROP,
context,
loc
)
}
// .sync handling is performed directly in the parse phase to transform
// it into v-model:arg equivalent.
}
if ( if (
!exp || !exp ||
(exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim()) (exp.type === NodeTypes.SIMPLE_EXPRESSION && !exp.content.trim())