Skip to content

Commit

Permalink
Compare adjacent rules ignoring whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed May 30, 2021
1 parent 8845d11 commit 15642fb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/jit/lib/collapseAdjacentRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions tests/jit/collapse-adjacent-rules.test.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/jit/collapse-adjacent-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 15642fb

Please sign in to comment.