Skip to content

Commit 187bf8c

Browse files
committed
feat(compiler): support empty expression for event with modifiers
1 parent 32849a7 commit 187bf8c

File tree

3 files changed

+135
-418
lines changed

3 files changed

+135
-418
lines changed

packages/compiler/src/transforms/transformElement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ function transformProp(
262262

263263
if (
264264
!isDirectiveRegex.test(name) &&
265+
!isEventRegex.test(name) &&
265266
(!prop.value || prop.value.type === 'StringLiteral')
266267
) {
267268
if (isReservedProp(name)) return

packages/compiler/test/transforms/__snapshots__/vOn.spec.ts.snap

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,89 @@ exports[`v-on > event modifier 1`] = `
5555
return [n1, n3, n5, n7, n9, n11, n13, n15, n17, n19, n21, n23, n25, n27, n29, n31, n33, n35, n37, n39, n41, n43]
5656
"
5757
`;
58+
59+
exports[`v-on > should delegate event 1`] = `
60+
"import { delegateEvents as _delegateEvents, template as _template } from 'vue';
61+
const t0 = _template("<div></div>", true)
62+
_delegateEvents("click")
63+
64+
export function render(_ctx) {
65+
const n0 = t0()
66+
n0.$evtclick = e => _ctx.test(e)
67+
return n0
68+
}"
69+
`;
70+
71+
exports[`v-on > should not wrap keys guard if no key modifier is present 1`] = `
72+
"
73+
const n0 = t0()
74+
n0.$evtkeyup = _withModifiers(e => test(e), ["exact"])
75+
return n0
76+
"
77+
`;
78+
79+
exports[`v-on > should support multiple modifiers and event options w/ prefixIdentifiers: true 1`] = `
80+
"
81+
const n0 = t0()
82+
_on(n0, "click", _withModifiers(e => test(e), ["stop","prevent"]), {
83+
capture: true,
84+
once: true
85+
})
86+
return n0
87+
"
88+
`;
89+
90+
exports[`v-on > should transform click.middle 1`] = `
91+
"import { withModifiers as _withModifiers, delegateEvents as _delegateEvents, template as _template } from 'vue';
92+
const t0 = _template("<div></div>", true)
93+
_delegateEvents("mouseup")
94+
95+
export function render(_ctx) {
96+
const n0 = t0()
97+
n0.$evtmouseup = _withModifiers(e => _ctx.test(e), ["middle"])
98+
return n0
99+
}"
100+
`;
101+
102+
exports[`v-on > should transform click.right 1`] = `
103+
"import { withModifiers as _withModifiers, delegateEvents as _delegateEvents, template as _template } from 'vue';
104+
const t0 = _template("<div></div>", true)
105+
_delegateEvents("contextmenu")
106+
107+
export function render(_ctx) {
108+
const n0 = t0()
109+
n0.$evtcontextmenu = _withModifiers(e => _ctx.test(e), ["right"])
110+
return n0
111+
}"
112+
`;
113+
114+
exports[`v-on > should use delegate helper when have multiple events of same name 1`] = `
115+
"import { delegate as _delegate, withModifiers as _withModifiers, delegateEvents as _delegateEvents, template as _template } from 'vue';
116+
const t0 = _template("<div></div>", true)
117+
_delegateEvents("click")
118+
119+
export function render(_ctx) {
120+
const n0 = t0()
121+
_delegate(n0, "click", e => _ctx.test(e))
122+
_delegate(n0, "click", _withModifiers(e => _ctx.test(e), ["stop"]))
123+
return n0
124+
}"
125+
`;
126+
127+
exports[`v-on > should wrap keys guard for keyboard events or dynamic events 1`] = `
128+
"
129+
const n0 = t0()
130+
_on(n0, "keydown", _withKeys(_withModifiers(e => test(e), ["stop","ctrl"]), ["a"]), {
131+
capture: true
132+
})
133+
return n0
134+
"
135+
`;
136+
137+
exports[`v-on > should wrap keys guard for static key event w/ left/right modifiers 1`] = `
138+
"
139+
const n0 = t0()
140+
n0.$evtkeyup = _withKeys(e => test(e), ["left"])
141+
return n0
142+
"
143+
`;

0 commit comments

Comments
 (0)