File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -590,6 +590,7 @@ module.exports = (options = {}) => {
590
590
}
591
591
} ) ;
592
592
593
+ const localRules = new Set ( ) ;
593
594
root . walkRules ( ( rule ) => {
594
595
if (
595
596
rule . parent &&
@@ -605,13 +606,23 @@ module.exports = (options = {}) => {
605
606
context . options = options ;
606
607
context . localAliasMap = localAliasMap ;
607
608
608
- if ( pureMode && context . hasPureGlobals ) {
609
+ if (
610
+ pureMode &&
611
+ context . hasPureGlobals &&
612
+ ! localRules . has ( rule . parent )
613
+ ) {
609
614
throw rule . error (
610
615
'Selector "' +
611
616
rule . selector +
612
617
'" is not pure ' +
613
618
"(pure selectors must contain at least one local class or id)"
614
619
) ;
620
+ } else {
621
+ // Once a parent is pure all children are also pure
622
+ // For example the span inside this .foo is also pure
623
+ // although it is not local itself:
624
+ // .foo { span { color: red; } }
625
+ localRules . add ( rule ) ;
615
626
}
616
627
617
628
rule . selector = context . selector ;
Original file line number Diff line number Diff line change @@ -868,6 +868,24 @@ const tests = [
868
868
options : { mode : "pure" } ,
869
869
error : / i s n o t p u r e / ,
870
870
} ,
871
+ {
872
+ name : "consider nonlocal children of a pure parent as pure" ,
873
+ input : ".foo { span { a_value: some-value; } }" ,
874
+ options : { mode : "pure" } ,
875
+ expected : ":local(.foo) { span { a_value: some-value; } }" ,
876
+ } ,
877
+ {
878
+ name : "consider nested nonlocal children of a pure parent as pure" ,
879
+ input : ".foo { span { a { a_value: some-value; } } }" ,
880
+ options : { mode : "pure" } ,
881
+ expected : ":local(.foo) { span { a { a_value: some-value; } } }" ,
882
+ } ,
883
+ {
884
+ name : "throw on mixed parents" ,
885
+ input : ".foo, html { span { a_value: some-value; } }" ,
886
+ options : { mode : "pure" } ,
887
+ error : / i s n o t p u r e / ,
888
+ } ,
871
889
{
872
890
name : "css nesting" ,
873
891
input : `
You can’t perform that action at this time.
0 commit comments