import { queuePostRenderEffect } from './renderer'
import { warn } from './warning'
import { DeprecationTypes } from './compat/deprecations'
-import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
+import { checkCompatEnabled, isCompatEnabled } from './compat/compatConfig'
export type WatchEffect = (onInvalidate: InvalidateCbRegistrator) => void
const val = baseGetter()
if (
isArray(val) &&
- softAssertCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance)
+ checkCompatEnabled(DeprecationTypes.WATCH_ARRAY, instance)
) {
traverse(val)
}
import Vue from '@vue/compat'
describe('compat: global API', () => {
- test('should work', async () => {
+ beforeEach(() => Vue.configureCompat({ MODE: 2 }))
+ afterEach(() => Vue.configureCompat({ MODE: 3 }))
+
+ test('should work', () => {
const el = document.createElement('div')
el.innerHTML = `{{ msg }}`
new Vue({
}
}
+/**
+ * Use this for features that are completely removed in non-compat build.
+ */
export function assertCompatEnabled(
key: DeprecationTypes,
instance: ComponentInternalInstance | null,
}
}
+/**
+ * Use this for features where legacy usage is still possible, but will likely
+ * lead to runtime error if compat is disabled. (warn in all cases)
+ */
export function softAssertCompatEnabled(
key: DeprecationTypes,
instance: ComponentInternalInstance | null,
return isCompatEnabled(key, instance)
}
-// disable features that conflict with v3 behavior
+/**
+ * Use this for features with the same syntax but with mutually exclusive
+ * behavior in 2 vs 3. Only warn if compat is enabled.
+ * e.g. render function
+ */
+export function checkCompatEnabled(
+ key: DeprecationTypes,
+ instance: ComponentInternalInstance | null,
+ ...args: any[]
+) {
+ const enabled = isCompatEnabled(key, instance)
+ if (__DEV__ && enabled) {
+ warnDeprecation(key, instance, ...args)
+ }
+ return enabled
+}
+
+// run tests in v3 mode by default
if (__TEST__) {
configureCompat({
- COMPONENT_ASYNC: false,
- COMPONENT_FUNCTIONAL: false,
- WATCH_ARRAY: false,
- INSTANCE_ATTRS_CLASS_STYLE: false
+ MODE: 3
})
}
import { resolveInjections } from '../componentOptions'
import { InternalSlots } from '../componentSlots'
import { isVNode } from '../vnode'
-import { isCompatEnabled, softAssertCompatEnabled } from './compatConfig'
-import { DeprecationTypes, warnDeprecation } from './deprecations'
+import { checkCompatEnabled, softAssertCompatEnabled } from './compatConfig'
+import { DeprecationTypes } from './deprecations'
import { getCompatListeners } from './instanceListeners'
import { compatH } from './renderFn'
// use softAssert here.
if (
isFunction(comp) &&
- isCompatEnabled(DeprecationTypes.COMPONENT_ASYNC, instance)
+ checkCompatEnabled(DeprecationTypes.COMPONENT_ASYNC, instance, comp)
) {
- __DEV__ && warnDeprecation(DeprecationTypes.COMPONENT_ASYNC, instance, comp)
return convertLegacyAsyncComponent(comp)
}
import { extend, NOOP } from '@vue/shared'
import { PublicPropertiesMap } from '../componentPublicInstance'
import { getCompatChildren } from './instanceChildren'
-import { assertCompatEnabled, isCompatEnabled } from './compatConfig'
-import { DeprecationTypes, warnDeprecation } from './deprecations'
+import {
+ assertCompatEnabled,
+ checkCompatEnabled,
+ isCompatEnabled
+} from './compatConfig'
+import { DeprecationTypes } from './deprecations'
import { off, on, once } from './instanceEventEmitter'
import { getCompatListeners } from './instanceListeners'
import { shallowReadonly } from '@vue/reactivity'
if (isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, i)) {
return new Proxy(i.slots, legacySlotProxyHandlers)
}
- return i.slots
+ return __DEV__ ? shallowReadonly(i.slots) : i.slots
},
$scopedSlots: i => {
// overrides existing accessor
$attrs: i => {
if (__DEV__ && i.type.inheritAttrs === false) {
- warnDeprecation(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, i)
+ checkCompatEnabled(DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE, i)
}
return __DEV__ ? shallowReadonly(i.attrs) : i.attrs
},
import { markAttrsAccessed } from './componentRenderUtils'
import { currentRenderingInstance } from './componentRenderContext'
import { startMeasure, endMeasure } from './profiling'
-import { isCompatEnabled } from './compat/compatConfig'
-import { DeprecationTypes, warnDeprecation } from './compat/deprecations'
+import { checkCompatEnabled } from './compat/compatConfig'
+import { DeprecationTypes } from './compat/deprecations'
import { compatH } from './compat/renderFn'
export type Data = Record<string, unknown>
if (
__COMPAT__ &&
Component.render &&
- isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, instance)
+ checkCompatEnabled(DeprecationTypes.RENDER_FUNCTION, instance)
) {
- warnDeprecation(DeprecationTypes.RENDER_FUNCTION, instance)
const originalRender = Component.render
Component.render = function compatRender() {
return originalRender.call(this, compatH)
import { warnDeprecation } from './compat/deprecations'
import { createCompatVue } from './compat/global'
-import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
+import {
+ isCompatEnabled,
+ checkCompatEnabled,
+ softAssertCompatEnabled
+} from './compat/compatConfig'
const _compatUtils = {
warnDeprecation,
createCompatVue,
isCompatEnabled,
+ checkCompatEnabled,
softAssertCompatEnabled
}
if (
__COMPAT__ &&
!rawProps.tag &&
- compatUtils.softAssertCompatEnabled(
+ compatUtils.checkCompatEnabled(
DeprecationTypes.TRANSITION_GROUP_ROOT,
instance.parent
)