@@ -6,7 +6,7 @@ use crate::printer::Printer;
66use crate :: declaration:: DeclarationBlock ;
77use crate :: vendor_prefix:: VendorPrefix ;
88use crate :: targets:: Browsers ;
9- use crate :: rules:: { CssRuleList , CssRule , ToCssWithContext , StyleContext } ;
9+ use crate :: rules:: { CssRuleList , ToCssWithContext , StyleContext } ;
1010use crate :: compat:: Feature ;
1111use crate :: error:: PrinterError ;
1212use super :: MinifyContext ;
@@ -21,17 +21,30 @@ pub struct StyleRule {
2121}
2222
2323impl StyleRule {
24- pub ( crate ) fn minify ( & mut self , context : & mut MinifyContext ) {
25- self . declarations . minify ( context. handler , context. important_handler , context. logical_properties ) ;
26-
24+ pub ( crate ) fn minify ( & mut self , context : & mut MinifyContext , parent_is_unused : bool ) -> bool {
25+ let mut unused = false ;
2726 if !context. unused_symbols . is_empty ( ) {
28- self . rules . 0 . retain ( |rule| {
29- match rule {
30- CssRule :: Style ( style) => !is_unused ( & mut style. selectors . 0 . iter ( ) , & context. unused_symbols ) ,
31- _ => true
27+ if is_unused ( & mut self . selectors . 0 . iter ( ) , & context. unused_symbols , parent_is_unused) {
28+ if self . rules . 0 . is_empty ( ) {
29+ return true
3230 }
33- } ) ;
31+
32+ self . declarations . declarations . clear ( ) ;
33+ self . declarations . important_declarations . clear ( ) ;
34+ unused = true ;
35+ }
36+ }
37+
38+ self . declarations . minify ( context. handler , context. important_handler , context. logical_properties ) ;
39+
40+ if !self . rules . 0 . is_empty ( ) {
41+ self . rules . minify ( context, unused) ;
42+ if unused && self . rules . 0 . is_empty ( ) {
43+ return true
44+ }
3445 }
46+
47+ false
3548 }
3649
3750 pub fn is_compatible ( & self , targets : Option < Browsers > ) -> bool {
0 commit comments