Skip to content

Commit

Permalink
fix(compiler-core/v-on): pass noninitial arguments in cached event ha…
Browse files Browse the repository at this point in the history
…ndlers (#1265)
  • Loading branch information
cathrinevaage authored Jun 15, 2020
1 parent 35dbef2 commit 7e28173
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ export function render(_ctx, _cache) {
return (_openBlock(), _createBlock(\\"div\\", null, [
_createVNode(\\"div\\", null, [
_createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = $event => (_ctx.foo($event)))
onClick: _cache[1] || (_cache[1] = ($event, ...args) => (_ctx.foo($event, ...args)))
})
])
]))
Expand Down
20 changes: 14 additions & 6 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('compiler: transform v-on', () => {
key: { content: `onClick` },
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`$event => (`, { content: `i++` }, `)`]
children: [`($event, ...args) => (`, { content: `i++` }, `)`]
}
}
]
Expand All @@ -160,7 +160,11 @@ describe('compiler: transform v-on', () => {
// should wrap with `{` for multiple statements
// in this case the return value is discarded and the behavior is
// consistent with 2.x
children: [`$event => {`, { content: `foo();bar()` }, `}`]
children: [
`($event, ...args) => {`,
{ content: `foo();bar()` },
`}`
]
}
}
]
Expand Down Expand Up @@ -196,7 +200,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`$event => (`,
`($event, ...args) => (`,
{
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
Expand Down Expand Up @@ -226,7 +230,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`$event => {`,
`($event, ...args) => {`,
{
children: [
{ content: `_ctx.foo` },
Expand Down Expand Up @@ -400,7 +404,11 @@ describe('compiler: transform v-on', () => {
index: 1,
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`$event => (`, { content: `_ctx.foo($event)` }, `)`]
children: [
`($event, ...args) => (`,
{ content: `_ctx.foo($event, ...args)` },
`)`
]
}
})
})
Expand Down Expand Up @@ -444,7 +452,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`$event => (`,
`($event, ...args) => (`,
{ children: [{ content: `_ctx.foo` }, `++`] },
`)`
]
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-core/src/transforms/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export const transformOn: DirectiveTransform = (
// avoiding the need to be patched.
if (isCacheable && isMemberExp) {
if (exp.type === NodeTypes.SIMPLE_EXPRESSION) {
exp.content += `($event)`
exp.content += `($event, ...args)`
} else {
exp.children.push(`($event)`)
exp.children.push(`($event, ...args)`)
}
}
}
Expand All @@ -102,7 +102,7 @@ export const transformOn: DirectiveTransform = (
if (isInlineStatement || (isCacheable && isMemberExp)) {
// wrap inline statement in a function expression
exp = createCompoundExpression([
`$event => ${hasMultipleStatements ? `{` : `(`}`,
`($event, ...args) => ${hasMultipleStatements ? `{` : `(`}`,
exp,
hasMultipleStatements ? `}` : `)`
])
Expand Down

0 comments on commit 7e28173

Please sign in to comment.