SlotElement() — svelte Function Reference
Architecture documentation for the SlotElement() function in SlotElement.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD a56e6575_408a_3fdf_8d40_43c862426641["SlotElement()"] 06302d5e_b0f5_f57d_20cf_13efce492ae0["SlotElement.js"] a56e6575_408a_3fdf_8d40_43c862426641 -->|defined in| 06302d5e_b0f5_f57d_20cf_13efce492ae0 e31bc2c2_91c1_b9a9_f78a_2832bddce6c5["build_attribute_value()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| e31bc2c2_91c1_b9a9_f78a_2832bddce6c5 5ff7d39f_78e8_c057_8c8e_279f6e72149e["add()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| 5ff7d39f_78e8_c057_8c8e_279f6e72149e 10046df1_7862_0e3a_2d28_14faf64ff123["apply()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| 10046df1_7862_0e3a_2d28_14faf64ff123 c2ad0578_181a_4701_2788_ba3b9ab69623["deriveds()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| c2ad0578_181a_4701_2788_ba3b9ab69623 3c8a9b45_1c84_b995_7438_57a8885c67ba["async_values()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| 3c8a9b45_1c84_b995_7438_57a8885c67ba c8d80c9d_ab6c_13c0_c85e_a9b120f82f45["blockers()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| c8d80c9d_ab6c_13c0_c85e_a9b120f82f45 0ded3b0c_d77a_8cc1_be19_72a1a33537da["async_ids()"] a56e6575_408a_3fdf_8d40_43c862426641 -->|calls| 0ded3b0c_d77a_8cc1_be19_72a1a33537da style a56e6575_408a_3fdf_8d40_43c862426641 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/3-transform/client/visitors/SlotElement.js lines 12–94
export function SlotElement(node, context) {
// <slot {a}>fallback</slot> --> $.slot($$slots.default, { get a() { .. } }, () => ...fallback);
context.state.template.push_comment();
/** @type {Property[]} */
const props = [];
/** @type {Expression[]} */
const spreads = [];
/** @type {ExpressionStatement[]} */
const lets = [];
const memoizer = new Memoizer();
let name = b.literal('default');
for (const attribute of node.attributes) {
if (attribute.type === 'SpreadAttribute') {
spreads.push(b.thunk(/** @type {Expression} */ (context.visit(attribute))));
} else if (attribute.type === 'Attribute') {
const { value, has_state } = build_attribute_value(
attribute.value,
context,
(value, metadata) =>
metadata.has_call || metadata.has_await
? b.call('$.get', memoizer.add(value, metadata))
: value
);
if (attribute.name === 'name') {
name = /** @type {Literal} */ (value);
} else if (attribute.name !== 'slot') {
if (has_state) {
props.push(b.get(attribute.name, [b.return(value)]));
} else {
props.push(b.init(attribute.name, value));
}
}
} else if (attribute.type === 'LetDirective') {
context.visit(attribute, { ...context.state, let_directives: lets });
}
}
memoizer.apply();
// Let bindings first, they can be used on attributes
context.state.init.push(...lets);
/** @type {Statement[]} */
const statements = memoizer.deriveds(context.state.analysis.runes);
const props_expression =
spreads.length === 0 ? b.object(props) : b.call('$.spread_props', b.object(props), ...spreads);
const fallback =
node.fragment.nodes.length === 0
? b.null
: b.arrow([b.id('$$anchor')], /** @type {BlockStatement} */ (context.visit(node.fragment)));
statements.push(
b.stmt(b.call('$.slot', context.state.node, b.id('$$props'), name, props_expression, fallback))
);
const async_values = memoizer.async_values();
const blockers = memoizer.blockers();
if (async_values || blockers) {
context.state.init.push(
b.stmt(
b.call(
'$.async',
context.state.node,
blockers,
async_values,
b.arrow([context.state.node, ...memoizer.async_ids()], b.block(statements))
)
)
);
} else {
context.state.init.push(statements.length === 1 ? statements[0] : b.block(statements));
Domain
Subdomains
Source
Frequently Asked Questions
What does SlotElement() do?
SlotElement() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/SlotElement.js.
Where is SlotElement() defined?
SlotElement() is defined in packages/svelte/src/compiler/phases/3-transform/client/visitors/SlotElement.js at line 12.
What does SlotElement() call?
SlotElement() calls 7 function(s): add, apply, async_ids, async_values, blockers, build_attribute_value, deriveds.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free