@@ -12,23 +12,23 @@ function normalizeNodeArray(nodes) {
12
12
array . push ( x ) ;
13
13
}
14
14
} ) ;
15
- if ( array . length > 0 && array [ array . length - 1 ] . type === " spacing" ) {
15
+ if ( array . length > 0 && array [ array . length - 1 ] . type === ' spacing' ) {
16
16
array . pop ( ) ;
17
17
}
18
18
return array ;
19
19
}
20
20
21
21
function localizeNode ( node , context ) {
22
- if ( context . ignoreNextSpacing && node . type !== " spacing" ) {
23
- throw new Error ( " Missing whitespace after :" + context . ignoreNextSpacing ) ;
22
+ if ( context . ignoreNextSpacing && node . type !== ' spacing' ) {
23
+ throw new Error ( ' Missing whitespace after :' + context . ignoreNextSpacing ) ;
24
24
}
25
- if ( context . enforceNoSpacing && node . type === " spacing" ) {
26
- throw new Error ( " Missing whitespace before :" + context . enforceNoSpacing ) ;
25
+ if ( context . enforceNoSpacing && node . type === ' spacing' ) {
26
+ throw new Error ( ' Missing whitespace before :' + context . enforceNoSpacing ) ;
27
27
}
28
28
29
29
var newNodes ;
30
30
switch ( node . type ) {
31
- case " selectors" :
31
+ case ' selectors' :
32
32
var resultingGlobal ;
33
33
context . hasPureGlobals = false ;
34
34
newNodes = node . nodes . map ( function ( n ) {
@@ -39,11 +39,11 @@ function localizeNode(node, context) {
39
39
explicit : false
40
40
} ;
41
41
n = localizeNode ( n , nContext ) ;
42
- if ( typeof resultingGlobal === " undefined" ) {
42
+ if ( typeof resultingGlobal === ' undefined' ) {
43
43
resultingGlobal = nContext . global ;
44
44
} else if ( resultingGlobal !== nContext . global ) {
45
- throw new Error ( " Inconsistent rule global/local result in rule '" +
46
- Tokenizer . stringify ( node ) + "' (multiple selectors must result in the same mode for the rule)" ) ;
45
+ throw new Error ( ' Inconsistent rule global/local result in rule "' +
46
+ Tokenizer . stringify ( node ) + '" (multiple selectors must result in the same mode for the rule)' ) ;
47
47
}
48
48
if ( ! nContext . hasLocals ) {
49
49
context . hasPureGlobals = true ;
@@ -55,15 +55,15 @@ function localizeNode(node, context) {
55
55
node . nodes = normalizeNodeArray ( newNodes ) ;
56
56
break ;
57
57
58
- case " selector" :
58
+ case ' selector' :
59
59
newNodes = node . nodes . map ( function ( n ) {
60
60
return localizeNode ( n , context ) ;
61
61
} ) ;
62
62
node = Object . create ( node ) ;
63
63
node . nodes = normalizeNodeArray ( newNodes ) ;
64
64
break ;
65
65
66
- case " spacing" :
66
+ case ' spacing' :
67
67
if ( context . ignoreNextSpacing ) {
68
68
context . ignoreNextSpacing = false ;
69
69
context . lastWasSpacing = false ;
@@ -73,27 +73,27 @@ function localizeNode(node, context) {
73
73
context . lastWasSpacing = true ;
74
74
return node ;
75
75
76
- case " pseudo-class" :
77
- if ( node . name === " local" || node . name === " global" ) {
76
+ case ' pseudo-class' :
77
+ if ( node . name === ' local' || node . name === ' global' ) {
78
78
if ( context . inside ) {
79
- throw new Error ( " A :" + node . name + " is not allowed inside of a :" + context . inside + " (...)" ) ;
79
+ throw new Error ( ' A :' + node . name + ' is not allowed inside of a :' + context . inside + ' (...)' ) ;
80
80
}
81
81
context . ignoreNextSpacing = context . lastWasSpacing ? node . name : false ;
82
82
context . enforceNoSpacing = context . lastWasSpacing ? false : node . name ;
83
- context . global = ( node . name === " global" ) ;
83
+ context . global = ( node . name === ' global' ) ;
84
84
context . explicit = true ;
85
85
return null ;
86
86
}
87
87
break ;
88
88
89
- case " nested-pseudo-class" :
89
+ case ' nested-pseudo-class' :
90
90
var subContext ;
91
- if ( node . name === " local" || node . name === " global" ) {
91
+ if ( node . name === ' local' || node . name === ' global' ) {
92
92
if ( context . inside ) {
93
- throw new Error ( " A :" + node . name + " (...) is not allowed inside of a :" + context . inside + " (...)" ) ;
93
+ throw new Error ( ' A :' + node . name + ' (...) is not allowed inside of a :' + context . inside + ' (...)' ) ;
94
94
}
95
95
subContext = {
96
- global : ( node . name === " global" ) ,
96
+ global : ( node . name === ' global' ) ,
97
97
inside : node . name ,
98
98
hasLocals : false ,
99
99
explicit : true
@@ -123,12 +123,12 @@ function localizeNode(node, context) {
123
123
}
124
124
break ;
125
125
126
- case "id" :
127
- case " class" :
126
+ case 'id' :
127
+ case ' class' :
128
128
if ( ! context . global ) {
129
129
node = {
130
- type : " nested-pseudo-class" ,
131
- name : " local" ,
130
+ type : ' nested-pseudo-class' ,
131
+ name : ' local' ,
132
132
nodes : [ node ]
133
133
} ;
134
134
context . hasLocals = true ;
@@ -146,15 +146,15 @@ function localizeNode(node, context) {
146
146
function localizeDeclNode ( node , context ) {
147
147
var newNode ;
148
148
switch ( node . type ) {
149
- case " item" :
149
+ case ' item' :
150
150
if ( context . localizeNextItem ) {
151
151
newNode = Object . create ( node ) ;
152
- newNode . name = " :local(" + newNode . name + ")" ;
152
+ newNode . name = ' :local(' + newNode . name + ')' ;
153
153
context . localizeNextItem = false ;
154
154
return newNode ;
155
155
}
156
156
break ;
157
- case " url" :
157
+ case ' url' :
158
158
if ( context . options && context . options . rewriteUrl ) {
159
159
newNode = Object . create ( node ) ;
160
160
newNode . url = context . options . rewriteUrl ( context . global , node . url ) ;
@@ -193,30 +193,30 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
193
193
options = { } ; // If options is undefined or not an object the plugin fails
194
194
}
195
195
if ( options && options . mode ) {
196
- if ( options . mode !== " global" && options . mode !== " local" && options . mode !== " pure" ) {
197
- throw new Error ( " options.mode must be either ' global', ' local' or ' pure' (default ' local')" ) ;
196
+ if ( options . mode !== ' global' && options . mode !== ' local' && options . mode !== ' pure' ) {
197
+ throw new Error ( ' options.mode must be either " global", " local" or " pure" (default " local")' ) ;
198
198
}
199
199
}
200
- var pureMode = options && options . mode === " pure" ;
201
- var globalMode = options && options . mode === " global" ;
200
+ var pureMode = options && options . mode === ' pure' ;
201
+ var globalMode = options && options . mode === ' global' ;
202
202
return function ( css ) {
203
203
css . walkAtRules ( function ( atrule ) {
204
204
if ( / k e y f r a m e s $ / . test ( atrule . name ) ) {
205
205
var globalMatch = / ^ \s * : g l o b a l \s * \( ( .+ ) \) \s * $ / . exec ( atrule . params ) ;
206
206
var localMatch = / ^ \s * : l o c a l \s * \( ( .+ ) \) \s * $ / . exec ( atrule . params ) ;
207
207
if ( globalMatch ) {
208
208
if ( pureMode ) {
209
- throw atrule . error ( " @keyframes :global(...) is not allowed in pure mode" ) ;
209
+ throw atrule . error ( ' @keyframes :global(...) is not allowed in pure mode' ) ;
210
210
}
211
211
atrule . params = globalMatch [ 1 ] ;
212
212
} else if ( localMatch ) {
213
213
atrule . params = localMatch [ 0 ] ;
214
214
} else if ( ! globalMode ) {
215
- atrule . params = " :local(" + atrule . params + ")" ;
215
+ atrule . params = ' :local(' + atrule . params + ')' ;
216
216
}
217
217
} else if ( atrule . nodes ) {
218
218
atrule . nodes . forEach ( function ( decl ) {
219
- if ( decl . type === " decl" ) {
219
+ if ( decl . type === ' decl' ) {
220
220
localizeDecl ( decl , {
221
221
options : options ,
222
222
global : globalMode
@@ -226,7 +226,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
226
226
}
227
227
} ) ;
228
228
css . walkRules ( function ( rule ) {
229
- if ( rule . parent . type === " atrule" && / k e y f r a m e s $ / . test ( rule . parent . name ) ) {
229
+ if ( rule . parent . type === ' atrule' && / k e y f r a m e s $ / . test ( rule . parent . name ) ) {
230
230
// ignore keyframe rules
231
231
return ;
232
232
}
@@ -243,8 +243,8 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
243
243
throw rule . error ( e . message ) ;
244
244
}
245
245
if ( pureMode && context . hasPureGlobals ) {
246
- throw rule . error ( " Selector '" + Tokenizer . stringify ( selector ) + "' is not pure " +
247
- " (pure selectors must contain at least one local class or id)" ) ;
246
+ throw rule . error ( ' Selector "' + Tokenizer . stringify ( selector ) + '" is not pure ' +
247
+ ' (pure selectors must contain at least one local class or id)' ) ;
248
248
}
249
249
rule . nodes . forEach ( function ( decl ) {
250
250
localizeDecl ( decl , context ) ;
0 commit comments