app.mount(root)
expect(serializeInner(root)).toBe('hello')
})
+
+ // config.compilerOptions is tested in packages/vue since it is only
+ // supported in the full build.
})
validateComponentName,
Component
} from './component'
-import { ComponentOptions } from './componentOptions'
+import { ComponentOptions, RuntimeCompilerOptions } from './componentOptions'
import { ComponentPublicInstance } from './componentPublicInstance'
import { Directive, validateDirectiveName } from './directives'
import { RootRenderFunction } from './renderer'
/**
* Options to pass to @vue/compiler-dom.
- * *Only supported in runtime compiler build.*
+ * Only supported in runtime compiler build.
*/
- compilerOptions: {
- isCustomElement: (tag: string) => boolean
- whitespace?: 'preserve' | 'condense'
- comments?: boolean
- delimiters?: [string, string]
- }
+ compilerOptions: RuntimeCompilerOptions
}
export interface AppContext {
} from '../compatConfig'
beforeEach(() => {
+ toggleDeprecationWarning(false)
Vue.configureCompat({ MODE: 2 })
})
--- /dev/null
+import Vue from '@vue/compat'
+import { toggleDeprecationWarning } from '../compatConfig'
+
+beforeEach(() => {
+ toggleDeprecationWarning(false)
+ Vue.configureCompat({ MODE: 2 })
+})
+
+afterEach(() => {
+ Vue.configureCompat({ MODE: 3 })
+ toggleDeprecationWarning(false)
+})
+
+function triggerEvent(
+ target: Element,
+ event: string,
+ process?: (e: any) => any
+) {
+ const e = document.createEvent('HTMLEvents')
+ e.initEvent(event, true, true)
+ if (process) process(e)
+ target.dispatchEvent(e)
+ return e
+}
+
+// only testing config options that affect runtime behavior.
+
+test('GLOBAL_KEY_CODES', () => {
+ Vue.config.keyCodes = {
+ foo: 86,
+ bar: [38, 87]
+ }
+
+ const onFoo = jest.fn()
+ const onBar = jest.fn()
+
+ const el = document.createElement('div')
+ new Vue({
+ el,
+ template: `<input type="text" @keyup.foo="onFoo" @keyup.bar="onBar">`,
+ methods: {
+ onFoo,
+ onBar
+ }
+ })
+
+ triggerEvent(el.children[0], 'keyup', e => {
+ e.key = '_'
+ e.keyCode = 86
+ })
+ expect(onFoo).toHaveBeenCalledTimes(1)
+ expect(onBar).toHaveBeenCalledTimes(0)
+
+ triggerEvent(el.children[0], 'keyup', e => {
+ e.key = '_'
+ e.keyCode = 38
+ })
+ expect(onFoo).toHaveBeenCalledTimes(1)
+ expect(onBar).toHaveBeenCalledTimes(1)
+
+ triggerEvent(el.children[0], 'keyup', e => {
+ e.key = '_'
+ e.keyCode = 87
+ })
+ expect(onFoo).toHaveBeenCalledTimes(1)
+ expect(onBar).toHaveBeenCalledTimes(2)
+})
+
+test('GLOBAL_IGNORED_ELEMENTS', () => {
+ Vue.config.ignoredElements = [/^v-/, 'foo']
+ const el = document.createElement('div')
+ new Vue({
+ el,
+ template: `<v-foo/><foo/>`
+ })
+ expect(el.innerHTML).toBe(`<v-foo></v-foo><foo></foo>`)
+})
NOOP,
EMPTY_OBJ,
isArray,
- isObject
+ isObject,
+ isString
} from '@vue/shared'
import { warn } from '../warning'
import { cloneVNode, createVNode } from '../vnode'
) {
continue
}
+ const val = singletonApp.config[key as keyof AppConfig]
// @ts-ignore
- app.config[key] = singletonApp.config[key]
+ app.config[key] = val
+
+ // compat for runtime ignoredElements -> isCustomElement
+ if (
+ key === 'ignoredElements' &&
+ isCompatEnabled(DeprecationTypes.CONFIG_IGNORED_ELEMENTS, null) &&
+ !isRuntimeOnly() &&
+ isArray(val)
+ ) {
+ app.config.compilerOptions.isCustomElement = tag => {
+ return val.some(v => (isString(v) ? v === tag : v.test(tag)))
+ }
+ }
}
isCopyingConfig = false
-import { extend, isArray, isString } from '@vue/shared'
+import { extend, isArray } from '@vue/shared'
import { AppConfig } from '../apiCreateApp'
-import { isRuntimeOnly } from '../component'
import { mergeDataOption } from './data'
-import {
- DeprecationTypes,
- warnDeprecation,
- isCompatEnabled
-} from './compatConfig'
+import { DeprecationTypes, warnDeprecation } from './compatConfig'
import { isCopyingConfig } from './global'
// legacy config warnings
warnDeprecation(legacyConfigOptions[key], null)
}
val = newVal
-
- // compat for runtime ignoredElements -> isCustomElement
- if (
- key === 'ignoredElements' &&
- isCompatEnabled(DeprecationTypes.CONFIG_IGNORED_ELEMENTS, null) &&
- !isRuntimeOnly() &&
- isArray(newVal)
- ) {
- config.isCustomElement = tag => {
- return newVal.some(
- val => (isString(val) ? val === tag : val.test(tag))
- )
- }
- }
}
})
})