Skip to content

Commit 956c635

Browse files
committed
simplify
1 parent d5db56e commit 956c635

File tree

1 file changed

+22
-31
lines changed
  • packages/svelte/src/compiler/phases/3-transform/css

1 file changed

+22
-31
lines changed

packages/svelte/src/compiler/phases/3-transform/css/index.js

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ const visitors = {
126126
return;
127127
}
128128

129-
const used = node.prelude.children.filter((s) => s.metadata.used);
130-
131-
if (used.length === 0) {
129+
if (!node.prelude.children.some((s) => s.metadata.used)) {
132130
state.code.prependRight(node.start, '/* (unused) ');
133131
state.code.appendLeft(node.end, '*/');
134132
escape_comment_close(node, state.code);
@@ -139,45 +137,38 @@ const visitors = {
139137
next();
140138
},
141139
SelectorList(node, { state, next, path }) {
142-
const used = node.children.filter((s) => s.metadata.used);
143-
144-
if (used.length < node.children.length) {
145-
let pruning = false;
146-
let last = node.children[0].start;
140+
let pruning = false;
141+
let last = node.children[0].start;
147142

148-
for (let i = 0; i < node.children.length; i += 1) {
149-
const selector = node.children[i];
143+
for (let i = 0; i < node.children.length; i += 1) {
144+
const selector = node.children[i];
150145

151-
if (selector.metadata.used === pruning) {
152-
if (pruning) {
153-
let i = selector.start;
154-
while (state.code.original[i] !== ',') i--;
146+
if (selector.metadata.used === pruning) {
147+
if (pruning) {
148+
let i = selector.start;
149+
while (state.code.original[i] !== ',') i--;
155150

156-
state.code.overwrite(i, i + 1, '*/');
151+
state.code.overwrite(i, i + 1, '*/');
152+
} else {
153+
if (i === 0) {
154+
state.code.prependRight(selector.start, '/* (unused) ');
157155
} else {
158-
if (i === 0) {
159-
state.code.prependRight(selector.start, '/* (unused) ');
160-
} else {
161-
state.code.overwrite(last, selector.start, ' /* (unused) ');
162-
}
156+
state.code.overwrite(last, selector.start, ' /* (unused) ');
163157
}
164-
165-
pruning = !pruning;
166158
}
167159

168-
last = selector.end;
160+
pruning = !pruning;
169161
}
170162

171-
if (pruning) {
172-
state.code.appendLeft(last, '*/');
173-
}
163+
last = selector.end;
164+
}
165+
166+
if (pruning) {
167+
state.code.appendLeft(last, '*/');
174168
}
175169

176-
const parent = /** @type {import('#compiler').Css.Node} */ (path.at(-1));
177-
next({
178-
...state,
179-
specificity: parent.type === 'Rule' ? { bumped: false } : state.specificity
180-
});
170+
const specificity = path.at(-1)?.type === 'Rule' ? { bumped: false } : state.specificity;
171+
next({ ...state, specificity });
181172
},
182173
ComplexSelector(node, context) {
183174
/** @param {import('#compiler').Css.SimpleSelector} selector */

0 commit comments

Comments
 (0)