Pārlūkot izejas kodu

fix(compiler): wrap scoped slots v-if conditions in parens (#9119)

fix #9114
Subhash 7 gadi atpakaļ
vecāks
revīzija
ef8524ab7d

+ 1 - 1
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)
     }}`

+ 11 - 0
test/unit/modules/compiler/codegen.spec.js

@@ -208,6 +208,17 @@ describe('codegen', () => {
     )
   })
 
+  it('generate scoped slot with multiline v-if', () => {
+    assertCodegen(
+      '<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar }}</template></foo>',
+      `with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return (\nshow\n)?[_v(_s(bar))]:undefined}}])})}`
+    )
+    assertCodegen(
+      '<foo><div v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
+      `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(