diff --git a/src/compile/nodes/Slot.ts b/src/compile/nodes/Slot.ts index 31026e302a..1540fa6271 100644 --- a/src/compile/nodes/Slot.ts +++ b/src/compile/nodes/Slot.ts @@ -5,6 +5,7 @@ import Attribute from './Attribute'; export default class Slot extends Element { type: 'Element'; name: string; + slot_name: string; attributes: Attribute[]; children: Node[]; @@ -27,8 +28,8 @@ export default class Slot extends Element { }); } - const slot_name = attr.value[0].data; - if (slot_name === 'default') { + this.slot_name = attr.value[0].data; + if (this.slot_name === 'default') { component.error(attr, { code: `invalid-slot-name`, message: `default is a reserved word — it cannot be used as a slot name` @@ -46,6 +47,8 @@ export default class Slot extends Element { // validator.slots.add(slot_name); }); + if (!this.slot_name) this.slot_name = 'default'; + // if (node.attributes.length === 0) && validator.slots.has('default')) { // validator.error(node, { // code: `duplicate-slot`, diff --git a/src/compile/render-dom/wrappers/Element/index.ts b/src/compile/render-dom/wrappers/Element/index.ts index 32c8063f05..fa025bacbe 100644 --- a/src/compile/render-dom/wrappers/Element/index.ts +++ b/src/compile/render-dom/wrappers/Element/index.ts @@ -20,6 +20,7 @@ import add_event_handlers from '../shared/add_event_handlers'; import add_actions from '../shared/add_actions'; import create_debugging_comment from '../shared/create_debugging_comment'; import { get_context_merger } from '../shared/get_context_merger'; +import Slot from '../../../nodes/Slot'; const events = [ { @@ -213,8 +214,7 @@ export default class ElementWrapper extends Wrapper { const { renderer } = this; if (this.node.name === 'slot') { - const slot_name = this.node.get_static_attribute_value('name') || 'default'; - renderer.slots.add(slot_name); + renderer.slots.add((this.node as Slot).slot_name); } if (this.node.name === 'noscript') return; diff --git a/src/compile/render-dom/wrappers/Slot.ts b/src/compile/render-dom/wrappers/Slot.ts index 3760e73ce0..0374587c24 100644 --- a/src/compile/render-dom/wrappers/Slot.ts +++ b/src/compile/render-dom/wrappers/Slot.ts @@ -55,7 +55,7 @@ export default class SlotWrapper extends Wrapper { ) { const { renderer } = this; - const slot_name = this.node.get_static_attribute_value('name') || 'default'; + const { slot_name } = this.node; renderer.slots.add(slot_name); let get_slot_changes; diff --git a/src/compile/render-ssr/handlers/Slot.ts b/src/compile/render-ssr/handlers/Slot.ts index 51e37ab9cf..77273e8009 100644 --- a/src/compile/render-ssr/handlers/Slot.ts +++ b/src/compile/render-ssr/handlers/Slot.ts @@ -2,10 +2,7 @@ import { quote_prop_if_necessary } from '../../../utils/names'; import get_slot_data from '../../utils/get_slot_data'; export default function(node, renderer, options) { - const name = node.attributes.find(attribute => attribute.name === 'name'); - - const slot_name = name && name.chunks[0].data || 'default'; - const prop = quote_prop_if_necessary(slot_name); + const prop = quote_prop_if_necessary(node.slot_name); const slot_data = get_slot_data(node.attributes, true);