apply_combinator() — svelte Function Reference
Architecture documentation for the apply_combinator() function in css-prune.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD a482078a_f217_b205_783e_29603b509866["apply_combinator()"] cb1bf043_dade_7352_cc2b_976ffa2968d8["css-prune.js"] a482078a_f217_b205_783e_29603b509866 -->|defined in| cb1bf043_dade_7352_cc2b_976ffa2968d8 c89a58ea_32ad_64b6_f48c_d266ac47f008["apply_selector()"] c89a58ea_32ad_64b6_f48c_d266ac47f008 -->|calls| a482078a_f217_b205_783e_29603b509866 fcd1a34a_dfa8_d0c2_392e_170db534e7f6["get_descendant_elements()"] a482078a_f217_b205_783e_29603b509866 -->|calls| fcd1a34a_dfa8_d0c2_392e_170db534e7f6 87b673b4_96c8_f795_369b_b570e339b73c["get_ancestor_elements()"] a482078a_f217_b205_783e_29603b509866 -->|calls| 87b673b4_96c8_f795_369b_b570e339b73c c89a58ea_32ad_64b6_f48c_d266ac47f008["apply_selector()"] a482078a_f217_b205_783e_29603b509866 -->|calls| c89a58ea_32ad_64b6_f48c_d266ac47f008 1092183f_deda_3e7f_c2d9_d945fa5bbecb["is_global()"] a482078a_f217_b205_783e_29603b509866 -->|calls| 1092183f_deda_3e7f_c2d9_d945fa5bbecb d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb["get_possible_element_siblings()"] a482078a_f217_b205_783e_29603b509866 -->|calls| d5d7e4cd_440a_0f1d_4f04_04a2cabd1beb 12d8f7ff_b44b_af7f_1477_a8dcff95b4fc["get_element_parent()"] a482078a_f217_b205_783e_29603b509866 -->|calls| 12d8f7ff_b44b_af7f_1477_a8dcff95b4fc style a482078a_f217_b205_783e_29603b509866 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js lines 223–285
function apply_combinator(relative_selector, rest_selectors, rule, node, direction) {
const combinator =
direction == FORWARD ? rest_selectors[0]?.combinator : relative_selector.combinator;
if (!combinator) return true;
switch (combinator.name) {
case ' ':
case '>': {
const is_adjacent = combinator.name === '>';
const parents =
direction === FORWARD
? get_descendant_elements(node, is_adjacent)
: get_ancestor_elements(node, is_adjacent);
let parent_matched = false;
for (const parent of parents) {
if (apply_selector(rest_selectors, rule, parent, direction)) {
parent_matched = true;
}
}
return (
parent_matched ||
(direction === BACKWARD &&
(!is_adjacent || parents.length === 0) &&
rest_selectors.every((selector) => is_global(selector, rule)))
);
}
case '+':
case '~': {
const siblings = get_possible_element_siblings(node, direction, combinator.name === '+');
let sibling_matched = false;
for (const possible_sibling of siblings.keys()) {
if (
possible_sibling.type === 'RenderTag' ||
possible_sibling.type === 'SlotElement' ||
possible_sibling.type === 'Component'
) {
// `{@render foo()}<p>foo</p>` with `:global(.x) + p` is a match
if (rest_selectors.length === 1 && rest_selectors[0].metadata.is_global) {
sibling_matched = true;
}
} else if (apply_selector(rest_selectors, rule, possible_sibling, direction)) {
sibling_matched = true;
}
}
return (
sibling_matched ||
(direction === BACKWARD &&
get_element_parent(node) === null &&
rest_selectors.every((selector) => is_global(selector, rule)))
);
}
default:
// TODO other combinators
return true;
}
}
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does apply_combinator() do?
apply_combinator() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js.
Where is apply_combinator() defined?
apply_combinator() is defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js at line 223.
What does apply_combinator() call?
apply_combinator() calls 6 function(s): apply_selector, get_ancestor_elements, get_descendant_elements, get_element_parent, get_possible_element_siblings, is_global.
What calls apply_combinator()?
apply_combinator() is called by 1 function(s): apply_selector.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free