Skip to content

Commit 8d84572

Browse files
committed
feat: warning for ambiguous v-slot usage
1 parent 67e85de commit 8d84572

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/compiler/parser/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ function processSlotContent (el) {
627627
el
628628
)
629629
}
630+
if (el.scopedSlots) {
631+
warn(
632+
`To avoid scope ambiguity, the default slot should also use ` +
633+
`<template> syntax when there are other named slots.`,
634+
slotBinding
635+
)
636+
}
630637
}
631638
// add the component's children to its default slot
632639
const slots = el.scopedSlots || (el.scopedSlots = {})

test/unit/features/component/component-scoped-slot.spec.js

+24-5
Original file line numberDiff line numberDiff line change
@@ -686,11 +686,13 @@ describe('Component scoped slot', () => {
686686
expect(vm.$el.innerHTML.trim()).toBe(`from foo default | from bar | from baz`)
687687
})
688688

689-
it('default + named slots', () => {
689+
it('named slots', () => {
690690
const vm = new Vue({
691691
template: `
692-
<foo #default="foo">
693-
{{ foo }}
692+
<foo>
693+
<template ${toNamed(syntax, 'default')}="foo">
694+
{{ foo }}
695+
</template>
694696
<template ${toNamed(syntax, 'one')}="one">
695697
{{ one }}
696698
</template>
@@ -748,8 +750,10 @@ describe('Component scoped slot', () => {
748750
it('shorthand named slots', () => {
749751
const vm = new Vue({
750752
template: `
751-
<foo #default="foo">
752-
{{ foo }}
753+
<foo>
754+
<template #default="foo">
755+
{{ foo }}
756+
</template>
753757
<template #one="one">
754758
{{ one }}
755759
</template>
@@ -763,6 +767,21 @@ describe('Component scoped slot', () => {
763767
expect(vm.$el.innerHTML.replace(/\s+/g, ' ')).toMatch(`from foo default from foo one from foo two`)
764768
})
765769

770+
it('should warn mixed root-default and named slots', () => {
771+
const vm = new Vue({
772+
template: `
773+
<foo #default="foo">
774+
{{ foo }}
775+
<template #one="one">
776+
{{ one }}
777+
</template>
778+
</foo>
779+
`,
780+
components: { Foo }
781+
}).$mount()
782+
expect(`default slot should also use <template>`).toHaveBeenWarned()
783+
})
784+
766785
it('shorthand without scope variable', () => {
767786
const vm = new Vue({
768787
template: `

0 commit comments

Comments
 (0)