Skip to content

Commit ef8524a

Browse files
subu28yyx990803
authored andcommitted
fix(compiler): wrap scoped slots v-if conditions in parens (#9119)
fix #9114
1 parent 0b31647 commit ef8524a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/compiler/codegen/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ function genScopedSlot (
367367
const fn = `function(${String(el.slotScope)}){` +
368368
`return ${el.tag === 'template'
369369
? el.if
370-
? `${el.if}?${genChildren(el, state) || 'undefined'}:undefined`
370+
? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
371371
: genChildren(el, state) || 'undefined'
372372
: genElement(el, state)
373373
}}`

test/unit/modules/compiler/codegen.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,17 @@ describe('codegen', () => {
208208
)
209209
})
210210

211+
it('generate scoped slot with multiline v-if', () => {
212+
assertCodegen(
213+
'<foo><template v-if="\nshow\n" slot-scope="bar">{{ bar }}</template></foo>',
214+
`with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return (\nshow\n)?[_v(_s(bar))]:undefined}}])})}`
215+
)
216+
assertCodegen(
217+
'<foo><div v-if="\nshow\n" slot="foo" slot-scope="bar">{{ bar }}</div></foo>',
218+
`with(this){return _c(\'foo\',{scopedSlots:_u([{key:"foo",fn:function(bar){return (\nshow\n)?_c(\'div\',{},[_v(_s(bar))]):_e()}}])})}`
219+
)
220+
})
221+
211222
it('generate class binding', () => {
212223
// static
213224
assertCodegen(

0 commit comments

Comments
 (0)