Skip to content

Commit 3edb999

Browse files
committed
polish: warn against incorrect nested v-slot usage
1 parent 2807fd2 commit 3edb999

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Diff for: src/compiler/parser/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ function processSlotContent (el) {
642642
el
643643
)
644644
}
645+
if (!maybeComponent(el.parent)) {
646+
warn(
647+
`<template v-slot> can only appear at the root level inside ` +
648+
`the receiving the component`,
649+
el
650+
)
651+
}
645652
}
646653
const { name, dynamic } = getSlotName(slotBinding)
647654
el.slotTarget = name

Diff for: test/unit/features/component/component-scoped-slot.spec.js

+14
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,20 @@ describe('Component scoped slot', () => {
845845
expect(vm.$el.innerHTML).toBe(`b from foo two `)
846846
}).then(done)
847847
})
848+
849+
it('warn when v-slot used on non-root <template>', () => {
850+
const vm = new Vue({
851+
template: `
852+
<foo>
853+
<template v-if="true">
854+
<template v-slot:one>foo</template>
855+
</template>
856+
</foo>
857+
`,
858+
components: { Foo }
859+
}).$mount()
860+
expect(`<template v-slot> can only appear at the root level`).toHaveBeenWarned()
861+
})
848862
})
849863

850864
// 2.6 scoped slot perf optimization

0 commit comments

Comments
 (0)