Skip to content

Commit 49d6db9

Browse files
committed
Ensure interleave nested declarations have a semicolon when needed
Closes #1089
1 parent 8986055 commit 49d6db9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24929,6 +24929,21 @@ mod tests {
2492924929
exclude: Features::empty(),
2493024930
},
2493124931
);
24932+
24933+
minify_test(
24934+
r#"
24935+
.foo {
24936+
color: red;
24937+
.bar {
24938+
color: green;
24939+
}
24940+
color: blue;
24941+
.baz {
24942+
color: pink;
24943+
}
24944+
}"#,
24945+
".foo{color:red;& .bar{color:green}color:#00f;& .baz{color:pink}}",
24946+
);
2493224947
}
2493324948

2493424949
#[test]

src/rules/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl<'a, 'i, T: ToCss> ToCss for CssRuleList<'i, T> {
10251025
let mut first = true;
10261026
let mut last_without_block = false;
10271027

1028-
for rule in &self.0 {
1028+
for (i, rule) in self.0.iter().enumerate() {
10291029
if let CssRule::Ignored = &rule {
10301030
continue;
10311031
}
@@ -1061,6 +1061,12 @@ impl<'a, 'i, T: ToCss> ToCss for CssRuleList<'i, T> {
10611061
dest.newline()?;
10621062
}
10631063
rule.to_css(dest)?;
1064+
1065+
// If this is an invisible nested declarations rule, and not the last rule in the block, add a semicolon.
1066+
if dest.minify && matches!(rule, CssRule::NestedDeclarations(_)) && i != self.0.len() - 1 {
1067+
dest.write_char(';')?;
1068+
}
1069+
10641070
last_without_block = matches!(
10651071
rule,
10661072
CssRule::Import(..) | CssRule::Namespace(..) | CssRule::LayerStatement(..)

0 commit comments

Comments
 (0)