From ef8524ab7db8d64ac449ce74f5858aa9d91357ad Mon Sep 17 00:00:00 2001 From: Subhash Date: Sat, 1 Dec 2018 11:03:59 +0530 Subject: [PATCH] fix(compiler): wrap scoped slots v-if conditions in parens (#9119) fix #9114 --- src/compiler/codegen/index.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/compiler/codegen/index.js b/src/compiler/codegen/index.js index f75d6300f66..d5b0aa09bd0 100644 --- a/src/compiler/codegen/index.js +++ b/src/compiler/codegen/index.js @@ -367,7 +367,7 @@ function genScopedSlot ( const fn = `function(${String(el.slotScope)}){` + `return ${el.tag === 'template' ? el.if - ? `${el.if}?${genChildren(el, state) || 'undefined'}:undefined` + ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined` : genChildren(el, state) || 'undefined' : genElement(el, state) }}` diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js index 0758142ed27..57caa60ada1 100644 --- a/test/unit/modules/compiler/codegen.spec.js +++ b/test/unit/modules/compiler/codegen.spec.js @@ -208,6 +208,17 @@ describe('codegen', () => { ) }) + it('generate scoped slot with multiline v-if', () => { + assertCodegen( + '', + `with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return (\nshow\n)?[_v(_s(bar))]:undefined}}])})}` + ) + assertCodegen( + '
{{ bar }}
', + `with(this){return _c(\'foo\',{scopedSlots:_u([{key:"foo",fn:function(bar){return (\nshow\n)?_c(\'div\',{},[_v(_s(bar))]):_e()}}])})}` + ) + }) + it('generate class binding', () => { // static assertCodegen(