feat(compiler-core): support aliasing vue: prefixed events to inline vnode hooks
This commit is contained in:
parent
1c9a4810fc
commit
4b0ca8709a
@ -1209,12 +1209,7 @@ describe('compiler: element transform', () => {
|
|||||||
|
|
||||||
test('force block for inline before-update handlers w/ children', () => {
|
test('force block for inline before-update handlers w/ children', () => {
|
||||||
expect(
|
expect(
|
||||||
parseWithElementTransform(`<div @vnode-before-update>hello</div>`).node
|
parseWithElementTransform(`<div @vue:before-update>hello</div>`).node
|
||||||
.isBlock
|
|
||||||
).toBe(true)
|
|
||||||
|
|
||||||
expect(
|
|
||||||
parseWithElementTransform(`<div @vnodeBeforeUpdate>hello</div>`).node
|
|
||||||
.isBlock
|
.isBlock
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
})
|
})
|
||||||
|
@ -438,6 +438,32 @@ describe('compiler: transform v-on', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('vue: prefixed events', () => {
|
||||||
|
const { node } = parseWithVOn(
|
||||||
|
`<div v-on:vue:mounted="onMount" @vue:before-update="onBeforeUpdate" />`
|
||||||
|
)
|
||||||
|
expect((node.codegenNode as VNodeCall).props).toMatchObject({
|
||||||
|
properties: [
|
||||||
|
{
|
||||||
|
key: {
|
||||||
|
content: `onVnodeMounted`
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
content: `onMount`
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: {
|
||||||
|
content: `onVnodeBeforeUpdate`
|
||||||
|
},
|
||||||
|
value: {
|
||||||
|
content: `onBeforeUpdate`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('cacheHandler', () => {
|
describe('cacheHandler', () => {
|
||||||
test('empty handler', () => {
|
test('empty handler', () => {
|
||||||
const { root, node } = parseWithVOn(`<div v-on:click.prevent />`, {
|
const { root, node } = parseWithVOn(`<div v-on:click.prevent />`, {
|
||||||
|
@ -550,7 +550,7 @@ export function buildProps(
|
|||||||
(isVBind && isStaticArgOf(arg, 'key')) ||
|
(isVBind && isStaticArgOf(arg, 'key')) ||
|
||||||
// inline before-update hooks need to force block so that it is invoked
|
// inline before-update hooks need to force block so that it is invoked
|
||||||
// before children
|
// before children
|
||||||
(isVOn && hasChildren && isStaticArgOf(arg, 'vnodeBeforeUpdate', true))
|
(isVOn && hasChildren && isStaticArgOf(arg, 'vue:before-update'))
|
||||||
) {
|
) {
|
||||||
shouldUseBlock = true
|
shouldUseBlock = true
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,11 @@ export const transformOn: DirectiveTransform = (
|
|||||||
let eventName: ExpressionNode
|
let eventName: ExpressionNode
|
||||||
if (arg.type === NodeTypes.SIMPLE_EXPRESSION) {
|
if (arg.type === NodeTypes.SIMPLE_EXPRESSION) {
|
||||||
if (arg.isStatic) {
|
if (arg.isStatic) {
|
||||||
const rawName = arg.content
|
let rawName = arg.content
|
||||||
|
// TODO deprecate @vnodeXXX usage
|
||||||
|
if (rawName.startsWith('vue:')) {
|
||||||
|
rawName = `vnode-${rawName.slice(4)}`
|
||||||
|
}
|
||||||
// for all event listeners, auto convert it to camelCase. See issue #2249
|
// for all event listeners, auto convert it to camelCase. See issue #2249
|
||||||
eventName = createSimpleExpression(
|
eventName = createSimpleExpression(
|
||||||
toHandlerKey(camelize(rawName)),
|
toHandlerKey(camelize(rawName)),
|
||||||
|
@ -42,14 +42,7 @@ import {
|
|||||||
WITH_MEMO,
|
WITH_MEMO,
|
||||||
OPEN_BLOCK
|
OPEN_BLOCK
|
||||||
} from './runtimeHelpers'
|
} from './runtimeHelpers'
|
||||||
import {
|
import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
|
||||||
isString,
|
|
||||||
isObject,
|
|
||||||
hyphenate,
|
|
||||||
extend,
|
|
||||||
NOOP,
|
|
||||||
camelize
|
|
||||||
} from '@vue/shared'
|
|
||||||
import { PropsExpression } from './transforms/transformElement'
|
import { PropsExpression } from './transforms/transformElement'
|
||||||
import { parseExpression } from '@babel/parser'
|
import { parseExpression } from '@babel/parser'
|
||||||
import { Expression } from '@babel/types'
|
import { Expression } from '@babel/types'
|
||||||
@ -298,14 +291,9 @@ export function findProp(
|
|||||||
|
|
||||||
export function isStaticArgOf(
|
export function isStaticArgOf(
|
||||||
arg: DirectiveNode['arg'],
|
arg: DirectiveNode['arg'],
|
||||||
name: string,
|
name: string
|
||||||
camel?: boolean
|
|
||||||
): boolean {
|
): boolean {
|
||||||
return !!(
|
return !!(arg && isStaticExp(arg) && arg.content === name)
|
||||||
arg &&
|
|
||||||
isStaticExp(arg) &&
|
|
||||||
(camel ? camelize(arg.content) : arg.content) === name
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function hasDynamicKeyVBind(node: ElementNode): boolean {
|
export function hasDynamicKeyVBind(node: ElementNode): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user