import { extend } from '@vue/shared'
+import { ComponentOptions, getCurrentInstance } from '../component'
import { DeprecationTypes, warnDeprecation } from './deprecations'
export type CompatConfig = Partial<
- Record<DeprecationTypes, DeprecationConfigItem>
->
-
-export interface DeprecationConfigItem {
- warning?: boolean // default: true
- enabled?: boolean // default: true
+ Record<DeprecationTypes, boolean | 'suppress-warning'>
+> & {
+ MODE?: 2 | 3
}
const globalCompatConfig: CompatConfig = {}
extend(globalCompatConfig, config)
}
-export function getCompatConfig(
- key: DeprecationTypes
-): DeprecationConfigItem | undefined {
+export function getCompatConfigForKey(key: DeprecationTypes | 'MODE') {
+ const instance = getCurrentInstance()
+ const instanceConfig =
+ instance && (instance.type as ComponentOptions).compatConfig
+ if (instanceConfig && key in instanceConfig) {
+ return instanceConfig[key]
+ }
return globalCompatConfig[key]
}
export function isCompatEnabled(key: DeprecationTypes): boolean {
- const config = getCompatConfig(key)
- return !config || config.enabled !== false
+ const mode = getCompatConfigForKey('MODE') || 2
+ const val = getCompatConfigForKey(key)
+ if (mode === 2) {
+ return val !== false
+ } else {
+ return val === true || val === 'suppress-warning'
+ }
}
export function assertCompatEnabled(key: DeprecationTypes, ...args: any[]) {
// 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 }
+ COMPONENT_ASYNC: false,
+ COMPONENT_FUNCTIONAL: false,
+ WATCH_ARRAY: false,
+ INSTANCE_ATTRS_CLASS_STYLE: false
})
}
isRuntimeOnly
} from '../component'
import { warn } from '../warning'
-import { getCompatConfig } from './compatConfig'
+import { getCompatConfigForKey, isCompatEnabled } from './compatConfig'
export const enum DeprecationTypes {
GLOBAL_MOUNT = 'GLOBAL_MOUNT',
`Components with inheritAttrs: false will no longer auto-inherit ` +
`class/style on its root element. If your code relies on this behavior, ` +
`you may see broken styling and need to adjust your CSS. Otherwise, ` +
- `you can suppress this warning with:` +
+ `you can disable the compat behavior and suppress this warning with:` +
`\n\n configureCompat({ ${
DeprecationTypes.INSTANCE_ATTRS_CLASS_STYLE
- }: { warning: false }})\n`,
+ }: false )\n`,
link: `https://v3.vuejs.org/guide/migration/attrs-includes-class-style.html`
},
`trigger on array mutation unless the "deep" option is specified. ` +
`If current usage is intended, you can disable the compat behavior and ` +
`suppress this warning with:` +
- `\n\n configureCompat({ ${
- DeprecationTypes.WATCH_ARRAY
- }: { enabled: false }})\n`,
+ `\n\n configureCompat({ ${DeprecationTypes.WATCH_ARRAY}: false })\n`,
link: `https://v3.vuejs.org/guide/migration/watch.html`
},
`you can disable the compat behavior and suppress this warning with:` +
`\n\n configureCompat({ ${
DeprecationTypes.ATTR_FALSE_VALUE
- }: { enabled: false }})\n`,
+ }: false })\n`,
link: `https://v3.vuejs.org/guide/migration/attribute-coercion.html`
},
`you can disable the compat behavior and suppress this warning with:` +
`\n\n configureCompat({ ${
DeprecationTypes.ATTR_ENUMERATED_COERSION
- }: { enabled: false }})\n`,
+ }: false })\n`,
link: `https://v3.vuejs.org/guide/migration/attribute-coercion.html`
},
`warning with:` +
`\n\n configureCompat({ ${
DeprecationTypes.TRANSITION_GROUP_ROOT
- }: { enabled: false }})\n`,
+ }: false })\n`,
link: `https://v3.vuejs.org/guide/migration/transition-group.html`
},
`then disable compat for legacy async components with:` +
`\n\n configureCompat({ ${
DeprecationTypes.COMPONENT_ASYNC
- }: { enabled: false }})\n`
+ }: false })\n`
)
},
link: `https://v3.vuejs.org/guide/migration/functional-components.html`
}
// check user config
- const config = getCompatConfig(key)
- if (
- config &&
- (config.warning === false ||
- (config.enabled === false && config.warning !== true))
- ) {
+ const config = getCompatConfigForKey(key)
+ if (config === 'suppress-warning') {
return
}
typeof message === 'function' ? message(...args) : message
}${link ? `\n Details: ${link}` : ``}`
)
+ if (!isCompatEnabled(key)) {
+ console.error(
+ `^ The above deprecation's compat behavior is disabled and will likely ` +
+ `lead to runtime errors.`
+ )
+ }
}
import { UnionToIntersection } from './helpers/typeUtils'
import { deepMergeData } from './compat/data'
import { DeprecationTypes } from './compat/deprecations'
-import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
+import {
+ CompatConfig,
+ isCompatEnabled,
+ softAssertCompatEnabled
+} from './compat/compatConfig'
/**
* Interface for declaring custom options.
Mixin extends ComponentOptionsMixin,
Extends extends ComponentOptionsMixin
> {
+ compatConfig?: CompatConfig
+
// allow any custom options
[key: string]: any
import { isCompatEnabled } from './compat/compatConfig'
import { DeprecationTypes } from './compat/deprecations'
-const isHookEventCompatEnabled =
- __COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS)
-
export interface Renderer<HostElement = RendererElement> {
render: RootRenderFunction<HostElement>
createApp: CreateAppFunction<HostElement>
options: RendererOptions,
createHydrationFns?: typeof createHydrationFunctions
): any {
+ const isHookEventCompatEnabled =
+ __COMPAT__ && isCompatEnabled(DeprecationTypes.INSTANCE_EVENT_HOOKS)
+
// compile-time feature flags check
if (__ESM_BUNDLER__ && !__TEST__) {
initFeatureFlags()