simplify some slot_name stuff

pull/2317/head
Rich Harris 6 years ago
parent af6f73c486
commit b8bc1224bd

@ -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`,

@ -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;

@ -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;

@ -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);

Loading…
Cancel
Save