Skip to content

Commit

Permalink
Fix invalid whitespace removal around star selector
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Feb 17, 2025
1 parent 015341e commit 9da6973
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/css/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,9 @@ fn check_weird_input() {
assert_eq!(minify("*/**/=").unwrap().to_string(), "* =");
assert_eq!(minify(r#"\-1"#).unwrap().to_string(), r#"\-1"#);
}

#[test]
fn check_space_after_star() {
assert_eq!(minify("* .original").unwrap().to_string(), "* .original");
assert_eq!(minify(".a * .original").unwrap().to_string(), ".a * .original");
}
12 changes: 12 additions & 0 deletions src/css/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ impl Token<'_> {
matches!(*self, Token::SelectorElement(SelectorElement::Media(_)))
}

fn is_a_selector_element(&self) -> bool {
matches!(*self, Token::SelectorElement(_))
}

fn is_a_license(&self) -> bool {
matches!(*self, Token::License(_))
}
Expand Down Expand Up @@ -619,6 +623,14 @@ fn clean_tokens(mut v: Vec<Token<'_>>) -> Vec<Token<'_>> {
{
// retain the space between keywords
// and the space that disambiguates functions from keyword-plus-parens
} else if v[previous_element_index].is_a_selector_element() &&
matches!(v.get(i + 1), Some(Token::Char(ReservedChar::Star)))
{
// retain the space before `*` if it's preceded by a selector.
} else if matches!(v[previous_element_index], Token::Char(ReservedChar::Star))
&& v.get(i + 1).is_some_and(|elem| elem.is_a_selector_element())
{
// retain the space after `*` if it's followed by a selector.
} else if matches!(
v[previous_element_index],
Token::Char(
Expand Down

0 comments on commit 9da6973

Please sign in to comment.