1
- import { ErrorCodes , createCompilerError } from '@vue/compiler-dom'
1
+ import {
2
+ ElementTypes ,
3
+ ErrorCodes ,
4
+ createCompilerError ,
5
+ } from '@vue/compiler-dom'
2
6
import type { DirectiveTransform } from '../transform'
3
7
import { IRNodeTypes , type KeyOverride , type SetEventIRNode } from '../ir'
4
8
import { resolveModifiers } from '@vue/compiler-dom'
5
- import { extend , makeMap } from '@vue/shared'
9
+ import { extend , makeMap , toHandlerKey } from '@vue/shared'
6
10
import { resolveExpression } from '../utils'
11
+ import { EMPTY_EXPRESSION } from './utils'
7
12
8
13
const delegatedEvents = /*#__PURE__*/ makeMap (
9
14
'beforeinput,click,dblclick,contextmenu,focusin,focusout,input,keydown,' +
@@ -14,6 +19,8 @@ const delegatedEvents = /*#__PURE__*/ makeMap(
14
19
15
20
export const transformVOn : DirectiveTransform = ( dir , node , context ) => {
16
21
let { arg, exp, loc, modifiers } = dir
22
+ const isComponent = node . tagType === ElementTypes . COMPONENT
23
+
17
24
if ( ! exp && ( ! modifiers . length || ! arg ) ) {
18
25
context . options . onError (
19
26
createCompilerError ( ErrorCodes . X_V_ON_NO_EXPRESSION , loc ) ,
@@ -70,6 +77,18 @@ export const transformVOn: DirectiveTransform = (dir, node, context) => {
70
77
}
71
78
}
72
79
80
+ if ( isComponent ) {
81
+ if ( arg . isStatic ) {
82
+ arg = extend ( { } , arg , { content : toHandlerKey ( arg . content ) } )
83
+ }
84
+ const handler = exp || EMPTY_EXPRESSION
85
+ return {
86
+ key : arg ,
87
+ value : handler ,
88
+ runtimeHandler : ! arg . isStatic ,
89
+ }
90
+ }
91
+
73
92
const operation : SetEventIRNode = {
74
93
type : IRNodeTypes . SET_EVENT ,
75
94
element : context . reference ( ) ,
0 commit comments