Skip to content

Commit

Permalink
fix(postcss-discard-empty): preserve empty layer declarations
Browse files Browse the repository at this point in the history
Fix #1544
  • Loading branch information
ludofischer committed Feb 22, 2024
1 parent 52d14d8 commit 4bf74ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/neat-houses-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"postcss-discard-empty": patch
---

fix(postcss-discard-empty): preserve empty layer declarations
2 changes: 1 addition & 1 deletion packages/postcss-discard-empty/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function discardAndReport(css, result) {
if (
(type === 'decl' && !node.value && !node.prop.startsWith('--')) ||
(type === 'rule' && !node.selector) ||
(sub && !sub.length) ||
(sub && !sub.length && !(type === 'atrule' && node.name === 'layer')) ||
(type === 'atrule' &&
((!sub && !node.params) ||
(!node.params &&
Expand Down
18 changes: 18 additions & 0 deletions packages/postcss-discard-empty/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ test(
passthroughCSS('*{--tw-shadow:; --something-else: ;}')
);

test(
'should preserve empty layers',
passthroughCSS(`@layer a {}
@layer b {}
@layer b {
foo {
color: red;
}
}
@layer a {
bar {
color: green;
}
}`)
);

test(
'should report removed selectors',
testRemovals('h1{}.hot{}.a.b{}{}@media screen, print{h1,h2{}}', '', [
Expand Down

0 comments on commit 4bf74ef

Please sign in to comment.