@@ -705,21 +705,22 @@ class PurgeCSS {
705
705
if ( isInPseudoClass ( selector ) ) return true ;
706
706
707
707
let isPresent = false ;
708
+
708
709
for ( const nodeSelector of selector . nodes ) {
710
+ const val =
711
+ ( nodeSelector . type === "attribute" && nodeSelector . attribute ) ||
712
+ nodeSelector . value ;
713
+
709
714
// if the selector is whitelisted with children
710
715
// returns true to keep all children selectors
711
- if (
712
- nodeSelector . value &&
713
- this . isSelectorWhitelistedChildren ( nodeSelector . value )
714
- ) {
716
+ if ( val && this . isSelectorWhitelistedChildren ( val ) ) {
715
717
return true ;
716
718
}
717
719
718
720
// The selector is found in the internal and user-defined whitelist
719
721
if (
720
- nodeSelector . value &&
721
- ( CSS_WHITELIST . includes ( nodeSelector . value ) ||
722
- this . isSelectorWhitelisted ( nodeSelector . value ) )
722
+ val &&
723
+ ( CSS_WHITELIST . includes ( val ) || this . isSelectorWhitelisted ( val ) )
723
724
) {
724
725
isPresent = true ;
725
726
continue ;
@@ -730,10 +731,11 @@ class PurgeCSS {
730
731
// `value` is a dynamic attribute, highly used in input element
731
732
// the choice is to always leave `value` as it can change based on the user
732
733
// idem for `checked`, `selected`
733
- isPresent =
734
- [ "value" , "checked" , "selected" ] . includes ( nodeSelector . attribute )
735
- ? true
736
- : isAttributeFound ( nodeSelector , selectorsFromExtractor ) ;
734
+ isPresent = [ "value" , "checked" , "selected" ] . includes (
735
+ nodeSelector . attribute
736
+ )
737
+ ? true
738
+ : isAttributeFound ( nodeSelector , selectorsFromExtractor ) ;
737
739
break ;
738
740
case "class" :
739
741
isPresent = isClassFound ( nodeSelector , selectorsFromExtractor ) ;
@@ -747,9 +749,12 @@ class PurgeCSS {
747
749
default :
748
750
break ;
749
751
}
752
+
750
753
// selector is not in whitelist children or in whitelist
751
754
// and it has not been found as an attribute/class/identifier/tag
752
- if ( ! isPresent ) return false ;
755
+ if ( ! isPresent ) {
756
+ return false ;
757
+ }
753
758
}
754
759
return isPresent ;
755
760
}
0 commit comments