|
|
@@ -5,7 +5,9 @@ import {
|
|
|
createCallExpression,
|
|
|
createObjectExpression,
|
|
|
createSimpleExpression,
|
|
|
- NodeTypes
|
|
|
+ NodeTypes,
|
|
|
+ CallExpression,
|
|
|
+ ObjectExpression
|
|
|
} from '@vue/compiler-core'
|
|
|
import { V_ON_MODIFIERS_GUARD, V_ON_KEYS_GUARD } from '../runtimeHelpers'
|
|
|
|
|
|
@@ -32,6 +34,7 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
|
|
const { modifiers } = dir
|
|
|
const baseResult = baseTransform(dir, node, context)
|
|
|
if (!modifiers.length) return baseResult
|
|
|
+
|
|
|
const { key, value } = baseResult.props[0]
|
|
|
const runtimeModifiers = modifiers.filter(m => !(m in EVENT_OPTION_MODIFIERS))
|
|
|
let handler = createCallExpression(context.helper(V_ON_MODIFIERS_GUARD), [
|
|
|
@@ -49,17 +52,15 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
|
|
JSON.stringify(runtimeModifiers.filter(m => !(m in NOT_KEY_MODIFIERS)))
|
|
|
])
|
|
|
}
|
|
|
- const properties = [
|
|
|
- createObjectProperty('handler', handler),
|
|
|
- // so the runtime knows the options never change
|
|
|
- createObjectProperty('persistent', createSimpleExpression('true', false))
|
|
|
- ]
|
|
|
+
|
|
|
+ let returnExp: CallExpression | ObjectExpression = handler
|
|
|
|
|
|
const eventOptionModifiers = modifiers.filter(
|
|
|
modifier => modifier in EVENT_OPTION_MODIFIERS
|
|
|
)
|
|
|
if (eventOptionModifiers.length) {
|
|
|
- properties.push(
|
|
|
+ returnExp = createObjectExpression([
|
|
|
+ createObjectProperty('handler', handler),
|
|
|
createObjectProperty(
|
|
|
'options',
|
|
|
createObjectExpression(
|
|
|
@@ -70,12 +71,14 @@ export const transformOn: DirectiveTransform = (dir, node, context) => {
|
|
|
)
|
|
|
)
|
|
|
)
|
|
|
- )
|
|
|
- )
|
|
|
+ ),
|
|
|
+ // so the runtime knows the options never change
|
|
|
+ createObjectProperty('persistent', createSimpleExpression('true', false))
|
|
|
+ ])
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
- props: [createObjectProperty(key, createObjectExpression(properties))],
|
|
|
+ props: [createObjectProperty(key, returnExp)],
|
|
|
needRuntime: false
|
|
|
}
|
|
|
}
|