2021-04-07 23:22:56 +08:00
|
|
|
import { extend } from '@vue/shared'
|
2021-04-08 03:38:04 +08:00
|
|
|
import { DeprecationTypes, warnDeprecation } from './deprecations'
|
2021-04-07 23:22:56 +08:00
|
|
|
|
|
|
|
export type CompatConfig = Partial<
|
|
|
|
Record<DeprecationTypes, DeprecationConfigItem>
|
|
|
|
>
|
|
|
|
|
|
|
|
export interface DeprecationConfigItem {
|
2021-04-08 03:38:04 +08:00
|
|
|
warning?: boolean // default: true
|
|
|
|
enabled?: boolean // default: true
|
2021-04-07 23:22:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const globalCompatConfig: CompatConfig = {}
|
|
|
|
|
|
|
|
export function configureCompat(config: CompatConfig) {
|
|
|
|
extend(globalCompatConfig, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCompatConfig(
|
|
|
|
key: DeprecationTypes
|
|
|
|
): DeprecationConfigItem | undefined {
|
|
|
|
return globalCompatConfig[key]
|
|
|
|
}
|
2021-04-08 00:24:45 +08:00
|
|
|
|
|
|
|
export function isCompatEnabled(key: DeprecationTypes): boolean {
|
|
|
|
const config = getCompatConfig(key)
|
2021-04-08 03:38:04 +08:00
|
|
|
return !config || config.enabled !== false
|
|
|
|
}
|
|
|
|
|
|
|
|
export function assertCompatEnabled(key: DeprecationTypes, ...args: any[]) {
|
|
|
|
if (!isCompatEnabled(key)) {
|
|
|
|
throw new Error(`${key} compat has been disabled.`)
|
|
|
|
} else if (__DEV__) {
|
|
|
|
warnDeprecation(key, ...args)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function softAssertCompatEnabled(key: DeprecationTypes, ...args: any[]) {
|
|
|
|
if (__DEV__) {
|
|
|
|
warnDeprecation(key, ...args)
|
|
|
|
}
|
|
|
|
return isCompatEnabled(key)
|
2021-04-08 00:24:45 +08:00
|
|
|
}
|
2021-04-09 04:33:53 +08:00
|
|
|
|
|
|
|
// disable features that conflict with v3 behavior
|
|
|
|
if (__TEST__) {
|
|
|
|
configureCompat({
|
|
|
|
COMPONENT_ASYNC: { enabled: false },
|
|
|
|
COMPONENT_FUNCTIONAL: { enabled: false },
|
|
|
|
WATCH_ARRAY: { enabled: false },
|
|
|
|
INSTANCE_ATTRS_CLASS_STYLE: { enabled: false }
|
|
|
|
})
|
|
|
|
}
|