Skip to content

Commit

Permalink
optimize nested light-dark()
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett committed Feb 14, 2024
1 parent a08f31b commit 2f18ed9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/lib.rs
Expand Up @@ -27035,6 +27035,10 @@ mod tests {
".foo { color: light-dark(yellow, red); }",
".foo{color:light-dark(#ff0,red)}",
);
minify_test(
".foo { color: light-dark(light-dark(yellow, red), light-dark(yellow, red)); }",
".foo{color:light-dark(#ff0,red)}",
);
minify_test(
".foo { color: light-dark(rgb(0, 0, 255), hsl(120deg, 50%, 50%)); }",
".foo{color:light-dark(#00f,#40bf40)}",
Expand Down
12 changes: 9 additions & 3 deletions src/values/color.rs
Expand Up @@ -1032,10 +1032,16 @@ fn parse_color_function<'i, 't>(
},
"light-dark" => {
input.parse_nested_block(|input| {
let light = CssColor::parse(input)?;
let light = match CssColor::parse(input)? {
CssColor::LightDark(light, _) => light,
light => Box::new(light)
};
input.expect_comma()?;
let dark = CssColor::parse(input)?;
Ok(CssColor::LightDark(Box::new(light), Box::new(dark)))
let dark = match CssColor::parse(input)? {
CssColor::LightDark(_, dark) => dark,
dark => Box::new(dark)
};
Ok(CssColor::LightDark(light, dark))
})
},
_ => Err(location.new_unexpected_token_error(
Expand Down

0 comments on commit 2f18ed9

Please sign in to comment.