Preserve whitespace after and in media queries in compressed mode (#242)

Closes #239
This commit is contained in:
Natalie Weizenbaum 2018-03-02 14:15:38 -08:00 committed by GitHub
parent 7d89ad0c1c
commit b7d4384a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 5 deletions

View File

@ -12,6 +12,8 @@
* Preserve empty lines in `/*` comments in the indented syntax.
* Preserve whitespace after `and` in media queries in compressed mode.
## 1.0.0-beta.5.2
* Fix a bug where some colors would crash `compressed` mode.

View File

@ -248,13 +248,12 @@ class _SerializeVisitor implements CssVisitor, ValueVisitor, SelectorVisitor {
if (query.type != null) {
_buffer.write(query.type);
if (query.features.isNotEmpty) {
_buffer.write(" and");
_writeOptionalSpace();
_buffer.write(" and ");
}
}
_writeBetween(
query.features, _isCompressed ? "and" : " and ", _buffer.write);
query.features, _isCompressed ? "and " : " and ", _buffer.write);
}
void visitStyleRule(CssStyleRule node) {

View File

@ -165,14 +165,16 @@ void main() {
equals("@media screen{a{b:c}}"));
});
test('removes whitespace around "and"', () {
// Removing whitespace after "and", "or", or "not" is forbidden because it
// would cause it to parse as a function token.
test('removes whitespace before "and" when possible', () {
expect(
_compile("""
@media screen and (min-width: 900px) and (max-width: 100px) {
a {b: c}
}
"""),
equals("@media screen and(min-width: 900px)and(max-width: 100px)"
equals("@media screen and (min-width: 900px)and (max-width: 100px)"
"{a{b:c}}"));
});