Home / File/ SlotElement.js — svelte Source File

SlotElement.js — svelte Source File

Architecture documentation for SlotElement.js, a javascript file in the svelte codebase. 4 imports, 1 dependents.

File javascript Compiler Transformer 4 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  07769de5_a9cd_3b34_92bc_b16584575cb7["SlotElement.js"]
  74eddc85_a390_2aab_af5a_ef32b77d5430["utils.js"]
  07769de5_a9cd_3b34_92bc_b16584575cb7 --> 74eddc85_a390_2aab_af5a_ef32b77d5430
  9f24c33c_da34_a132_f273_3ffd2f6e5cf8["build_attribute_value"]
  07769de5_a9cd_3b34_92bc_b16584575cb7 --> 9f24c33c_da34_a132_f273_3ffd2f6e5cf8
  89f84d70_5c6c_1980_33f9_650ce42a04ab["PromiseOptimiser"]
  07769de5_a9cd_3b34_92bc_b16584575cb7 --> 89f84d70_5c6c_1980_33f9_650ce42a04ab
  95c28355_f14c_c3cd_5a03_d5a53ca255bc["builders"]
  07769de5_a9cd_3b34_92bc_b16584575cb7 --> 95c28355_f14c_c3cd_5a03_d5a53ca255bc
  86cf8685_38fa_3a1c_9b81_21c452968289["transform-server.js"]
  86cf8685_38fa_3a1c_9b81_21c452968289 --> 07769de5_a9cd_3b34_92bc_b16584575cb7
  style 07769de5_a9cd_3b34_92bc_b16584575cb7 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/** @import { BlockStatement, Expression, Literal, Property } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types.js' */
import * as b from '#compiler/builders';
import {
	build_attribute_value,
	PromiseOptimiser,
	block_open,
	block_close
} from './shared/utils.js';

/**
 * @param {AST.SlotElement} node
 * @param {ComponentContext} context
 */
export function SlotElement(node, context) {
	/** @type {Property[]} */
	const props = [];

	/** @type {Expression[]} */
	const spreads = [];

	const optimiser = new PromiseOptimiser();

	let name = b.literal('default');

	for (const attribute of node.attributes) {
		if (attribute.type === 'SpreadAttribute') {
			let expression = /** @type {Expression} */ (context.visit(attribute));
			spreads.push(optimiser.transform(expression, attribute.metadata.expression));
		} else if (attribute.type === 'Attribute') {
			const value = build_attribute_value(
				attribute.value,
				context,
				optimiser.transform,
				false,
				true
			);

			if (attribute.name === 'name') {
				name = /** @type {Literal} */ (value);
			} else if (attribute.name !== 'slot') {
				props.push(b.init(attribute.name, value));
			}
		}
	}

	const props_expression =
		spreads.length === 0
			? b.object(props)
			: b.call('$.spread_props', b.array([b.object(props), ...spreads]));

	const fallback =
		node.fragment.nodes.length === 0
			? b.null
			: b.thunk(/** @type {BlockStatement} */ (context.visit(node.fragment)));

	const slot = b.call(
		'$.slot',
		b.id('$$renderer'),
		b.id('$$props'),
		name,
		props_expression,
		fallback
	);

	context.state.template.push(block_open, ...optimiser.render_block([b.stmt(slot)]), block_close);
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does SlotElement.js do?
SlotElement.js is a source file in the svelte codebase, written in javascript. It belongs to the Compiler domain, Transformer subdomain.
What functions are defined in SlotElement.js?
SlotElement.js defines 1 function(s): SlotElement.
What does SlotElement.js depend on?
SlotElement.js imports 4 module(s): PromiseOptimiser, build_attribute_value, builders, utils.js.
What files import SlotElement.js?
SlotElement.js is imported by 1 file(s): transform-server.js.
Where is SlotElement.js in the architecture?
SlotElement.js is located at packages/svelte/src/compiler/phases/3-transform/server/visitors/SlotElement.js (domain: Compiler, subdomain: Transformer, directory: packages/svelte/src/compiler/phases/3-transform/server/visitors).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free