Skip to content

Commit

Permalink
always print initial-value: ; regardless of amount of whitespace ch…
Browse files Browse the repository at this point in the history
…aracters
  • Loading branch information
RobinMalfait committed Jan 12, 2024
1 parent f61531f commit 803c631
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25903,7 +25903,7 @@ mod tests {
@property --property-name {
syntax: "*";
inherits: false;
initial-value:;
initial-value: ;
}
"#},
);
Expand All @@ -25916,7 +25916,7 @@ mod tests {
initial-value:;
}
"#,
"@property --property-name{syntax:\"*\";inherits:false;initial-value:}",
"@property --property-name{syntax:\"*\";inherits:false;initial-value: }",
);

minify_test(
Expand Down
39 changes: 4 additions & 35 deletions src/rules/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ impl<'i> PropertyRule<'i> {
let mut parser = Parser::new(&mut input);

if parser.is_exhausted() {
Some(ParsedComponent::Token(match parser.next_including_whitespace() {
Ok(t) => t.into(),
Err(_) => crate::properties::custom::Token::WhiteSpace("".into()),
}))
Some(ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(
" ".into(),
)))
} else {
Some(syntax.parse_value(&mut parser)?)
}
Expand Down Expand Up @@ -144,37 +143,7 @@ impl<'i> ToCss for PropertyRule<'i> {

dest.write_str("initial-value:")?;
match initial_value {
ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(value)) => {
// Only emit a single whitespace character if the value has one or more spaces. This
// happens in the scenario where initial-value was defined as:
//
// ```css
// @property --foo {
// initial-value: ;
// }
// ```
//
// or with more spaces:
//
// ```css
// @property --foo {
// initial-value: ;
// }
// ```
//
// If no spaces were defined at all, then we don't want to emit any whitespace:
//
// ```css
// @property --foo {
// initial-value:;
// }
// ```
if value.len() >= 1 {
// Not using dest.whitespace() because we _do_ want to emit a single space even when
// minifying.
dest.write_char(' ')?
}
}
ParsedComponent::Token(crate::properties::custom::Token::WhiteSpace(value)) => dest.write_str(value)?,
_ => {
dest.whitespace()?;
initial_value.to_css(dest)?;
Expand Down

0 comments on commit 803c631

Please sign in to comment.