Skip to content

Commit

Permalink
polish: warn against incorrect nested v-slot usage
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 31, 2019
1 parent 2807fd2 commit 3edb999
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,13 @@ function processSlotContent (el) {
el
)
}
if (!maybeComponent(el.parent)) {
warn(
`<template v-slot> can only appear at the root level inside ` +
`the receiving the component`,
el
)
}
}
const { name, dynamic } = getSlotName(slotBinding)
el.slotTarget = name
Expand Down
14 changes: 14 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,20 @@ describe('Component scoped slot', () => {
expect(vm.$el.innerHTML).toBe(`b from foo two `)
}).then(done)
})

it('warn when v-slot used on non-root <template>', () => {
const vm = new Vue({
template: `
<foo>
<template v-if="true">
<template v-slot:one>foo</template>
</template>
</foo>
`,
components: { Foo }
}).$mount()
expect(`<template v-slot> can only appear at the root level`).toHaveBeenWarned()
})
})

// 2.6 scoped slot perf optimization
Expand Down

0 comments on commit 3edb999

Please sign in to comment.