]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor(compiler-core): remove unnecessary arg in cached handler codegen
authorEvan You <yyx990803@gmail.com>
Wed, 8 Jul 2020 15:36:31 +0000 (11:36 -0400)
committerEvan You <yyx990803@gmail.com>
Wed, 8 Jul 2020 15:48:12 +0000 (11:48 -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 d4415ede0c445a70940ea0470c910eaec5013ad8..6926708345ec2000b89d0ffa086eceb3cff457ed 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, ...args) => (_ctx.foo($event, ...args)))
+        onClick: _cache[1] || (_cache[1] = (...args) => (_ctx.foo(...args)))
       })
     ])
   ]))
index f17c5b9aa464d7530bc03a3a02192e55418ec791..996d63e4909539de36c0e9c14d2c12a7c00a2a0f 100644 (file)
@@ -400,11 +400,7 @@ describe('compiler: transform v-on', () => {
         index: 1,
         value: {
           type: NodeTypes.COMPOUND_EXPRESSION,
-          children: [
-            `($event, ...args) => (`,
-            { content: `_ctx.foo($event, ...args)` },
-            `)`
-          ]
+          children: [`(...args) => (`, { content: `_ctx.foo(...args)` }, `)`]
         }
       })
     })
index 76988578860a9bf4f797e8beee02906f0a1d78e6..40e61a3f7b3dd36cca7166caaa2d49073a2b1d89 100644 (file)
@@ -70,9 +70,9 @@ export const transformOn: DirectiveTransform = (
 
     // process the expression since it's been skipped
     if (!__BROWSER__ && context.prefixIdentifiers) {
-      context.addIdentifiers(`$event`)
+      isInlineStatement && context.addIdentifiers(`$event`)
       exp = processExpression(exp, context, false, hasMultipleStatements)
-      context.removeIdentifiers(`$event`)
+      isInlineStatement && context.removeIdentifiers(`$event`)
       // with scope analysis, the function is hoistable if it has no reference
       // to scope variables.
       isCacheable =
@@ -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, ...args)`
+          exp.content += `(...args)`
         } else {
-          exp.children.push(`($event, ...args)`)
+          exp.children.push(`(...args)`)
         }
       }
     }
@@ -102,7 +102,7 @@ export const transformOn: DirectiveTransform = (
     if (isInlineStatement || (isCacheable && isMemberExp)) {
       // wrap inline statement in a function expression
       exp = createCompoundExpression([
-        `${isInlineStatement ? `$event` : `($event, ...args)`} => ${
+        `${isInlineStatement ? `$event` : `(...args)`} => ${
           hasMultipleStatements ? `{` : `(`
         }`,
         exp,