]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core/v-on): pass noninitial arguments in cached event handlers (#1265)
authorCathrine Vaage <cathrine.vaage@gmail.com>
Mon, 15 Jun 2020 19:04:03 +0000 (21:04 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Jun 2020 19:04:03 +0000 (15:04 -0400)
packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap
packages/compiler-core/__tests__/transforms/vOn.spec.ts
packages/compiler-core/src/transforms/vOn.ts

index fcad21be3d88fefc18708fa059ffc7e8184a2c01..d4415ede0c445a70940ea0470c910eaec5013ad8 100644 (file)
@@ -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)))
       })
     ])
   ]))
index 158daa29b64be6d475e02df0cafc82760a56dc34..300a4624d1457c4f3f8e389258a557f1d40709d4 100644 (file)
@@ -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++` }, `)`]
           }
         }
       ]
@@ -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()` },
+              `}`
+            ]
           }
         }
       ]
@@ -196,7 +200,7 @@ describe('compiler: transform v-on', () => {
           value: {
             type: NodeTypes.COMPOUND_EXPRESSION,
             children: [
-              `$event => (`,
+              `($event, ...args) => (`,
               {
                 type: NodeTypes.COMPOUND_EXPRESSION,
                 children: [
@@ -226,7 +230,7 @@ describe('compiler: transform v-on', () => {
           value: {
             type: NodeTypes.COMPOUND_EXPRESSION,
             children: [
-              `$event => {`,
+              `($event, ...args) => {`,
               {
                 children: [
                   { content: `_ctx.foo` },
@@ -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)` },
+            `)`
+          ]
         }
       })
     })
@@ -444,7 +452,7 @@ describe('compiler: transform v-on', () => {
         value: {
           type: NodeTypes.COMPOUND_EXPRESSION,
           children: [
-            `$event => (`,
+            `($event, ...args) => (`,
             { children: [{ content: `_ctx.foo` }, `++`] },
             `)`
           ]
index d245841004e191b2ff85a569760722489102a6f0..026ad3cf9f8172f84dec3101b29da4dad8fbb4f2 100644 (file)
@@ -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)`)
         }
       }
     }
@@ -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 ? `}` : `)`
       ])