mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 01:11:24 +01:00
disallow duplicate slot="xxx" elements - fixes second half of #2320
This commit is contained in:
parent
1c5c688dc5
commit
b2860c789d
@ -119,6 +119,7 @@ export default class Component {
|
||||
globally_used_names: Set<string> = new Set();
|
||||
|
||||
slots: Map<string, Slot> = new Map();
|
||||
slot_outlets: Set<string> = new Set();
|
||||
|
||||
constructor(
|
||||
ast: Ast,
|
||||
|
@ -361,6 +361,15 @@ export default class Element extends Node {
|
||||
});
|
||||
}
|
||||
|
||||
if (component.slot_outlets.has(name)) {
|
||||
component.error(attribute, {
|
||||
code: `duplicate-slot-attribute`,
|
||||
message: `Duplicate '${name}' slot`
|
||||
});
|
||||
|
||||
component.slot_outlets.add(name);
|
||||
}
|
||||
|
||||
let ancestor = this.parent;
|
||||
do {
|
||||
if (ancestor.type === 'InlineComponent') break;
|
||||
|
@ -40,15 +40,6 @@ export default class Slot extends Element {
|
||||
}
|
||||
|
||||
this.values.set(attr.name, new Attribute(component, this, scope, attr));
|
||||
|
||||
// TODO should duplicate slots be disallowed? Feels like it's more likely to be a
|
||||
// bug than anything. Perhaps it should be a warning
|
||||
|
||||
// if (validator.slots.has(slot_name)) {
|
||||
// validator.error(`duplicate '${slot_name}' <slot> element`, nameAttribute.start);
|
||||
// }
|
||||
|
||||
// validator.slots.add(slot_name);
|
||||
});
|
||||
|
||||
if (!this.slot_name) this.slot_name = 'default';
|
||||
@ -76,12 +67,5 @@ export default class Slot extends Element {
|
||||
}
|
||||
|
||||
component.slots.set(this.slot_name, this);
|
||||
|
||||
// if (node.attributes.length === 0) && validator.slots.has('default')) {
|
||||
// validator.error(node, {
|
||||
// code: `duplicate-slot`,
|
||||
// message: `duplicate default <slot> element`
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user