diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index c0038a1f..04be3fb1 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -375,7 +375,8 @@ function genScopedSlot ( el: ASTElement, state: CodegenState ): string { - if (el.if && !el.ifProcessed) { + const isLegacySyntax = el.attrsMap['slot-scope'] + if (el.if && !el.ifProcessed && !isLegacySyntax) { return genIf(el, state, genScopedSlot, `null`) } if (el.for && !el.forProcessed) { @@ -383,7 +384,9 @@ function genScopedSlot ( } const fn = `function(${String(el.slotScope)}){` + `return ${el.tag === 'template' - ? genChildren(el, state) || 'undefined' + ? el.if && isLegacySyntax + ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined` + : genChildren(el, state) || 'undefined' : genElement(el, state) }}` return `{key:${el.slotTarget || `"default"`},fn:${fn}}` diff --git a/test/unit/features/component/component-scoped-slot.spec.js b/test/unit/features/component/component-scoped-slot.spec.js index 7c6caf26..5141d9b1 100644 --- a/test/unit/features/component/component-scoped-slot.spec.js +++ b/test/unit/features/component/component-scoped-slot.spec.js @@ -650,6 +650,25 @@ describe('Component scoped slot', () => { }).then(done) }) + // #9422 + // the behavior of the new syntax is slightly different. + it('scoped slot v-if using slot-scope value', () => { + const Child = { + template: '