Skip to content

Commit

Permalink
fix(compiler-core): fix scope var reference check for v-on expressions
Browse files Browse the repository at this point in the history
fix #2564
  • Loading branch information
yyx990803 committed Nov 30, 2020
1 parent e41b46c commit 9db7095
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Expand Up @@ -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', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-core/src/transforms/vOn.ts
Expand Up @@ -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.
Expand Down

0 comments on commit 9db7095

Please sign in to comment.