Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Commit 14fce9c

Browse files
committed
squash adjacent css nodes with the same selector
1 parent 77bf869 commit 14fce9c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/index.test.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
}
1212
.apply-test {
1313
margin-top: 1.5rem;
14-
}
15-
.apply-test {
1614
--tw-bg-opacity: 1;
1715
background-color: rgba(236, 72, 153, var(--tw-bg-opacity));
1816
}
@@ -105,14 +103,10 @@
105103
}
106104
.apply-order-a {
107105
margin: 1.25rem;
108-
}
109-
.apply-order-a {
110106
margin-top: 1.5rem;
111107
}
112108
.apply-order-b {
113109
margin: 1.25rem;
114-
}
115-
.apply-order-b {
116110
margin-top: 1.5rem;
117111
}
118112
.dark .dark\:group:hover .apply-dark-group-example-a {

src/lib/collapseAdjacentRules.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
let types = new Set(['atrule', 'rule'])
2+
let comparisonMap = {
3+
atrule: 'params',
4+
rule: 'selector',
5+
}
6+
17
function collapseAdjacentRules(context) {
28
return (root) => {
39
let currentRule = null
410
root.each((node) => {
5-
if (node.type !== 'atrule') {
11+
if (!types.has(node.type)) {
612
currentRule = null
713
return
814
}
@@ -12,7 +18,8 @@ function collapseAdjacentRules(context) {
1218
return
1319
}
1420

15-
if (node.params === currentRule.params) {
21+
let property = comparisonMap[node.type]
22+
if (node[property] === currentRule[property]) {
1623
currentRule.append(node.nodes)
1724
node.remove()
1825
} else {

0 commit comments

Comments
 (0)