]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-core): fix scope var reference check for v-on expressions
authorEvan You <yyx990803@gmail.com>
Mon, 30 Nov 2020 20:19:22 +0000 (15:19 -0500)
committerEvan You <yyx990803@gmail.com>
Mon, 30 Nov 2020 20:19:32 +0000 (15:19 -0500)
fix #2564

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

index 9d8beca6167b71a3ddfc56f105783b532a6a28e1..a14198c8adc4bb110609d4b05a0fb13b4ef1ec35 100644 (file)
@@ -521,6 +521,21 @@ describe('compiler: transform component slots', () => {
       </Comp>`,
       true
     )
+
+    // #2564
+    assertDynamicSlots(
+      `<div v-for="i in list">
+        <Comp v-slot="bar"><button @click="fn(i)" /></Comp>
+      </div>`,
+      true
+    )
+
+    assertDynamicSlots(
+      `<div v-for="i in list">
+        <Comp v-slot="bar"><button @click="fn()" /></Comp>
+      </div>`,
+      false
+    )
   })
 
   test('named slot with v-if', () => {
index 207d53e4195a5018199b0da056f61ce0c4a056a9..02dd9796031e60d2889738d3033c8bc274c2ce45 100644 (file)
@@ -79,7 +79,12 @@ export const transformOn: DirectiveTransform = (
     // process the expression since it's been skipped
     if (!__BROWSER__ && context.prefixIdentifiers) {
       isInlineStatement && context.addIdentifiers(`$event`)
-      exp = processExpression(exp, context, false, hasMultipleStatements)
+      exp = dir.exp = processExpression(
+        exp,
+        context,
+        false,
+        hasMultipleStatements
+      )
       isInlineStatement && context.removeIdentifiers(`$event`)
       // with scope analysis, the function is hoistable if it has no reference
       // to scope variables.