|
|
|
|
@ -55,11 +55,9 @@ const nesting_selector = {
|
|
|
|
|
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
|
|
|
|
|
*/
|
|
|
|
|
export function prune(stylesheet, element) {
|
|
|
|
|
walk(stylesheet, { element }, visitors);
|
|
|
|
|
}
|
|
|
|
|
const state = { element };
|
|
|
|
|
|
|
|
|
|
/** @type {Visitors<Compiler.Css.Node, State>} */
|
|
|
|
|
const visitors = {
|
|
|
|
|
walk(/** @type {Compiler.Css.Node} */ (stylesheet), state, {
|
|
|
|
|
Rule(node, context) {
|
|
|
|
|
if (node.metadata.is_global_block) {
|
|
|
|
|
context.visit(node.prelude);
|
|
|
|
|
@ -86,7 +84,8 @@ const visitors = {
|
|
|
|
|
// selectors that don't belong to rules (i.e. inside `:is(...)` etc)
|
|
|
|
|
// when we encounter them below
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves the relative selectors (minus the trailing globals) from a complex selector.
|
|
|
|
|
@ -103,16 +102,12 @@ function get_relative_selectors(node) {
|
|
|
|
|
|
|
|
|
|
// nesting could be inside pseudo classes like :is, :has or :where
|
|
|
|
|
for (let selector of selectors) {
|
|
|
|
|
walk(
|
|
|
|
|
selector,
|
|
|
|
|
{},
|
|
|
|
|
{
|
|
|
|
|
walk(selector, null, {
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
NestingSelector() {
|
|
|
|
|
has_explicit_nesting_selector = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
// if we found one we can break from the others
|
|
|
|
|
if (has_explicit_nesting_selector) break;
|
|
|
|
|
}
|
|
|
|
|
|