You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use lightningcss::{
css_modules,
stylesheet::{MinifyOptions, ParserOptions, PrinterOptions, StyleSheet},
};
fn main() {
let mut stylesheet = StyleSheet::parse(
r#"
.a {
color: red;
}
.b {
color: red;
}
:global(.c) {
color: red;
}
:global(.d) {
color: red;
}
"#,
ParserOptions {
css_modules: Some(css_modules::Config::default()),
..ParserOptions::default()
},
)
.unwrap();
stylesheet.minify(MinifyOptions::default()).unwrap();
let css = stylesheet.to_css(PrinterOptions::default()).unwrap();
// The scoped class name selectors get combined, but the global class name
// ones don't.
let expected = r"._8Z4fiW_a, ._8Z4fiW_b {
color: red;
}
.c {
color: red;
}
.d {
color: red;
}
";
assert_eq!(css.code, expected);
// As a workaround, I can create a separate style sheet and minify that to
// combine the scoped and global class name selectors into a single rule.
let mut stylesheet_2 = StyleSheet::parse(&css.code, ParserOptions::default()).unwrap();
stylesheet_2.minify(MinifyOptions::default()).unwrap();
let css_2 = stylesheet_2.to_css(PrinterOptions::default()).unwrap();
let expected_2 = r"._8Z4fiW_a, ._8Z4fiW_b, .c, .d {
color: red;
}
";
assert_eq!(css_2.code, expected_2);
}
The text was updated successfully, but these errors were encountered:
This:
minifies to this:
But I expected it to minify to this:
Demo:
The text was updated successfully, but these errors were encountered: