From: Evan You Date: Mon, 15 Jun 2020 19:24:46 +0000 (-0400) Subject: refactor: only inject rest args for member expression handlers + fix tests X-Git-Tag: v3.0.0-beta.16~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=605953a154872ecad0e02310d4cccaa1f60b72fe;p=thirdparty%2Fvuejs%2Fcore.git refactor: only inject rest args for member expression handlers + fix tests --- diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index 300a4624d1..f17c5b9aa4 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -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++` }, `)`] } } ] @@ -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(`
`) expect((node.codegenNode as VNodeCall).props).toMatchObject({ properties: [ @@ -200,7 +196,7 @@ describe('compiler: transform v-on', () => { value: { type: NodeTypes.COMPOUND_EXPRESSION, children: [ - `($event, ...args) => (`, + `$event => (`, { type: NodeTypes.COMPOUND_EXPRESSION, children: [ @@ -230,7 +226,7 @@ describe('compiler: transform v-on', () => { value: { type: NodeTypes.COMPOUND_EXPRESSION, children: [ - `($event, ...args) => {`, + `$event => {`, { children: [ { content: `_ctx.foo` }, @@ -452,7 +448,7 @@ describe('compiler: transform v-on', () => { value: { type: NodeTypes.COMPOUND_EXPRESSION, children: [ - `($event, ...args) => (`, + `$event => (`, { children: [{ content: `_ctx.foo` }, `++`] }, `)` ] diff --git a/packages/compiler-core/src/transforms/vOn.ts b/packages/compiler-core/src/transforms/vOn.ts index 026ad3cf9f..7698857886 100644 --- a/packages/compiler-core/src/transforms/vOn.ts +++ b/packages/compiler-core/src/transforms/vOn.ts @@ -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 ? `}` : `)` ])