fix(compiler-core): fix scope var reference check for v-on expressions

fix #2564
This commit is contained in:
Evan You 2020-11-30 15:19:22 -05:00
parent e41b46c396
commit 9db7095962
2 changed files with 21 additions and 1 deletions

View File

@ -521,6 +521,21 @@ describe('compiler: transform component slots', () => {
</Comp>`, </Comp>`,
true 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', () => { test('named slot with v-if', () => {

View File

@ -79,7 +79,12 @@ export const transformOn: DirectiveTransform = (
// process the expression since it's been skipped // process the expression since it's been skipped
if (!__BROWSER__ && context.prefixIdentifiers) { if (!__BROWSER__ && context.prefixIdentifiers) {
isInlineStatement && context.addIdentifiers(`$event`) isInlineStatement && context.addIdentifiers(`$event`)
exp = processExpression(exp, context, false, hasMultipleStatements) exp = dir.exp = processExpression(
exp,
context,
false,
hasMultipleStatements
)
isInlineStatement && context.removeIdentifiers(`$event`) isInlineStatement && context.removeIdentifiers(`$event`)
// with scope analysis, the function is hoistable if it has no reference // with scope analysis, the function is hoistable if it has no reference
// to scope variables. // to scope variables.