From 7a25cbb7a78f41243f986b81d650c5c99ee1cf27 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 9 Apr 2021 23:21:13 -0400 Subject: [PATCH] wip: fix compat utils usage --- packages/runtime-core/src/apiWatch.ts | 4 ++-- .../runtime-core/src/compat/deprecations.ts | 2 +- packages/runtime-core/src/renderer.ts | 2 +- .../runtime-dom/src/components/Transition.ts | 2 +- .../src/components/TransitionGroup.ts | 3 ++- packages/runtime-dom/src/directives/vOn.ts | 20 ++++++++++++++----- packages/runtime-dom/src/index.ts | 5 ++++- packages/runtime-dom/src/modules/attrs.ts | 7 ++++++- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index d33adb3e..b739ef26 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -226,7 +226,7 @@ function doWatch( const val = baseGetter() if ( isArray(val) && - softAssertCompatEnabled(DeprecationTypes.WATCH_ARRAY) + softAssertCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance) ) { traverse(val) } @@ -277,7 +277,7 @@ function doWatch( hasChanged(newValue, oldValue) || (__COMPAT__ && isArray(newValue) && - isCompatEnabled(DeprecationTypes.WATCH_ARRAY)) + isCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance)) ) { // cleanup before running cb again if (cleanup) { diff --git a/packages/runtime-core/src/compat/deprecations.ts b/packages/runtime-core/src/compat/deprecations.ts index 8a00ab0e..e91ea920 100644 --- a/packages/runtime-core/src/compat/deprecations.ts +++ b/packages/runtime-core/src/compat/deprecations.ts @@ -1,4 +1,4 @@ -import { hasOwn, isArray } from '@vue/shared/src' +import { hasOwn, isArray } from '@vue/shared' import { ComponentInternalInstance, ComponentOptions, diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index a6ad23d0..38302589 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -443,7 +443,7 @@ function baseCreateRenderer( createHydrationFns?: typeof createHydrationFunctions ): any { const isHookEventCompatEnabled = - __COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS) + __COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS, null) // compile-time feature flags check if (__ESM_BUNDLER__ && !__TEST__) { diff --git a/packages/runtime-dom/src/components/Transition.ts b/packages/runtime-dom/src/components/Transition.ts index 0d5681cb..1121af1e 100644 --- a/packages/runtime-dom/src/components/Transition.ts +++ b/packages/runtime-dom/src/components/Transition.ts @@ -103,7 +103,7 @@ export function resolveTransitionProps( // legacy transition class compat const legacyClassEnabled = __COMPAT__ && - compatUtils.isCompatEnabled(DeprecationTypes.TRANSITION_CLASSES) + compatUtils.isCompatEnabled(DeprecationTypes.TRANSITION_CLASSES, null) let legacyEnterFromClass: string let legacyAppearFromClass: string let legacyLeaveFromClass: string diff --git a/packages/runtime-dom/src/components/TransitionGroup.ts b/packages/runtime-dom/src/components/TransitionGroup.ts index 02fa38f1..50c526ba 100644 --- a/packages/runtime-dom/src/components/TransitionGroup.ts +++ b/packages/runtime-dom/src/components/TransitionGroup.ts @@ -107,7 +107,8 @@ const TransitionGroupImpl = { __COMPAT__ && !rawProps.tag && compatUtils.softAssertCompatEnabled( - DeprecationTypes.TRANSITION_GROUP_ROOT + DeprecationTypes.TRANSITION_GROUP_ROOT, + instance.parent ) ) { tag = 'span' diff --git a/packages/runtime-dom/src/directives/vOn.ts b/packages/runtime-dom/src/directives/vOn.ts index 4de92f15..45fc58ad 100644 --- a/packages/runtime-dom/src/directives/vOn.ts +++ b/packages/runtime-dom/src/directives/vOn.ts @@ -2,7 +2,8 @@ import { getCurrentInstance, DeprecationTypes, LegacyConfig, - compatUtils + compatUtils, + ComponentInternalInstance } from '@vue/runtime-core' import { hyphenate, isArray } from '@vue/shared' @@ -58,16 +59,22 @@ const keyNames: Record = { */ export const withKeys = (fn: Function, modifiers: string[]) => { let globalKeyCodes: LegacyConfig['keyCodes'] + let instance: ComponentInternalInstance | null = null if (__COMPAT__) { - if (compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES)) { - const instance = getCurrentInstance() + instance = getCurrentInstance() + if ( + compatUtils.isCompatEnabled(DeprecationTypes.CONFIG_KEY_CODES, instance) + ) { if (instance) { globalKeyCodes = ((instance.appContext.config as any) as LegacyConfig) .keyCodes } } 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__) { const keyCode = String(event.keyCode) if ( - compatUtils.isCompatEnabled(DeprecationTypes.V_ON_KEYCODE_MODIFIER) && + compatUtils.isCompatEnabled( + DeprecationTypes.V_ON_KEYCODE_MODIFIER, + instance + ) && modifiers.some(mod => mod == keyCode) ) { return fn(event) diff --git a/packages/runtime-dom/src/index.ts b/packages/runtime-dom/src/index.ts index 767b7007..780152aa 100644 --- a/packages/runtime-dom/src/index.ts +++ b/packages/runtime-dom/src/index.ts @@ -78,7 +78,10 @@ export const createApp = ((...args) => { for (let i = 0; i < container.attributes.length; i++) { const attr = container.attributes[i] if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) { - compatUtils.warnDeprecation(DeprecationTypes.GLOBAL_MOUNT_CONTAINER) + compatUtils.warnDeprecation( + DeprecationTypes.GLOBAL_MOUNT_CONTAINER, + null + ) break } } diff --git a/packages/runtime-dom/src/modules/attrs.ts b/packages/runtime-dom/src/modules/attrs.ts index 975f6cbe..fc3ead52 100644 --- a/packages/runtime-dom/src/modules/attrs.ts +++ b/packages/runtime-dom/src/modules/attrs.ts @@ -54,6 +54,7 @@ export function compatCoerceAttr( v2CocercedValue && compatUtils.softAssertCompatEnabled( DeprecationTypes.ATTR_ENUMERATED_COERSION, + null, key, value, v2CocercedValue @@ -65,7 +66,11 @@ export function compatCoerceAttr( } else if ( value === false && !isSpecialBooleanAttr(key) && - compatUtils.softAssertCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, key) + compatUtils.softAssertCompatEnabled( + DeprecationTypes.ATTR_FALSE_VALUE, + null, + key + ) ) { el.removeAttribute(key) return true