|
|
|
@ -1,72 +1,61 @@
|
|
|
|
import Wrapper from './shared/Wrapper';
|
|
|
|
import Wrapper from './shared/Wrapper.js';
|
|
|
|
import Renderer from '../Renderer';
|
|
|
|
import FragmentWrapper from './Fragment.js';
|
|
|
|
import Block from '../Block';
|
|
|
|
import create_debugging_comment from './shared/create_debugging_comment.js';
|
|
|
|
import FragmentWrapper from './Fragment';
|
|
|
|
import { get_slot_definition } from './shared/get_slot_definition.js';
|
|
|
|
import create_debugging_comment from './shared/create_debugging_comment';
|
|
|
|
|
|
|
|
import { get_slot_definition } from './shared/get_slot_definition';
|
|
|
|
|
|
|
|
import { b, x } from 'code-red';
|
|
|
|
import { b, x } from 'code-red';
|
|
|
|
import { sanitize } from '../../../utils/names';
|
|
|
|
import { sanitize } from '../../../utils/names.js';
|
|
|
|
import { Identifier } from 'estree';
|
|
|
|
|
|
|
|
import InlineComponentWrapper from './InlineComponent';
|
|
|
|
|
|
|
|
import { extract_names } from 'periscopic';
|
|
|
|
import { extract_names } from 'periscopic';
|
|
|
|
import SlotTemplate from '../../nodes/SlotTemplate';
|
|
|
|
import { add_const_tags, add_const_tags_context } from './shared/add_const_tags.js';
|
|
|
|
import { add_const_tags, add_const_tags_context } from './shared/add_const_tags';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @extends Wrapper */
|
|
|
|
export default class SlotTemplateWrapper extends Wrapper {
|
|
|
|
export default class SlotTemplateWrapper extends Wrapper {
|
|
|
|
node: SlotTemplate;
|
|
|
|
|
|
|
|
fragment: FragmentWrapper;
|
|
|
|
|
|
|
|
block: Block;
|
|
|
|
|
|
|
|
parent: InlineComponentWrapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
/** @type {import('../../nodes/SlotTemplate.js').default} */
|
|
|
|
renderer: Renderer,
|
|
|
|
node;
|
|
|
|
block: Block,
|
|
|
|
|
|
|
|
parent: Wrapper,
|
|
|
|
|
|
|
|
node: SlotTemplate,
|
|
|
|
|
|
|
|
strip_whitespace: boolean,
|
|
|
|
|
|
|
|
next_sibling: Wrapper
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
super(renderer, block, parent, node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { scope, lets, const_tags, slot_template_name } = this.node;
|
|
|
|
/** @type {import('./Fragment.js').default} */
|
|
|
|
|
|
|
|
fragment;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('../Block.js').default} */
|
|
|
|
|
|
|
|
block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @type {import('./InlineComponent.js').default} */
|
|
|
|
|
|
|
|
parent;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {import('../Renderer.js').default} renderer
|
|
|
|
|
|
|
|
* @param {import('../Block.js').default} block
|
|
|
|
|
|
|
|
* @param {import('./shared/Wrapper.js').default} parent
|
|
|
|
|
|
|
|
* @param {import('../../nodes/SlotTemplate.js').default} node
|
|
|
|
|
|
|
|
* @param {boolean} strip_whitespace
|
|
|
|
|
|
|
|
* @param {import('./shared/Wrapper.js').default} next_sibling
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
|
|
|
|
|
|
|
|
super(renderer, block, parent, node);
|
|
|
|
|
|
|
|
const { scope, lets, const_tags, slot_template_name } = this.node;
|
|
|
|
lets.forEach((l) => {
|
|
|
|
lets.forEach((l) => {
|
|
|
|
extract_names(l.value || l.name).forEach((name) => {
|
|
|
|
extract_names(l.value || l.name).forEach((name) => {
|
|
|
|
renderer.add_to_context(name, true);
|
|
|
|
renderer.add_to_context(name, true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
add_const_tags_context(renderer, const_tags);
|
|
|
|
add_const_tags_context(renderer, const_tags);
|
|
|
|
|
|
|
|
|
|
|
|
this.block = block.child({
|
|
|
|
this.block = block.child({
|
|
|
|
comment: create_debugging_comment(this.node, this.renderer.component),
|
|
|
|
comment: create_debugging_comment(this.node, this.renderer.component),
|
|
|
|
name: this.renderer.component.get_unique_name(`create_${sanitize(slot_template_name)}_slot`),
|
|
|
|
name: this.renderer.component.get_unique_name(`create_${sanitize(slot_template_name)}_slot`),
|
|
|
|
type: 'slot'
|
|
|
|
type: 'slot'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.renderer.blocks.push(this.block);
|
|
|
|
this.renderer.blocks.push(this.block);
|
|
|
|
|
|
|
|
|
|
|
|
const seen = new Set(lets.map((l) => l.name.name));
|
|
|
|
const seen = new Set(lets.map((l) => l.name.name));
|
|
|
|
this.parent.node.lets.forEach((l) => {
|
|
|
|
this.parent.node.lets.forEach((l) => {
|
|
|
|
if (!seen.has(l.name.name)) lets.push(l);
|
|
|
|
if (!seen.has(l.name.name))
|
|
|
|
|
|
|
|
lets.push(l);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.parent.set_slot(slot_template_name, get_slot_definition(this.block, scope, lets));
|
|
|
|
this.parent.set_slot(slot_template_name, get_slot_definition(this.block, scope, lets));
|
|
|
|
|
|
|
|
this.fragment = new FragmentWrapper(renderer, this.block, node.type === 'SlotTemplate' ? node.children : [node], this, strip_whitespace, next_sibling);
|
|
|
|
this.fragment = new FragmentWrapper(
|
|
|
|
|
|
|
|
renderer,
|
|
|
|
|
|
|
|
this.block,
|
|
|
|
|
|
|
|
node.type === 'SlotTemplate' ? node.children : [node],
|
|
|
|
|
|
|
|
this,
|
|
|
|
|
|
|
|
strip_whitespace,
|
|
|
|
|
|
|
|
next_sibling
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.block.parent.add_dependencies(this.block.dependencies);
|
|
|
|
this.block.parent.add_dependencies(this.block.dependencies);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
|
this.fragment.render(this.block, null, x`#nodes` as Identifier);
|
|
|
|
this.fragment.render(this.block, null, /** @type {import('estree').Identifier} */ (x `#nodes`));
|
|
|
|
|
|
|
|
|
|
|
|
if (this.node.const_tags.length > 0) {
|
|
|
|
if (this.node.const_tags.length > 0) {
|
|
|
|
this.render_get_context();
|
|
|
|
this.render_get_context();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -84,3 +73,7 @@ export default class SlotTemplateWrapper extends Wrapper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|