@@ -88,7 +88,7 @@ const plugin = (options = {}) => {
8888
8989  return  { 
9090    postcssPlugin : "postcss-modules-scope" , 
91-     RootExit ( root ,  {  rule } )  { 
91+     Once ( root ,  {  rule } )  { 
9292      const  exports  =  Object . create ( null ) ; 
9393
9494      function  exportScopedName ( name ,  rawName )  { 
@@ -188,21 +188,19 @@ const plugin = (options = {}) => {
188188      // Find any :import and remember imported names 
189189      const  importedNames  =  { } ; 
190190
191-       root . walkRules ( ( rule )  =>  { 
192-         if  ( / ^ : i m p o r t \( .+ \) $ / . test ( rule . selector ) )  { 
193-           rule . walkDecls ( ( decl )  =>  { 
194-             importedNames [ decl . prop ]  =  true ; 
195-           } ) ; 
196-         } 
191+       root . walkRules ( / ^ : i m p o r t \( .+ \) $ / ,  ( rule )  =>  { 
192+         rule . walkDecls ( ( decl )  =>  { 
193+           importedNames [ decl . prop ]  =  true ; 
194+         } ) ; 
197195      } ) ; 
198196
199-       // Find any :local classes  
197+       // Find any :local selectors  
200198      root . walkRules ( ( rule )  =>  { 
201199        let  parsedSelector  =  selectorParser ( ) . astSync ( rule ) ; 
202200
203201        rule . selector  =  traverseNode ( parsedSelector . clone ( ) ) . toString ( ) ; 
204202
205-         rule . walkDecls ( / c o m p o s e s | c o m p o s e - w i t h / ,  ( decl )  =>  { 
203+         rule . walkDecls ( / c o m p o s e s | c o m p o s e - w i t h / i ,  ( decl )  =>  { 
206204          const  localNames  =  getSingleLocalNamesForComposes ( parsedSelector ) ; 
207205          const  classes  =  decl . value . split ( / \s + / ) ; 
208206
@@ -233,30 +231,31 @@ const plugin = (options = {}) => {
233231          decl . remove ( ) ; 
234232        } ) ; 
235233
234+         // Find any :local values 
236235        rule . walkDecls ( ( decl )  =>  { 
236+           if  ( ! / : l o c a l \s * \( ( .+ ?) \) / . test ( decl . value ) )  { 
237+             return ; 
238+           } 
239+ 
237240          let  tokens  =  decl . value . split ( / ( , | ' [ ^ ' ] * ' | " [ ^ " ] * " ) / ) ; 
238241
239242          tokens  =  tokens . map ( ( token ,  idx )  =>  { 
240243            if  ( idx  ===  0  ||  tokens [ idx  -  1 ]  ===  "," )  { 
241244              let  result  =  token ; 
242245
243-               const  localMatch  =  / ^ ( \s * ) : l o c a l \s * \( ( .+ ?) \) / . exec ( token ) ; 
244-               const  nextLocalMatch  =  / : l o c a l \s * \( ( .+ ?) \) / . exec ( token ) ; 
246+               const  localMatch  =  / : l o c a l \s * \( ( .+ ?) \) / . exec ( token ) ; 
245247
246248              if  ( localMatch )  { 
247-                 result  = 
248-                   localMatch [ 1 ]  + 
249-                   exportScopedName ( localMatch [ 2 ] )  + 
250-                   token . substr ( localMatch [ 0 ] . length ) ; 
251-               }  else  if  ( nextLocalMatch )  { 
252-                 const  input  =  nextLocalMatch . input ; 
253-                 const  matchPattern  =  nextLocalMatch [ 0 ] ; 
254-                 const  matchVal  =  nextLocalMatch [ 1 ] ; 
249+                 const  input  =  localMatch . input ; 
250+                 const  matchPattern  =  localMatch [ 0 ] ; 
251+                 const  matchVal  =  localMatch [ 1 ] ; 
255252                const  newVal  =  exportScopedName ( matchVal ) ; 
253+ 
256254                result  =  input . replace ( matchPattern ,  newVal ) ; 
257255              }  else  { 
258-                 // do nothing 
256+                 return   token ; 
259257              } 
258+ 
260259              return  result ; 
261260            }  else  { 
262261              return  token ; 
@@ -268,14 +267,14 @@ const plugin = (options = {}) => {
268267      } ) ; 
269268
270269      // Find any :local keyframes 
271-       root . walkAtRules ( ( atrule )  =>  { 
272-         if  ( / k e y f r a m e s $ / i. test ( atrule . name ) )  { 
273-           const  localMatch  =  / ^ \s * : l o c a l \s * \( ( .+ ?) \) \s * $ / . exec ( atrule . params ) ; 
270+       root . walkAtRules ( / k e y f r a m e s $ / i,  ( atRule )  =>  { 
271+         const  localMatch  =  / ^ \s * : l o c a l \s * \( ( .+ ?) \) \s * $ / . exec ( atRule . params ) ; 
274272
275-           if  ( localMatch )  { 
276-             atrule . params  =  exportScopedName ( localMatch [ 1 ] ) ; 
277-           } 
273+         if  ( ! localMatch )  { 
274+           return ; 
278275        } 
276+ 
277+         atRule . params  =  exportScopedName ( localMatch [ 1 ] ) ; 
279278      } ) ; 
280279
281280      // If we found any :locals, insert an :export rule 
0 commit comments