@@ -46,6 +46,8 @@ function normalizeNodeArray(nodes) {
4646 return array ;
4747}
4848
49+ const isPureSelectorSymbol = Symbol ( "is-pure-selector" ) ;
50+
4951function localizeNode ( rule , mode , localAliasMap ) {
5052 const transform = ( node , context ) => {
5153 if ( context . ignoreNextSpacing && ! isSpacing ( node ) ) {
@@ -253,7 +255,7 @@ function localizeNode(rule, mode, localAliasMap) {
253255 }
254256 case "nesting" : {
255257 if ( node . value === "&" ) {
256- context . hasLocals = true ;
258+ context . hasLocals = rule . parent [ isPureSelectorSymbol ] ;
257259 }
258260 }
259261 }
@@ -502,6 +504,18 @@ function localizeDeclaration(declaration, context) {
502504 }
503505}
504506
507+ const isPureSelector = ( context , rule ) => {
508+ if ( ! rule . parent || rule . type === "root" ) {
509+ return ! context . hasPureGlobals ;
510+ }
511+
512+ if ( rule . type === "rule" && rule [ isPureSelectorSymbol ] ) {
513+ return rule [ isPureSelectorSymbol ] || isPureSelector ( context , rule . parent ) ;
514+ }
515+
516+ return ! context . hasPureGlobals || isPureSelector ( context , rule . parent ) ;
517+ } ;
518+
505519module . exports = ( options = { } ) => {
506520 if (
507521 options &&
@@ -652,8 +666,17 @@ module.exports = (options = {}) => {
652666 context . localAliasMap = localAliasMap ;
653667
654668 const ignoreComment = pureMode ? getIgnoreComment ( rule ) : undefined ;
669+ const isNotPure = pureMode && ! isPureSelector ( context , rule ) ;
655670
656- if ( pureMode && context . hasPureGlobals && ! ignoreComment ) {
671+ if (
672+ isNotPure &&
673+ ! ignoreComment &&
674+ ( rule . nodes . length > 0
675+ ? ! rule . nodes . every (
676+ ( item ) => item . type === "rule" || item . type === "atrule"
677+ )
678+ : true )
679+ ) {
657680 throw rule . error (
658681 'Selector "' +
659682 rule . selector +
@@ -664,6 +687,10 @@ module.exports = (options = {}) => {
664687 ignoreComment . remove ( ) ;
665688 }
666689
690+ if ( pureMode ) {
691+ rule [ isPureSelectorSymbol ] = ! isNotPure ;
692+ }
693+
667694 rule . selector = context . selector ;
668695
669696 // Less-syntax mixins parse as rules with no nodes
0 commit comments