@@ -12,23 +12,23 @@ function normalizeNodeArray(nodes) {
1212 array . push ( x ) ;
1313 }
1414 } ) ;
15- if ( array . length > 0 && array [ array . length - 1 ] . type === " spacing" ) {
15+ if ( array . length > 0 && array [ array . length - 1 ] . type === ' spacing' ) {
1616 array . pop ( ) ;
1717 }
1818 return array ;
1919}
2020
2121function 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 ) ;
2424 }
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 ) ;
2727 }
2828
2929 var newNodes ;
3030 switch ( node . type ) {
31- case " selectors" :
31+ case ' selectors' :
3232 var resultingGlobal ;
3333 context . hasPureGlobals = false ;
3434 newNodes = node . nodes . map ( function ( n ) {
@@ -39,11 +39,11 @@ function localizeNode(node, context) {
3939 explicit : false
4040 } ;
4141 n = localizeNode ( n , nContext ) ;
42- if ( typeof resultingGlobal === " undefined" ) {
42+ if ( typeof resultingGlobal === ' undefined' ) {
4343 resultingGlobal = nContext . global ;
4444 } 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)' ) ;
4747 }
4848 if ( ! nContext . hasLocals ) {
4949 context . hasPureGlobals = true ;
@@ -55,15 +55,15 @@ function localizeNode(node, context) {
5555 node . nodes = normalizeNodeArray ( newNodes ) ;
5656 break ;
5757
58- case " selector" :
58+ case ' selector' :
5959 newNodes = node . nodes . map ( function ( n ) {
6060 return localizeNode ( n , context ) ;
6161 } ) ;
6262 node = Object . create ( node ) ;
6363 node . nodes = normalizeNodeArray ( newNodes ) ;
6464 break ;
6565
66- case " spacing" :
66+ case ' spacing' :
6767 if ( context . ignoreNextSpacing ) {
6868 context . ignoreNextSpacing = false ;
6969 context . lastWasSpacing = false ;
@@ -73,27 +73,27 @@ function localizeNode(node, context) {
7373 context . lastWasSpacing = true ;
7474 return node ;
7575
76- case " pseudo-class" :
77- if ( node . name === " local" || node . name === " global" ) {
76+ case ' pseudo-class' :
77+ if ( node . name === ' local' || node . name === ' global' ) {
7878 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 + ' (...)' ) ;
8080 }
8181 context . ignoreNextSpacing = context . lastWasSpacing ? node . name : false ;
8282 context . enforceNoSpacing = context . lastWasSpacing ? false : node . name ;
83- context . global = ( node . name === " global" ) ;
83+ context . global = ( node . name === ' global' ) ;
8484 context . explicit = true ;
8585 return null ;
8686 }
8787 break ;
8888
89- case " nested-pseudo-class" :
89+ case ' nested-pseudo-class' :
9090 var subContext ;
91- if ( node . name === " local" || node . name === " global" ) {
91+ if ( node . name === ' local' || node . name === ' global' ) {
9292 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 + ' (...)' ) ;
9494 }
9595 subContext = {
96- global : ( node . name === " global" ) ,
96+ global : ( node . name === ' global' ) ,
9797 inside : node . name ,
9898 hasLocals : false ,
9999 explicit : true
@@ -123,12 +123,12 @@ function localizeNode(node, context) {
123123 }
124124 break ;
125125
126- case "id" :
127- case " class" :
126+ case 'id' :
127+ case ' class' :
128128 if ( ! context . global ) {
129129 node = {
130- type : " nested-pseudo-class" ,
131- name : " local" ,
130+ type : ' nested-pseudo-class' ,
131+ name : ' local' ,
132132 nodes : [ node ]
133133 } ;
134134 context . hasLocals = true ;
@@ -146,15 +146,15 @@ function localizeNode(node, context) {
146146function localizeDeclNode ( node , context ) {
147147 var newNode ;
148148 switch ( node . type ) {
149- case " item" :
149+ case ' item' :
150150 if ( context . localizeNextItem ) {
151151 newNode = Object . create ( node ) ;
152- newNode . name = " :local(" + newNode . name + ")" ;
152+ newNode . name = ' :local(' + newNode . name + ')' ;
153153 context . localizeNextItem = false ;
154154 return newNode ;
155155 }
156156 break ;
157- case " url" :
157+ case ' url' :
158158 if ( context . options && context . options . rewriteUrl ) {
159159 newNode = Object . create ( node ) ;
160160 newNode . url = context . options . rewriteUrl ( context . global , node . url ) ;
@@ -193,30 +193,30 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
193193 options = { } ; // If options is undefined or not an object the plugin fails
194194 }
195195 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")' ) ;
198198 }
199199 }
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' ;
202202 return function ( css ) {
203203 css . walkAtRules ( function ( atrule ) {
204204 if ( / k e y f r a m e s $ / . test ( atrule . name ) ) {
205205 var globalMatch = / ^ \s * : g l o b a l \s * \( ( .+ ) \) \s * $ / . exec ( atrule . params ) ;
206206 var localMatch = / ^ \s * : l o c a l \s * \( ( .+ ) \) \s * $ / . exec ( atrule . params ) ;
207207 if ( globalMatch ) {
208208 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' ) ;
210210 }
211211 atrule . params = globalMatch [ 1 ] ;
212212 } else if ( localMatch ) {
213213 atrule . params = localMatch [ 0 ] ;
214214 } else if ( ! globalMode ) {
215- atrule . params = " :local(" + atrule . params + ")" ;
215+ atrule . params = ' :local(' + atrule . params + ')' ;
216216 }
217217 } else if ( atrule . nodes ) {
218218 atrule . nodes . forEach ( function ( decl ) {
219- if ( decl . type === " decl" ) {
219+ if ( decl . type === ' decl' ) {
220220 localizeDecl ( decl , {
221221 options : options ,
222222 global : globalMode
@@ -226,7 +226,7 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
226226 }
227227 } ) ;
228228 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 ) ) {
230230 // ignore keyframe rules
231231 return ;
232232 }
@@ -243,8 +243,8 @@ module.exports = postcss.plugin('postcss-modules-local-by-default', function (op
243243 throw rule . error ( e . message ) ;
244244 }
245245 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)' ) ;
248248 }
249249 rule . nodes . forEach ( function ( decl ) {
250250 localizeDecl ( decl , context ) ;
0 commit comments