Properly handle trailing commas combined with newlines

This commit is contained in:
ConnorSkees 2020-02-22 18:33:42 -05:00
parent 53861ccb0d
commit 023bc647bd
2 changed files with 18 additions and 1 deletions

View File

@ -57,7 +57,10 @@ impl Display for Selector {
while let Some(sel) = iter.peek() {
if sel != &&SelectorKind::Multiple {
write!(f, ",")?;
if sel != &&SelectorKind::Newline {
if sel == &&SelectorKind::Newline {
iter.next();
f.write_char('\n')?;
} else {
f.write_char(' ')?;
}
break;
@ -65,6 +68,15 @@ impl Display for Selector {
iter.next();
devour_whitespace(&mut iter);
}
while let Some(sel) = iter.peek() {
if sel != &&SelectorKind::Multiple
&& sel != &&SelectorKind::Newline
&& !sel.is_whitespace()
{
break;
}
iter.next();
}
}
_ => write!(f, "{}", s)?,
}

View File

@ -261,3 +261,8 @@ test!(
"a,\nb {\n c {\n color: blue;\n }\n color: red;\n}\n",
"a,\nb {\n color: red;\n}\na c,\nb c {\n color: blue;\n}\n"
);
test!(
trailing_comma_newline,
"#foo #bar,,\n,#baz #boom, {a: b}",
"#foo #bar,\n#baz #boom {\n a: b;\n}\n"
);