Skip to content

Commit 26fee41

Browse files
authored
feat: compound expression for v-on (#60)
1 parent fb4d9a1 commit 26fee41

File tree

7 files changed

+532
-35
lines changed

7 files changed

+532
-35
lines changed

packages/compiler-vapor/__tests__/transforms/__snapshots__/vOn.spec.ts.snap

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ export function render(_ctx) {
1212
}"
1313
`;
1414

15+
exports[`v-on > complex member expression w/ prefixIdentifiers: true 1`] = `
16+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
17+
18+
export function render(_ctx) {
19+
const t0 = _template("<div></div>")
20+
const n0 = t0()
21+
const { 0: [n1],} = _children(n0)
22+
_on(n1, "click", (...args) => (_ctx.a['b' + _ctx.c] && _ctx.a['b' + _ctx.c](...args)))
23+
return n0
24+
}"
25+
`;
26+
1527
exports[`v-on > dynamic arg 1`] = `
1628
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
1729
@@ -26,6 +38,34 @@ export function render(_ctx) {
2638
}"
2739
`;
2840

41+
exports[`v-on > dynamic arg with complex exp prefixing 1`] = `
42+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
43+
44+
export function render(_ctx) {
45+
const t0 = _template("<div></div>")
46+
const n0 = t0()
47+
const { 0: [n1],} = _children(n0)
48+
_renderEffect(() => {
49+
_on(n1, _ctx.event(_ctx.foo), (...args) => (_ctx.handler && _ctx.handler(...args)))
50+
})
51+
return n0
52+
}"
53+
`;
54+
55+
exports[`v-on > dynamic arg with prefixing 1`] = `
56+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on } from 'vue/vapor';
57+
58+
export function render(_ctx) {
59+
const t0 = _template("<div></div>")
60+
const n0 = t0()
61+
const { 0: [n1],} = _children(n0)
62+
_renderEffect(() => {
63+
_on(n1, _ctx.event, (...args) => (_ctx.handler && _ctx.handler(...args)))
64+
})
65+
return n0
66+
}"
67+
`;
68+
2969
exports[`v-on > event modifier 1`] = `
3070
"import { template as _template, children as _children, on as _on, withModifiers as _withModifiers, withKeys as _withKeys } from 'vue/vapor';
3171
@@ -59,6 +99,133 @@ export function render(_ctx) {
5999
}"
60100
`;
61101

102+
exports[`v-on > function expression w/ prefixIdentifiers: true 1`] = `
103+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
104+
105+
export function render(_ctx) {
106+
const t0 = _template("<div></div>")
107+
const n0 = t0()
108+
const { 0: [n1],} = _children(n0)
109+
_on(n1, "click", e => _ctx.foo(e))
110+
return n0
111+
}"
112+
`;
113+
114+
exports[`v-on > inline statement w/ prefixIdentifiers: true 1`] = `
115+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
116+
117+
export function render(_ctx) {
118+
const t0 = _template("<div></div>")
119+
const n0 = t0()
120+
const { 0: [n1],} = _children(n0)
121+
_on(n1, "click", $event => (_ctx.foo($event)))
122+
return n0
123+
}"
124+
`;
125+
126+
exports[`v-on > multiple inline statements w/ prefixIdentifiers: true 1`] = `
127+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
128+
129+
export function render(_ctx) {
130+
const t0 = _template("<div></div>")
131+
const n0 = t0()
132+
const { 0: [n1],} = _children(n0)
133+
_on(n1, "click", $event => {_ctx.foo($event);_ctx.bar()})
134+
return n0
135+
}"
136+
`;
137+
138+
exports[`v-on > should NOT add a prefix to $event if the expression is a function expression 1`] = `
139+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
140+
141+
export function render(_ctx) {
142+
const t0 = _template("<div></div>")
143+
const n0 = t0()
144+
const { 0: [n1],} = _children(n0)
145+
_on(n1, "click", $event => {_ctx.i++;_ctx.foo($event)})
146+
return n0
147+
}"
148+
`;
149+
150+
exports[`v-on > should NOT wrap as function if expression is already function expression (with Typescript) 1`] = `
151+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
152+
153+
export function render(_ctx) {
154+
const t0 = _template("<div></div>")
155+
const n0 = t0()
156+
const { 0: [n1],} = _children(n0)
157+
_on(n1, "click", (e: any): any => _ctx.foo(e))
158+
return n0
159+
}"
160+
`;
161+
162+
exports[`v-on > should NOT wrap as function if expression is already function expression (with newlines) 1`] = `
163+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
164+
165+
export function render(_ctx) {
166+
const t0 = _template("<div></div>")
167+
const n0 = t0()
168+
const { 0: [n1],} = _children(n0)
169+
_on(n1, "click",
170+
$event => {
171+
_ctx.foo($event)
172+
}
173+
)
174+
return n0
175+
}"
176+
`;
177+
178+
exports[`v-on > should NOT wrap as function if expression is already function expression 1`] = `
179+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
180+
181+
export function render(_ctx) {
182+
const t0 = _template("<div></div>")
183+
const n0 = t0()
184+
const { 0: [n1],} = _children(n0)
185+
_on(n1, "click", $event => _ctx.foo($event))
186+
return n0
187+
}"
188+
`;
189+
190+
exports[`v-on > should NOT wrap as function if expression is complex member expression 1`] = `
191+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
192+
193+
export function render(_ctx) {
194+
const t0 = _template("<div></div>")
195+
const n0 = t0()
196+
const { 0: [n1],} = _children(n0)
197+
_on(n1, "click", (...args) => (_ctx.a['b' + _ctx.c] && _ctx.a['b' + _ctx.c](...args)))
198+
return n0
199+
}"
200+
`;
201+
202+
exports[`v-on > should handle multi-line statement 1`] = `
203+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
204+
205+
export function render(_ctx) {
206+
const t0 = _template("<div></div>")
207+
const n0 = t0()
208+
const { 0: [n1],} = _children(n0)
209+
_on(n1, "click", $event => {
210+
_ctx.foo();
211+
_ctx.bar()
212+
})
213+
return n0
214+
}"
215+
`;
216+
217+
exports[`v-on > should handle multiple inline statement 1`] = `
218+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
219+
220+
export function render(_ctx) {
221+
const t0 = _template("<div></div>")
222+
const n0 = t0()
223+
const { 0: [n1],} = _children(n0)
224+
_on(n1, "click", $event => {_ctx.foo();_ctx.bar()})
225+
return n0
226+
}"
227+
`;
228+
62229
exports[`v-on > should not wrap keys guard if no key modifier is present 1`] = `
63230
"import { template as _template, children as _children, on as _on, withModifiers as _withModifiers } from 'vue/vapor';
64231
@@ -148,6 +315,32 @@ export function render(_ctx) {
148315
}"
149316
`;
150317

318+
exports[`v-on > should wrap as function if expression is inline statement 1`] = `
319+
"import { template as _template, children as _children, on as _on } from 'vue/vapor';
320+
321+
export function render(_ctx) {
322+
const t0 = _template("<div></div>")
323+
const n0 = t0()
324+
const { 0: [n1],} = _children(n0)
325+
_on(n1, "click", $event => (_ctx.i++))
326+
return n0
327+
}"
328+
`;
329+
330+
exports[`v-on > should wrap both for dynamic key event w/ left/right modifiers 1`] = `
331+
"import { template as _template, children as _children, renderEffect as _renderEffect, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
332+
333+
export function render(_ctx) {
334+
const t0 = _template("<div></div>")
335+
const n0 = t0()
336+
const { 0: [n1],} = _children(n0)
337+
_renderEffect(() => {
338+
_on(n1, _ctx.e, _withKeys(_withModifiers((...args) => (_ctx.test && _ctx.test(...args)), ["left"]), ["left"]))
339+
})
340+
return n0
341+
}"
342+
`;
343+
151344
exports[`v-on > should wrap keys guard for keyboard events or dynamic events 1`] = `
152345
"import { template as _template, children as _children, on as _on, withKeys as _withKeys, withModifiers as _withModifiers } from 'vue/vapor';
153346

0 commit comments

Comments
 (0)