Skip to content

Commit 9fbb592

Browse files
authored
fix: collect of used variables for changed selector (#1217)
1 parent eef05cd commit 9fbb592

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

packages/purgecss/__tests__/css-variables.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ describe("purge unused css variables", () => {
2727
expect(purgedCSS.includes("--color-first:")).toBe(true);
2828
expect(purgedCSS.includes("--wrong-order:")).toBe(true);
2929
});
30+
it("keeps '--outline-color'", () => {
31+
expect(purgedCSS.includes("--outline-color:")).toBe(true);
32+
});
3033
});

packages/purgecss/__tests__/test_examples/css-variables/variables.css

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
--used-color: rebeccapurple;
88
--accent-color: orange;
99
--wrong-order: yellow;
10+
--outline-color: coral;
1011
--random: var(--not-existing);
1112
}
1213

@@ -19,6 +20,10 @@
1920
border-color: var(--border-color);
2021
}
2122

23+
.button, .unused-class {
24+
outline-color: var(--outline-color);
25+
}
26+
2227
.button:focus {
2328
background-color: var(--accent-color);
2429
color: var(--primary-color);

packages/purgecss/src/index.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ class PurgeCSS {
525525
return;
526526
}
527527

528-
let keepSelector = true;
529528
const selectorsRemovedFromRule: string[] = [];
530529

531530
// selector transformer, walk over the list of the parsed selectors twice.
@@ -540,7 +539,7 @@ class PurgeCSS {
540539
return;
541540
}
542541

543-
keepSelector = this.shouldKeepSelector(selector, selectors);
542+
const keepSelector = this.shouldKeepSelector(selector, selectors);
544543

545544
if (!keepSelector) {
546545
if (this.options.rejected) {
@@ -575,7 +574,7 @@ class PurgeCSS {
575574
}).processSync(node.selector);
576575

577576
// declarations
578-
if (keepSelector && typeof node.nodes !== "undefined") {
577+
if (node.selector && typeof node.nodes !== "undefined") {
579578
for (const childNode of node.nodes) {
580579
if (childNode.type !== "decl") continue;
581580
this.collectDeclarationsData(childNode);

0 commit comments

Comments
 (0)