Skip to content

Commit 605953a

Browse files
committed
refactor: only inject rest args for member expression handlers + fix tests
1 parent 7e28173 commit 605953a

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

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

+6-10
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, ...args) => (`, { content: `i++` }, `)`]
145+
children: [`$event => (`, { content: `i++` }, `)`]
146146
}
147147
}
148148
]
@@ -160,18 +160,14 @@ 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: [
164-
`($event, ...args) => {`,
165-
{ content: `foo();bar()` },
166-
`}`
167-
]
163+
children: [`$event => {`, { content: `foo();bar()` }, `}`]
168164
}
169165
}
170166
]
171167
})
172168
})
173169

174-
test('should handle multiple line statement', () => {
170+
test('should handle multi-line statement', () => {
175171
const { node } = parseWithVOn(`<div @click="\nfoo();\nbar()\n"/>`)
176172
expect((node.codegenNode as VNodeCall).props).toMatchObject({
177173
properties: [
@@ -200,7 +196,7 @@ describe('compiler: transform v-on', () => {
200196
value: {
201197
type: NodeTypes.COMPOUND_EXPRESSION,
202198
children: [
203-
`($event, ...args) => (`,
199+
`$event => (`,
204200
{
205201
type: NodeTypes.COMPOUND_EXPRESSION,
206202
children: [
@@ -230,7 +226,7 @@ describe('compiler: transform v-on', () => {
230226
value: {
231227
type: NodeTypes.COMPOUND_EXPRESSION,
232228
children: [
233-
`($event, ...args) => {`,
229+
`$event => {`,
234230
{
235231
children: [
236232
{ content: `_ctx.foo` },
@@ -452,7 +448,7 @@ describe('compiler: transform v-on', () => {
452448
value: {
453449
type: NodeTypes.COMPOUND_EXPRESSION,
454450
children: [
455-
`($event, ...args) => (`,
451+
`$event => (`,
456452
{ children: [{ content: `_ctx.foo` }, `++`] },
457453
`)`
458454
]

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ export const transformOn: DirectiveTransform = (
102102
if (isInlineStatement || (isCacheable && isMemberExp)) {
103103
// wrap inline statement in a function expression
104104
exp = createCompoundExpression([
105-
`($event, ...args) => ${hasMultipleStatements ? `{` : `(`}`,
105+
`${isInlineStatement ? `$event` : `($event, ...args)`} => ${
106+
hasMultipleStatements ? `{` : `(`
107+
}`,
106108
exp,
107109
hasMultipleStatements ? `}` : `)`
108110
])

0 commit comments

Comments
 (0)