@@ -41,15 +41,19 @@ function localizeNode(rule, mode, options) {
4141 switch ( node . type ) {
4242 case 'root' : {
4343 let resultingGlobal ;
44+
4445 context . hasPureGlobals = false ;
46+
4547 newNodes = node . nodes . map ( function ( n ) {
4648 const nContext = {
4749 global : context . global ,
4850 lastWasSpacing : true ,
4951 hasLocals : false ,
5052 explicit : false ,
5153 } ;
54+
5255 n = transform ( n , nContext ) ;
56+
5357 if ( typeof resultingGlobal === 'undefined' ) {
5458 resultingGlobal = nContext . global ;
5559 } else if ( resultingGlobal !== nContext . global ) {
@@ -59,11 +63,14 @@ function localizeNode(rule, mode, options) {
5963 '" (multiple selectors must result in the same mode for the rule)'
6064 ) ;
6165 }
66+
6267 if ( ! nContext . hasLocals ) {
6368 context . hasPureGlobals = true ;
6469 }
70+
6571 return n ;
6672 } ) ;
73+
6774 context . global = resultingGlobal ;
6875
6976 node . nodes = normalizeNodeArray ( newNodes ) ;
@@ -160,7 +167,6 @@ function localizeNode(rule, mode, options) {
160167 ) ;
161168 }
162169
163- const next = node . parent ;
164170 const addBackSpacing = ! ! node . spaces . before ;
165171
166172 context . ignoreNextSpacing = context . lastWasSpacing
@@ -205,6 +211,7 @@ function localizeNode(rule, mode, options) {
205211 context . lastWasSpacing = false ;
206212 context . ignoreNextSpacing = false ;
207213 context . enforceNoSpacing = false ;
214+
208215 return node ;
209216 } ;
210217
@@ -213,11 +220,10 @@ function localizeNode(rule, mode, options) {
213220 hasPureGlobals : false ,
214221 } ;
215222
216- const selector = selectorParser ( root => {
223+ rootContext . selector = selectorParser ( root => {
217224 transform ( root , rootContext ) ;
218225 } ) . processSync ( rule , { updateSelector : false , lossless : true } ) ;
219226
220- rootContext . selector = selector ;
221227 return rootContext ;
222228}
223229
@@ -400,6 +406,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
400406 if ( typeof options !== 'object' ) {
401407 options = { } ; // If options is undefined or not an object the plugin fails
402408 }
409+
403410 if ( options && options . mode ) {
404411 if (
405412 options . mode !== 'global' &&
@@ -411,8 +418,10 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
411418 ) ;
412419 }
413420 }
421+
414422 const pureMode = options && options . mode === 'pure' ;
415423 const globalMode = options && options . mode === 'global' ;
424+
416425 return function ( css ) {
417426 css . walkAtRules ( function ( atrule ) {
418427 if ( / k e y f r a m e s $ / i. test ( atrule . name ) ) {
@@ -450,6 +459,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
450459 } ) ;
451460 }
452461 } ) ;
462+
453463 css . walkRules ( function ( rule ) {
454464 if (
455465 rule . parent . type === 'atrule' &&
@@ -480,7 +490,9 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
480490 '(pure selectors must contain at least one local class or id)'
481491 ) ;
482492 }
493+
483494 rule . selector = context . selector ;
495+
484496 // Less-syntax mixins parse as rules with no nodes
485497 if ( rule . nodes ) {
486498 rule . nodes . forEach ( decl => localizeDecl ( decl , context ) ) ;
0 commit comments