Skip to content

Commit

Permalink
fix(compiler): wrap scoped slots v-if conditions in parens (#9119)
Browse files Browse the repository at this point in the history
fix #9114
  • Loading branch information
subu28 authored and yyx990803 committed Dec 1, 2018
1 parent 0b31647 commit ef8524a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}}`
Expand Down
11 changes: 11 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit ef8524a

Please sign in to comment.