Skip to content

Commit 9db7095

Browse files
committed
fix(compiler-core): fix scope var reference check for v-on expressions
fix #2564
1 parent e41b46c commit 9db7095

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

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

+15
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,21 @@ describe('compiler: transform component slots', () => {
521521
</Comp>`,
522522
true
523523
)
524+
525+
// #2564
526+
assertDynamicSlots(
527+
`<div v-for="i in list">
528+
<Comp v-slot="bar"><button @click="fn(i)" /></Comp>
529+
</div>`,
530+
true
531+
)
532+
533+
assertDynamicSlots(
534+
`<div v-for="i in list">
535+
<Comp v-slot="bar"><button @click="fn()" /></Comp>
536+
</div>`,
537+
false
538+
)
524539
})
525540

526541
test('named slot with v-if', () => {

packages/compiler-core/src/transforms/vOn.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ export const transformOn: DirectiveTransform = (
7979
// process the expression since it's been skipped
8080
if (!__BROWSER__ && context.prefixIdentifiers) {
8181
isInlineStatement && context.addIdentifiers(`$event`)
82-
exp = processExpression(exp, context, false, hasMultipleStatements)
82+
exp = dir.exp = processExpression(
83+
exp,
84+
context,
85+
false,
86+
hasMultipleStatements
87+
)
8388
isInlineStatement && context.removeIdentifiers(`$event`)
8489
// with scope analysis, the function is hoistable if it has no reference
8590
// to scope variables.

0 commit comments

Comments
 (0)