From b2860c789dd78136474700ac17fff993c90da2d8 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 14 Apr 2019 18:06:24 -0400 Subject: [PATCH] disallow duplicate slot="xxx" elements - fixes second half of #2320 --- src/compile/Component.ts | 1 + src/compile/nodes/Element.ts | 9 +++++++++ src/compile/nodes/Slot.ts | 16 ---------------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 41d6c3e3d5..bf2fdf9a5a 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -119,6 +119,7 @@ export default class Component { globally_used_names: Set = new Set(); slots: Map = new Map(); + slot_outlets: Set = new Set(); constructor( ast: Ast, diff --git a/src/compile/nodes/Element.ts b/src/compile/nodes/Element.ts index bc1991c57e..b38ee5b6fb 100644 --- a/src/compile/nodes/Element.ts +++ b/src/compile/nodes/Element.ts @@ -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; diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 396b53ea94..dbb502b41a 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -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}' 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 element` - // }); - // } } } \ No newline at end of file