@@ -41,15 +41,19 @@ function localizeNode(rule, mode, options) {
41
41
switch ( node . type ) {
42
42
case 'root' : {
43
43
let resultingGlobal ;
44
+
44
45
context . hasPureGlobals = false ;
46
+
45
47
newNodes = node . nodes . map ( function ( n ) {
46
48
const nContext = {
47
49
global : context . global ,
48
50
lastWasSpacing : true ,
49
51
hasLocals : false ,
50
52
explicit : false ,
51
53
} ;
54
+
52
55
n = transform ( n , nContext ) ;
56
+
53
57
if ( typeof resultingGlobal === 'undefined' ) {
54
58
resultingGlobal = nContext . global ;
55
59
} else if ( resultingGlobal !== nContext . global ) {
@@ -59,11 +63,14 @@ function localizeNode(rule, mode, options) {
59
63
'" (multiple selectors must result in the same mode for the rule)'
60
64
) ;
61
65
}
66
+
62
67
if ( ! nContext . hasLocals ) {
63
68
context . hasPureGlobals = true ;
64
69
}
70
+
65
71
return n ;
66
72
} ) ;
73
+
67
74
context . global = resultingGlobal ;
68
75
69
76
node . nodes = normalizeNodeArray ( newNodes ) ;
@@ -160,7 +167,6 @@ function localizeNode(rule, mode, options) {
160
167
) ;
161
168
}
162
169
163
- const next = node . parent ;
164
170
const addBackSpacing = ! ! node . spaces . before ;
165
171
166
172
context . ignoreNextSpacing = context . lastWasSpacing
@@ -205,6 +211,7 @@ function localizeNode(rule, mode, options) {
205
211
context . lastWasSpacing = false ;
206
212
context . ignoreNextSpacing = false ;
207
213
context . enforceNoSpacing = false ;
214
+
208
215
return node ;
209
216
} ;
210
217
@@ -213,11 +220,10 @@ function localizeNode(rule, mode, options) {
213
220
hasPureGlobals : false ,
214
221
} ;
215
222
216
- const selector = selectorParser ( root => {
223
+ rootContext . selector = selectorParser ( root => {
217
224
transform ( root , rootContext ) ;
218
225
} ) . processSync ( rule , { updateSelector : false , lossless : true } ) ;
219
226
220
- rootContext . selector = selector ;
221
227
return rootContext ;
222
228
}
223
229
@@ -400,6 +406,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
400
406
if ( typeof options !== 'object' ) {
401
407
options = { } ; // If options is undefined or not an object the plugin fails
402
408
}
409
+
403
410
if ( options && options . mode ) {
404
411
if (
405
412
options . mode !== 'global' &&
@@ -411,8 +418,10 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
411
418
) ;
412
419
}
413
420
}
421
+
414
422
const pureMode = options && options . mode === 'pure' ;
415
423
const globalMode = options && options . mode === 'global' ;
424
+
416
425
return function ( css ) {
417
426
css . walkAtRules ( function ( atrule ) {
418
427
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(
450
459
} ) ;
451
460
}
452
461
} ) ;
462
+
453
463
css . walkRules ( function ( rule ) {
454
464
if (
455
465
rule . parent . type === 'atrule' &&
@@ -480,7 +490,9 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function(
480
490
'(pure selectors must contain at least one local class or id)'
481
491
) ;
482
492
}
493
+
483
494
rule . selector = context . selector ;
495
+
484
496
// Less-syntax mixins parse as rules with no nodes
485
497
if ( rule . nodes ) {
486
498
rule . nodes . forEach ( decl => localizeDecl ( decl , context ) ) ;
0 commit comments