| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { extend } from '@vue/shared'
- import { DeprecationTypes, warnDeprecation } from './deprecations'
- export type CompatConfig = Partial<
- Record<DeprecationTypes, DeprecationConfigItem>
- >
- export interface DeprecationConfigItem {
- warning?: boolean // default: true
- enabled?: boolean // default: true
- }
- const globalCompatConfig: CompatConfig = {}
- export function configureCompat(config: CompatConfig) {
- extend(globalCompatConfig, config)
- }
- export function getCompatConfig(
- key: DeprecationTypes
- ): DeprecationConfigItem | undefined {
- return globalCompatConfig[key]
- }
- export function isCompatEnabled(key: DeprecationTypes): boolean {
- const config = getCompatConfig(key)
- 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)
- }
- // 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 }
- })
- }
|