Home / Function/ get_possible_element_siblings() — svelte Function Reference

get_possible_element_siblings() — svelte Function Reference

Architecture documentation for the get_possible_element_siblings() function in css-prune.js from the svelte codebase.

Function javascript Compiler Analyzer calls 4 called by 1

Entity Profile

Dependency Diagram

graph TD
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb["get_possible_element_siblings()"]
  cb1bf043_dade_7352_cc2b_976ffa2968d8["css-prune.js"]
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb -->|defined in| cb1bf043_dade_7352_cc2b_976ffa2968d8
  a482078a_f217_b205_783e_29603b509866["apply_combinator()"]
  a482078a_f217_b205_783e_29603b509866 -->|calls| d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb
  5850e1d2_00c3_46f8_65a8_3e14a5008835["is_block()"]
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb -->|calls| 5850e1d2_00c3_46f8_65a8_3e14a5008835
  14568a03_9aaf_6654_12a2_6715c1feb40f["get_possible_nested_siblings()"]
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb -->|calls| 14568a03_9aaf_6654_12a2_6715c1feb40f
  69fc97cc_09aa_8b84_a7ce_425c1db8c339["add_to_map()"]
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb -->|calls| 69fc97cc_09aa_8b84_a7ce_425c1db8c339
  72641a2e_b8fc_984b_8f67_3250d77a3ede["has_definite_elements()"]
  d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb -->|calls| 72641a2e_b8fc_984b_8f67_3250d77a3ede
  style d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js lines 909–1001

function get_possible_element_siblings(node, direction, adjacent_only, seen = new Set()) {
	/** @type {Map<Compiler.AST.RegularElement | Compiler.AST.SvelteElement | Compiler.AST.SlotElement | Compiler.AST.RenderTag | Compiler.AST.Component, NodeExistsValue>} */
	const result = new Map();
	const path = node.metadata.path;

	/** @type {Compiler.AST.SvelteNode} */
	let current = node;

	let i = path.length;

	while (i--) {
		const fragment = /** @type {Compiler.AST.Fragment} */ (path[i--]);
		let j = fragment.nodes.indexOf(current) + (direction === FORWARD ? 1 : -1);

		while (j >= 0 && j < fragment.nodes.length) {
			const node = fragment.nodes[j];

			if (node.type === 'RegularElement') {
				const has_slot_attribute = node.attributes.some(
					(attr) => attr.type === 'Attribute' && attr.name.toLowerCase() === 'slot'
				);

				if (!has_slot_attribute) {
					result.set(node, NODE_DEFINITELY_EXISTS);

					if (adjacent_only) {
						return result;
					}
				}
				// Special case: slots, render tags and svelte:element tags could resolve to no siblings,
				// so we want to continue until we find a definite sibling even with the adjacent-only combinator
			} else if (is_block(node) || node.type === 'Component') {
				if (node.type === 'SlotElement' || node.type === 'Component') {
					result.set(node, NODE_PROBABLY_EXISTS);
				}

				const possible_last_child = get_possible_nested_siblings(node, direction, adjacent_only);
				add_to_map(possible_last_child, result);
				if (
					adjacent_only &&
					node.type !== 'Component' &&
					has_definite_elements(possible_last_child)
				) {
					return result;
				}
			} else if (node.type === 'SvelteElement') {
				result.set(node, NODE_PROBABLY_EXISTS);
			} else if (node.type === 'RenderTag') {
				result.set(node, NODE_PROBABLY_EXISTS);
				for (const snippet of node.metadata.snippets) {
					add_to_map(get_possible_nested_siblings(snippet, direction, adjacent_only), result);
				}
			}

			j = direction === FORWARD ? j + 1 : j - 1;
		}

		current = path[i];

		if (!current) break;

		if (
			current.type === 'Component' ||
			current.type === 'SvelteComponent' ||
			current.type === 'SvelteSelf'
		) {
			continue;
		}

		if (current.type === 'SnippetBlock') {
			if (seen.has(current)) break;
			seen.add(current);

			for (const site of current.metadata.sites) {
				const siblings = get_possible_element_siblings(site, direction, adjacent_only, seen);
				add_to_map(siblings, result);

				if (adjacent_only && current.metadata.sites.size === 1 && has_definite_elements(siblings)) {
					return result;
				}
			}

Domain

Subdomains

Called By

Frequently Asked Questions

What does get_possible_element_siblings() do?
get_possible_element_siblings() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js.
Where is get_possible_element_siblings() defined?
get_possible_element_siblings() is defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js at line 909.
What does get_possible_element_siblings() call?
get_possible_element_siblings() calls 4 function(s): add_to_map, get_possible_nested_siblings, has_definite_elements, is_block.
What calls get_possible_element_siblings()?
get_possible_element_siblings() is called by 1 function(s): apply_combinator.

Analyze Your Own Codebase

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

Try Supermodel Free