-import { extend, hasOwn, isArray } from '@vue/shared'
+import { extend, hasOwn, isArray, isFunction } from '@vue/shared'
import {
+ Component,
ComponentInternalInstance,
ComponentOptions,
formatComponentName,
export type CompatConfig = Partial<
Record<DeprecationTypes, boolean | 'suppress-warning'>
> & {
- MODE?: 2 | 3
+ MODE?: 2 | 3 | ((comp: Component | null) => 2 | 3)
}
export const globalCompatConfig: CompatConfig = {
return false
}
- const mode = getCompatConfigForKey('MODE', instance) || 2
+ const rawMode = getCompatConfigForKey('MODE', instance) || 2
const val = getCompatConfigForKey(key, instance)
+
+ const mode = isFunction(rawMode)
+ ? rawMode(instance && instance.type)
+ : rawMode
+
if (mode === 2) {
return val !== false
} else {
toggleDeprecationWarning
} from '../../runtime-core/src/compat/compatConfig'
import { triggerEvent } from './utils'
+import { h } from '@vue/runtime-core'
beforeEach(() => {
toggleDeprecationWarning(true)
Vue.configureCompat({ MODE: 3 })
})
+test('mode as function', () => {
+ const Foo = {
+ name: 'Foo',
+ render: (h: any) => h('div', 'foo')
+ }
+
+ const Bar = {
+ name: 'Bar',
+ data: () => ({ msg: 'bar' }),
+ render: (ctx: any) => h('div', ctx.msg)
+ }
+
+ toggleDeprecationWarning(false)
+ Vue.configureCompat({
+ MODE: comp => (comp && comp.name === 'Bar' ? 3 : 2)
+ })
+
+ const vm = new Vue({
+ components: { Foo, Bar },
+ template: `<div><foo/><bar/></div>`
+ }).$mount()
+
+ expect(vm.$el.innerHTML).toBe(`<div>foo</div><div>bar</div>`)
+})
+
test('WATCH_ARRAY', async () => {
const spy = jest.fn()
const vm = new Vue({