Lint and format src/compiler/compile/render_dom/wrappers/SlotTemplate.js

pull/8569/head
Simon Holthausen 3 years ago
parent 61d9a3cc5b
commit a0c7d25cf1

@ -9,71 +9,72 @@ import { add_const_tags, add_const_tags_context } from './shared/add_const_tags.
/** @extends Wrapper */ /** @extends Wrapper */
export default class SlotTemplateWrapper extends Wrapper { export default class SlotTemplateWrapper extends Wrapper {
/** @type {import('../../nodes/SlotTemplate.js').default} */
node;
/** @type {import('../../nodes/SlotTemplate.js').default} */ /** @type {import('./Fragment.js').default} */
node; fragment;
/** @type {import('./Fragment.js').default} */ /** @type {import('../Block.js').default} */
fragment; block;
/** @type {import('../Block.js').default} */ /** @type {import('./InlineComponent.js').default} */
block; parent;
/** @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('../Renderer.js').default} renderer * @param {import('../../nodes/SlotTemplate.js').default} node
* @param {import('../Block.js').default} block * @param {boolean} strip_whitespace
* @param {import('./shared/Wrapper.js').default} parent * @param {import('./shared/Wrapper.js').default} next_sibling
* @param {import('../../nodes/SlotTemplate.js').default} node */
* @param {boolean} strip_whitespace constructor(renderer, block, parent, node, strip_whitespace, next_sibling) {
* @param {import('./shared/Wrapper.js').default} next_sibling super(renderer, block, parent, node);
*/ const { scope, lets, const_tags, slot_template_name } = this.node;
constructor(renderer, block, parent, node, strip_whitespace, next_sibling) { lets.forEach((l) => {
super(renderer, block, parent, node); extract_names(l.value || l.name).forEach((name) => {
const { scope, lets, const_tags, slot_template_name } = this.node; renderer.add_to_context(name, true);
lets.forEach((l) => { });
extract_names(l.value || l.name).forEach((name) => { });
renderer.add_to_context(name, true); add_const_tags_context(renderer, const_tags);
}); this.block = block.child({
}); comment: create_debugging_comment(this.node, this.renderer.component),
add_const_tags_context(renderer, const_tags); name: this.renderer.component.get_unique_name(`create_${sanitize(slot_template_name)}_slot`),
this.block = block.child({ type: 'slot'
comment: create_debugging_comment(this.node, this.renderer.component), });
name: this.renderer.component.get_unique_name(`create_${sanitize(slot_template_name)}_slot`), this.renderer.blocks.push(this.block);
type: 'slot' const seen = new Set(lets.map((l) => l.name.name));
}); this.parent.node.lets.forEach((l) => {
this.renderer.blocks.push(this.block); if (!seen.has(l.name.name)) lets.push(l);
const seen = new Set(lets.map((l) => l.name.name)); });
this.parent.node.lets.forEach((l) => { this.parent.set_slot(slot_template_name, get_slot_definition(this.block, scope, lets));
if (!seen.has(l.name.name)) this.fragment = new FragmentWrapper(
lets.push(l); renderer,
}); this.block,
this.parent.set_slot(slot_template_name, get_slot_definition(this.block, scope, lets)); node.type === 'SlotTemplate' ? node.children : [node],
this.fragment = new FragmentWrapper(renderer, this.block, node.type === 'SlotTemplate' ? node.children : [node], this, strip_whitespace, next_sibling); this,
this.block.parent.add_dependencies(this.block.dependencies); strip_whitespace,
} next_sibling
render() { );
this.fragment.render(this.block, null, /** @type {import('estree').Identifier} */ (x `#nodes`)); this.block.parent.add_dependencies(this.block.dependencies);
if (this.node.const_tags.length > 0) { }
this.render_get_context(); render() {
} this.fragment.render(this.block, null, /** @type {import('estree').Identifier} */ (x`#nodes`));
} if (this.node.const_tags.length > 0) {
render_get_context() { this.render_get_context();
const get_context = this.block.renderer.component.get_unique_name('get_context'); }
this.block.renderer.blocks.push(b ` }
render_get_context() {
const get_context = this.block.renderer.component.get_unique_name('get_context');
this.block.renderer.blocks.push(b`
function ${get_context}(#ctx) { function ${get_context}(#ctx) {
${add_const_tags(this.block, this.node.const_tags, '#ctx')} ${add_const_tags(this.block, this.node.const_tags, '#ctx')}
} }
`); `);
this.block.chunks.declarations.push(b `${get_context}(#ctx)`); this.block.chunks.declarations.push(b`${get_context}(#ctx)`);
if (this.block.has_update_method) { if (this.block.has_update_method) {
this.block.chunks.update.unshift(b `${get_context}(#ctx)`); this.block.chunks.update.unshift(b`${get_context}(#ctx)`);
} }
} }
} }

Loading…
Cancel
Save