Skip to content

Commit 7e28173

Browse files
fix(compiler-core/v-on): pass noninitial arguments in cached event handlers (#1265)
1 parent 35dbef2 commit 7e28173

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export function render(_ctx, _cache) {
209209
return (_openBlock(), _createBlock(\\"div\\", null, [
210210
_createVNode(\\"div\\", null, [
211211
_createVNode(\\"div\\", {
212-
onClick: _cache[1] || (_cache[1] = $event => (_ctx.foo($event)))
212+
onClick: _cache[1] || (_cache[1] = ($event, ...args) => (_ctx.foo($event, ...args)))
213213
})
214214
])
215215
]))

packages/compiler-core/__tests__/transforms/vOn.spec.ts

+14-6
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('compiler: transform v-on', () => {
142142
key: { content: `onClick` },
143143
value: {
144144
type: NodeTypes.COMPOUND_EXPRESSION,
145-
children: [`$event => (`, { content: `i++` }, `)`]
145+
children: [`($event, ...args) => (`, { content: `i++` }, `)`]
146146
}
147147
}
148148
]
@@ -160,7 +160,11 @@ describe('compiler: transform v-on', () => {
160160
// should wrap with `{` for multiple statements
161161
// in this case the return value is discarded and the behavior is
162162
// consistent with 2.x
163-
children: [`$event => {`, { content: `foo();bar()` }, `}`]
163+
children: [
164+
`($event, ...args) => {`,
165+
{ content: `foo();bar()` },
166+
`}`
167+
]
164168
}
165169
}
166170
]
@@ -196,7 +200,7 @@ describe('compiler: transform v-on', () => {
196200
value: {
197201
type: NodeTypes.COMPOUND_EXPRESSION,
198202
children: [
199-
`$event => (`,
203+
`($event, ...args) => (`,
200204
{
201205
type: NodeTypes.COMPOUND_EXPRESSION,
202206
children: [
@@ -226,7 +230,7 @@ describe('compiler: transform v-on', () => {
226230
value: {
227231
type: NodeTypes.COMPOUND_EXPRESSION,
228232
children: [
229-
`$event => {`,
233+
`($event, ...args) => {`,
230234
{
231235
children: [
232236
{ content: `_ctx.foo` },
@@ -400,7 +404,11 @@ describe('compiler: transform v-on', () => {
400404
index: 1,
401405
value: {
402406
type: NodeTypes.COMPOUND_EXPRESSION,
403-
children: [`$event => (`, { content: `_ctx.foo($event)` }, `)`]
407+
children: [
408+
`($event, ...args) => (`,
409+
{ content: `_ctx.foo($event, ...args)` },
410+
`)`
411+
]
404412
}
405413
})
406414
})
@@ -444,7 +452,7 @@ describe('compiler: transform v-on', () => {
444452
value: {
445453
type: NodeTypes.COMPOUND_EXPRESSION,
446454
children: [
447-
`$event => (`,
455+
`($event, ...args) => (`,
448456
{ children: [{ content: `_ctx.foo` }, `++`] },
449457
`)`
450458
]

packages/compiler-core/src/transforms/vOn.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ export const transformOn: DirectiveTransform = (
8383
// avoiding the need to be patched.
8484
if (isCacheable && isMemberExp) {
8585
if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
86-
exp.content += `($event)`
86+
exp.content += `($event, ...args)`
8787
} else {
88-
exp.children.push(`($event)`)
88+
exp.children.push(`($event, ...args)`)
8989
}
9090
}
9191
}
@@ -102,7 +102,7 @@ export const transformOn: DirectiveTransform = (
102102
if (isInlineStatement || (isCacheable && isMemberExp)) {
103103
// wrap inline statement in a function expression
104104
exp = createCompoundExpression([
105-
`$event => ${hasMultipleStatements ? `{` : `(`}`,
105+
`($event, ...args) => ${hasMultipleStatements ? `{` : `(`}`,
106106
exp,
107107
hasMultipleStatements ? `}` : `)`
108108
])

0 commit comments

Comments
 (0)