Skip to content

Commit af7ebb0

Browse files
committed
tidy up
1 parent bc46771 commit af7ebb0

File tree

1 file changed

+34
-39
lines changed
  • packages/svelte/src/compiler/phases/2-analyze/css

1 file changed

+34
-39
lines changed

packages/svelte/src/compiler/phases/2-analyze/css/css-prune.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,37 @@ const nesting_selector = {
5555
* @param {Compiler.AST.RegularElement | Compiler.AST.SvelteElement} element
5656
*/
5757
export function prune(stylesheet, element) {
58-
walk(stylesheet, { element }, visitors);
59-
}
58+
const state = { element };
59+
60+
walk(/** @type {Compiler.Css.Node} */ (stylesheet), state, {
61+
Rule(node, context) {
62+
if (node.metadata.is_global_block) {
63+
context.visit(node.prelude);
64+
} else {
65+
context.next();
66+
}
67+
},
68+
ComplexSelector(node, context) {
69+
const selectors = get_relative_selectors(node);
70+
71+
if (
72+
apply_selector(
73+
selectors,
74+
/** @type {Compiler.Css.Rule} */ (node.metadata.rule),
75+
context.state.element,
76+
context.state
77+
)
78+
) {
79+
mark(selectors[selectors.length - 1], context.state.element);
80+
node.metadata.used = true;
81+
}
6082

61-
/** @type {Visitors<Compiler.Css.Node, State>} */
62-
const visitors = {
63-
Rule(node, context) {
64-
if (node.metadata.is_global_block) {
65-
context.visit(node.prelude);
66-
} else {
67-
context.next();
68-
}
69-
},
70-
ComplexSelector(node, context) {
71-
const selectors = get_relative_selectors(node);
72-
73-
if (
74-
apply_selector(
75-
selectors,
76-
/** @type {Compiler.Css.Rule} */ (node.metadata.rule),
77-
context.state.element,
78-
context.state
79-
)
80-
) {
81-
mark(selectors[selectors.length - 1], context.state.element);
82-
node.metadata.used = true;
83+
// note: we don't call context.next() here, we only recurse into
84+
// selectors that don't belong to rules (i.e. inside `:is(...)` etc)
85+
// when we encounter them below
8386
}
84-
85-
// note: we don't call context.next() here, we only recurse into
86-
// selectors that don't belong to rules (i.e. inside `:is(...)` etc)
87-
// when we encounter them below
88-
}
89-
};
87+
});
88+
}
9089

9190
/**
9291
* Retrieves the relative selectors (minus the trailing globals) from a complex selector.
@@ -103,16 +102,12 @@ function get_relative_selectors(node) {
103102

104103
// nesting could be inside pseudo classes like :is, :has or :where
105104
for (let selector of selectors) {
106-
walk(
107-
selector,
108-
{},
109-
{
110-
// @ts-ignore
111-
NestingSelector() {
112-
has_explicit_nesting_selector = true;
113-
}
105+
walk(selector, null, {
106+
// @ts-ignore
107+
NestingSelector() {
108+
has_explicit_nesting_selector = true;
114109
}
115-
);
110+
});
116111
// if we found one we can break from the others
117112
if (has_explicit_nesting_selector) break;
118113
}

0 commit comments

Comments
 (0)