|
|
|
@ -3,7 +3,7 @@ import Attribute from './Attribute';
|
|
|
|
import Component from '../Component';
|
|
|
|
import Component from '../Component';
|
|
|
|
import TemplateScope from './shared/TemplateScope';
|
|
|
|
import TemplateScope from './shared/TemplateScope';
|
|
|
|
import { INode } from './interfaces';
|
|
|
|
import { INode } from './interfaces';
|
|
|
|
import { TemplateNode } from '../../interfaces';
|
|
|
|
import { TemplateNode, Attribute as AttributeNode } from '../../interfaces';
|
|
|
|
import compiler_errors from '../compiler_errors';
|
|
|
|
import compiler_errors from '../compiler_errors';
|
|
|
|
|
|
|
|
|
|
|
|
export default class Slot extends Element {
|
|
|
|
export default class Slot extends Element {
|
|
|
|
@ -11,31 +11,44 @@ export default class Slot extends Element {
|
|
|
|
name: string;
|
|
|
|
name: string;
|
|
|
|
children: INode[];
|
|
|
|
children: INode[];
|
|
|
|
slot_name: string;
|
|
|
|
slot_name: string;
|
|
|
|
|
|
|
|
name_attribute: Attribute;
|
|
|
|
values: Map<string, Attribute> = new Map();
|
|
|
|
values: Map<string, Attribute> = new Map();
|
|
|
|
|
|
|
|
|
|
|
|
constructor(component: Component, parent: INode, scope: TemplateScope, info: TemplateNode) {
|
|
|
|
constructor(component: Component, parent: INode, scope: TemplateScope, info: TemplateNode) {
|
|
|
|
super(component, parent, scope, info);
|
|
|
|
super(component, parent, scope, info);
|
|
|
|
|
|
|
|
|
|
|
|
info.attributes.forEach(attr => {
|
|
|
|
info.attributes.forEach((attr: AttributeNode) => {
|
|
|
|
if (attr.type !== 'Attribute' && attr.type !== 'Spread') {
|
|
|
|
if (attr.type !== 'Attribute' && attr.type !== 'Spread') {
|
|
|
|
return component.error(attr, compiler_errors.invalid_slot_directive);
|
|
|
|
return component.error(attr, compiler_errors.invalid_slot_directive);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const new_attribute = new Attribute(component, this, scope, attr);
|
|
|
|
if (attr.name === 'name') {
|
|
|
|
if (attr.name === 'name') {
|
|
|
|
if (attr.value.length !== 1 || attr.value[0].type !== 'Text') {
|
|
|
|
if (attr.value.length === 1 && attr.value[0].type === 'Text') {
|
|
|
|
return component.error(attr, compiler_errors.dynamic_slot_name);
|
|
|
|
this.slot_name = attr.value[0].data;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.slot_name = component.get_unique_name('dynamic_slot_name').name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.slot_name = attr.value[0].data;
|
|
|
|
|
|
|
|
if (this.slot_name === 'default') {
|
|
|
|
if (this.slot_name === 'default') {
|
|
|
|
return component.error(attr, compiler_errors.invalid_slot_name);
|
|
|
|
return component.error(attr, compiler_errors.invalid_slot_name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.name_attribute = new_attribute;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.values.set(attr.name, new Attribute(component, this, scope, attr));
|
|
|
|
this.values.set(attr.name, new_attribute);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!this.slot_name) this.slot_name = 'default';
|
|
|
|
if (!this.slot_name) {
|
|
|
|
|
|
|
|
// If there is no name attribute, pretend we do have a name attribute with value 'default'
|
|
|
|
|
|
|
|
this.slot_name = 'default';
|
|
|
|
|
|
|
|
this.name_attribute = new Attribute(component, this, scope, {
|
|
|
|
|
|
|
|
type: 'Attribute',
|
|
|
|
|
|
|
|
name: 'name',
|
|
|
|
|
|
|
|
value: [ { type: 'Text', data: 'default' } ]
|
|
|
|
|
|
|
|
} as AttributeNode);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (this.slot_name === 'default') {
|
|
|
|
if (this.slot_name === 'default') {
|
|
|
|
// if this is the default slot, add our dependencies to any
|
|
|
|
// if this is the default slot, add our dependencies to any
|
|
|
|
|