From 1e440a0d2cbc0942a6738598bb281836d9862846 Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Wed, 1 Feb 2023 00:57:10 +0100 Subject: [PATCH] fix calc whitespace (#71) --- crates/compiler/src/serializer.rs | 5 +++-- crates/lib/tests/compressed.rs | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/compiler/src/serializer.rs b/crates/compiler/src/serializer.rs index 1ad1183..0552678 100644 --- a/crates/compiler/src/serializer.rs +++ b/crates/compiler/src/serializer.rs @@ -5,7 +5,7 @@ use codemap::{CodeMap, Span}; use crate::{ ast::{CssStmt, MediaQuery, Style, SupportsRule}, color::{Color, ColorFormat, NAMED_COLORS}, - common::{Brackets, ListSeparator, QuoteKind}, + common::{BinaryOp, Brackets, ListSeparator, QuoteKind}, error::SassResult, selector::{ Combinator, ComplexSelector, ComplexSelectorComponent, CompoundSelector, Namespace, Pseudo, @@ -358,7 +358,8 @@ impl<'a> Serializer<'a> { self.buffer.push(b')'); } - let operator_whitespace = !self.options.is_compressed() || op.precedence() == 1; + let operator_whitespace = + !self.options.is_compressed() || matches!(op, BinaryOp::Plus | BinaryOp::Minus); if operator_whitespace { self.buffer.push(b' '); diff --git a/crates/lib/tests/compressed.rs b/crates/lib/tests/compressed.rs index 975e95d..a5a2549 100644 --- a/crates/lib/tests/compressed.rs +++ b/crates/lib/tests/compressed.rs @@ -146,3 +146,9 @@ test!( "a{color:a/b/c}", grass::Options::default().style(grass::OutputStyle::Compressed) ); +test!( + calc, + "a {\n width: calc(100% + 32px);\n}\n", + "a{width:calc(100% + 32px)}", + grass::Options::default().style(grass::OutputStyle::Compressed) +);