Compare adjacent rules ignoring whitespace

This commit is contained in:
Adam Wathan 2021-05-30 14:52:54 -04:00
parent 8845d112fb
commit 15642fbcc8
3 changed files with 19 additions and 1 deletions

View file

@ -22,7 +22,13 @@ export default function collapseAdjacentRules() {
if (node.type === 'atrule' && node.name === 'font-face') {
currentRule = node
} else if (properties.every((property) => node[property] === currentRule[property])) {
} else if (
properties.every(
(property) =>
(node[property] ?? '').replace(/\s+/g, ' ') ===
(currentRule[property] ?? '').replace(/\s+/g, ' ')
)
) {
currentRule.append(node.nodes)
node.remove()
} else {

View file

@ -36,6 +36,11 @@
.font-bold {
font-weight: 700;
}
.foo,
.bar {
color: black;
font-weight: 700;
}
@media (min-width: 640px) {
.sm\:text-center {
text-align: center;

View file

@ -47,6 +47,13 @@ test('collapse adjacent rules', () => {
url("/fonts/ProximaNova.woff") format("woff");
}
}
.foo, .bar {
color: black;
}
.foo,
.bar {
font-weight: 700;
}
`
return run(css, config).then((result) => {