wip: fix compat utils usage

This commit is contained in:
Evan You 2021-04-09 23:21:13 -04:00
parent 183f9b0013
commit 7a25cbb7a7
8 changed files with 32 additions and 13 deletions

View File

@ -226,7 +226,7 @@ function doWatch(
const val = baseGetter() const val = baseGetter()
if ( if (
isArray(val) && isArray(val) &&
softAssertCompatEnabled(DeprecationTypes.WATCH_ARRAY) softAssertCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance)
) { ) {
traverse(val) traverse(val)
} }
@ -277,7 +277,7 @@ function doWatch(
hasChanged(newValue, oldValue) || hasChanged(newValue, oldValue) ||
(__COMPAT__ && (__COMPAT__ &&
isArray(newValue) && isArray(newValue) &&
isCompatEnabled(DeprecationTypes.WATCH_ARRAY)) isCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance))
) { ) {
// cleanup before running cb again // cleanup before running cb again
if (cleanup) { if (cleanup) {

View File

@ -1,4 +1,4 @@
import { hasOwn, isArray } from '@vue/shared/src' import { hasOwn, isArray } from '@vue/shared'
import { import {
ComponentInternalInstance, ComponentInternalInstance,
ComponentOptions, ComponentOptions,

View File

@ -443,7 +443,7 @@ function baseCreateRenderer(
createHydrationFns?: typeof createHydrationFunctions createHydrationFns?: typeof createHydrationFunctions
): any { ): any {
const isHookEventCompatEnabled = const isHookEventCompatEnabled =
__COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS) __COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, null)
// compile-time feature flags check // compile-time feature flags check
if (__ESM_BUNDLER__ && !__TEST__) { if (__ESM_BUNDLER__ && !__TEST__) {

View File

@ -103,7 +103,7 @@ export function resolveTransitionProps(
// legacy transition class compat // legacy transition class compat
const legacyClassEnabled = const legacyClassEnabled =
__COMPAT__ && __COMPAT__ &&
compatUtils.isCompatEnabled(DeprecationTypes.TRANSITION_CLASSES) compatUtils.isCompatEnabled(DeprecationTypes.TRANSITION_CLASSES, null)
let legacyEnterFromClass: string let legacyEnterFromClass: string
let legacyAppearFromClass: string let legacyAppearFromClass: string
let legacyLeaveFromClass: string let legacyLeaveFromClass: string

View File

@ -107,7 +107,8 @@ const TransitionGroupImpl = {
__COMPAT__ && __COMPAT__ &&
!rawProps.tag && !rawProps.tag &&
compatUtils.softAssertCompatEnabled( compatUtils.softAssertCompatEnabled(
DeprecationTypes.TRANSITION_GROUP_ROOT DeprecationTypes.TRANSITION_GROUP_ROOT,
instance.parent
) )
) { ) {
tag = 'span' tag = 'span'

View File

@ -2,7 +2,8 @@ import {
getCurrentInstance, getCurrentInstance,
DeprecationTypes, DeprecationTypes,
LegacyConfig, LegacyConfig,
compatUtils compatUtils,
ComponentInternalInstance
} from '@vue/runtime-core' } from '@vue/runtime-core'
import { hyphenate, isArray } from '@vue/shared' import { hyphenate, isArray } from '@vue/shared'
@ -58,16 +59,22 @@ const keyNames: Record<string, string | string[]> = {
*/ */
export const withKeys = (fn: Function, modifiers: string[]) => { export const withKeys = (fn: Function, modifiers: string[]) => {
let globalKeyCodes: LegacyConfig['keyCodes'] let globalKeyCodes: LegacyConfig['keyCodes']
let instance: ComponentInternalInstance | null = null
if (__COMPAT__) { if (__COMPAT__) {
if (compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES)) { instance = getCurrentInstance()
const instance = getCurrentInstance() if (
compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES, instance)
) {
if (instance) { if (instance) {
globalKeyCodes = ((instance.appContext.config as any) as LegacyConfig) globalKeyCodes = ((instance.appContext.config as any) as LegacyConfig)
.keyCodes .keyCodes
} }
} }
if (__DEV__ && modifiers.some(m => /^\d+$/.test(m))) { if (__DEV__ && modifiers.some(m => /^\d+$/.test(m))) {
compatUtils.warnDeprecation(DeprecationTypes.V_ON_KEYCODE_MODIFIER) compatUtils.warnDeprecation(
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
instance
)
} }
} }
@ -84,7 +91,10 @@ export const withKeys = (fn: Function, modifiers: string[]) => {
if (__COMPAT__) { if (__COMPAT__) {
const keyCode = String(event.keyCode) const keyCode = String(event.keyCode)
if ( if (
compatUtils.isCompatEnabled(DeprecationTypes.V_ON_KEYCODE_MODIFIER) && compatUtils.isCompatEnabled(
DeprecationTypes.V_ON_KEYCODE_MODIFIER,
instance
) &&
modifiers.some(mod => mod == keyCode) modifiers.some(mod => mod == keyCode)
) { ) {
return fn(event) return fn(event)

View File

@ -78,7 +78,10 @@ export const createApp = ((...args) => {
for (let i = 0; i < container.attributes.length; i++) { for (let i = 0; i < container.attributes.length; i++) {
const attr = container.attributes[i] const attr = container.attributes[i]
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) { if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
compatUtils.warnDeprecation(DeprecationTypes.GLOBAL_MOUNT_CONTAINER) compatUtils.warnDeprecation(
DeprecationTypes.GLOBAL_MOUNT_CONTAINER,
null
)
break break
} }
} }

View File

@ -54,6 +54,7 @@ export function compatCoerceAttr(
v2CocercedValue && v2CocercedValue &&
compatUtils.softAssertCompatEnabled( compatUtils.softAssertCompatEnabled(
DeprecationTypes.ATTR_ENUMERATED_COERSION, DeprecationTypes.ATTR_ENUMERATED_COERSION,
null,
key, key,
value, value,
v2CocercedValue v2CocercedValue
@ -65,7 +66,11 @@ export function compatCoerceAttr(
} else if ( } else if (
value === false && value === false &&
!isSpecialBooleanAttr(key) && !isSpecialBooleanAttr(key) &&
compatUtils.softAssertCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, key) compatUtils.softAssertCompatEnabled(
DeprecationTypes.ATTR_FALSE_VALUE,
null,
key
)
) { ) {
el.removeAttribute(key) el.removeAttribute(key)
return true return true