relative_selector_might_apply_to_node() — svelte Function Reference
Architecture documentation for the relative_selector_might_apply_to_node() function in css-prune.js from the svelte codebase.
Entity Profile
Dependency Diagram
graph TD 44fb7f7e_7a78_eedb_fde3_53e386135788["relative_selector_might_apply_to_node()"] cb1bf043_dade_7352_cc2b_976ffa2968d8["css-prune.js"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|defined in| cb1bf043_dade_7352_cc2b_976ffa2968d8 c89a58ea_32ad_64b6_f48c_d266ac47f008["apply_selector()"] c89a58ea_32ad_64b6_f48c_d266ac47f008 -->|calls| 44fb7f7e_7a78_eedb_fde3_53e386135788 a430a35e_5924_1332_76a5_38935337865e["get_parent_rules()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| a430a35e_5924_1332_76a5_38935337865e 1092183f_deda_3e7f_c2d9_d945fa5bbecb["is_global()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| 1092183f_deda_3e7f_c2d9_d945fa5bbecb a446abce_d160_6f0a_0d38_aca50a65af3e["truncate()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| a446abce_d160_6f0a_0d38_aca50a65af3e c89a58ea_32ad_64b6_f48c_d266ac47f008["apply_selector()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| c89a58ea_32ad_64b6_f48c_d266ac47f008 12d8f7ff_b44b_af7f_1477_a8dcff95b4fc["get_element_parent()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| 12d8f7ff_b44b_af7f_1477_a8dcff95b4fc 553f3c22_7366_321b_ab4f_fcd972b6b687["attribute_matches()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| 553f3c22_7366_321b_ab4f_fcd972b6b687 b5bb08b1_07de_d3d7_61e5_14a1c9b2ee46["unquote()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| b5bb08b1_07de_d3d7_61e5_14a1c9b2ee46 93e4e2a8_d367_c800_840d_5097d02af978["get_relative_selectors()"] 44fb7f7e_7a78_eedb_fde3_53e386135788 -->|calls| 93e4e2a8_d367_c800_840d_5097d02af978 style 44fb7f7e_7a78_eedb_fde3_53e386135788 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js lines 348–588
function relative_selector_might_apply_to_node(relative_selector, rule, element, direction) {
// Sort :has(...) selectors in one bucket and everything else into another
const has_selectors = [];
const other_selectors = [];
for (const selector of relative_selector.selectors) {
if (selector.type === 'PseudoClassSelector' && selector.name === 'has' && selector.args) {
has_selectors.push(selector);
} else {
other_selectors.push(selector);
}
}
// If we're called recursively from a :has(...) selector, we're on the way of checking if the other selectors match.
// In that case ignore this check (because we just came from this) to avoid an infinite loop.
if (has_selectors.length > 0) {
// If this is a :has inside a global selector, we gotta include the element itself, too,
// because the global selector might be for an element that's outside the component,
// e.g. :root:has(.scoped), :global(.foo):has(.scoped), or :root { &:has(.scoped) {} }
const rules = get_parent_rules(rule);
const include_self =
rules.some((r) => r.prelude.children.some((c) => c.children.some((s) => is_global(s, r)))) ||
rules[rules.length - 1].prelude.children.some((c) =>
c.children.some((r) =>
r.selectors.some(
(s) =>
s.type === 'PseudoClassSelector' &&
(s.name === 'root' || (s.name === 'global' && s.args))
)
)
);
// :has(...) is special in that it means "look downwards in the CSS tree". Since our matching algorithm goes
// upwards and back-to-front, we need to first check the selectors inside :has(...), then check the rest of the
// selector in a way that is similar to ancestor matching. In a sense, we're treating `.x:has(.y)` as `.x .y`.
for (const has_selector of has_selectors) {
const complex_selectors = /** @type {Compiler.AST.CSS.SelectorList} */ (has_selector.args)
.children;
let matched = false;
for (const complex_selector of complex_selectors) {
const [first, ...rest] = truncate(complex_selector);
// if it was just a :global(...)
if (!first) {
complex_selector.metadata.used = true;
matched = true;
continue;
}
if (include_self) {
const selector_including_self = [
first.combinator ? { ...first, combinator: null } : first,
...rest
];
if (apply_selector(selector_including_self, rule, element, FORWARD)) {
complex_selector.metadata.used = true;
matched = true;
}
}
const selector_excluding_self = [
any_selector,
first.combinator ? first : { ...first, combinator: descendant_combinator },
...rest
];
if (apply_selector(selector_excluding_self, rule, element, FORWARD)) {
complex_selector.metadata.used = true;
matched = true;
}
}
if (!matched) {
return false;
}
}
}
for (const selector of other_selectors) {
if (selector.type === 'Percentage' || selector.type === 'Nth') continue;
const name = selector.name.replace(regex_backslash_and_following_character, '$1');
Domain
Subdomains
Calls
Called By
Source
Frequently Asked Questions
What does relative_selector_might_apply_to_node() do?
relative_selector_might_apply_to_node() is a function in the svelte codebase, defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js.
Where is relative_selector_might_apply_to_node() defined?
relative_selector_might_apply_to_node() is defined in packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js at line 348.
What does relative_selector_might_apply_to_node() call?
relative_selector_might_apply_to_node() calls 8 function(s): apply_selector, attribute_matches, get_element_parent, get_parent_rules, get_relative_selectors, is_global, truncate, unquote.
What calls relative_selector_might_apply_to_node()?
relative_selector_might_apply_to_node() 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