Skip to content

Commit

Permalink
refactor: only inject rest args for member expression handlers + fix …
Browse files Browse the repository at this point in the history
…tests
  • Loading branch information
yyx990803 committed Jun 15, 2020
1 parent 7e28173 commit 605953a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 6 additions & 10 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Expand Up @@ -142,7 +142,7 @@ describe('compiler: transform v-on', () => {
key: { content: `onClick` },
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [`($event, ...args) => (`, { content: `i++` }, `)`]
children: [`$event => (`, { content: `i++` }, `)`]
}
}
]
Expand All @@ -160,18 +160,14 @@ 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, ...args) => {`,
{ content: `foo();bar()` },
`}`
]
children: [`$event => {`, { content: `foo();bar()` }, `}`]
}
}
]
})
})

test('should handle multiple line statement', () => {
test('should handle multi-line statement', () => {
const { node } = parseWithVOn(`<div @click="\nfoo();\nbar()\n"/>`)
expect((node.codegenNode as VNodeCall).props).toMatchObject({
properties: [
Expand Down Expand Up @@ -200,7 +196,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`($event, ...args) => (`,
`$event => (`,
{
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
Expand Down Expand Up @@ -230,7 +226,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`($event, ...args) => {`,
`$event => {`,
{
children: [
{ content: `_ctx.foo` },
Expand Down Expand Up @@ -452,7 +448,7 @@ describe('compiler: transform v-on', () => {
value: {
type: NodeTypes.COMPOUND_EXPRESSION,
children: [
`($event, ...args) => (`,
`$event => (`,
{ children: [{ content: `_ctx.foo` }, `++`] },
`)`
]
Expand Down
4 changes: 3 additions & 1 deletion packages/compiler-core/src/transforms/vOn.ts
Expand Up @@ -102,7 +102,9 @@ export const transformOn: DirectiveTransform = (
if (isInlineStatement || (isCacheable && isMemberExp)) {
// wrap inline statement in a function expression
exp = createCompoundExpression([
`($event, ...args) => ${hasMultipleStatements ? `{` : `(`}`,
`${isInlineStatement ? `$event` : `($event, ...args)`} => ${
hasMultipleStatements ? `{` : `(`
}`,
exp,
hasMultipleStatements ? `}` : `)`
])
Expand Down

0 comments on commit 605953a

Please sign in to comment.