File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,18 @@ export default function transformCssModules({ types: t }) {
5151 return new RegExp ( `(${ extensionsPattern } )$` , 'i' ) ;
5252 }
5353
54+ function buildClassNameToScopeNameMap ( tokens ) {
55+ /* eslint-disable new-cap */
56+ return t . ObjectExpression (
57+ Object . keys ( tokens ) . map ( token =>
58+ t . ObjectProperty (
59+ t . StringLiteral ( token ) ,
60+ t . StringLiteral ( tokens [ token ] )
61+ )
62+ )
63+ ) ;
64+ }
65+
5466 return {
5567 visitor : {
5668 Program ( path , state ) {
@@ -134,15 +146,7 @@ export default function transformCssModules({ types: t }) {
134146 // if parent expression is not a Program, replace expression with tokens
135147 // Otherwise remove require from file, we just want to get generated css for our output
136148 if ( ! t . isExpressionStatement ( path . parent ) ) {
137- /* eslint-disable new-cap */
138- path . replaceWith ( t . ObjectExpression (
139- Object . keys ( tokens ) . map (
140- token => t . ObjectProperty (
141- t . StringLiteral ( token ) ,
142- t . StringLiteral ( tokens [ token ] )
143- )
144- )
145- ) ) ;
149+ path . replaceWith ( buildClassNameToScopeNameMap ( tokens ) ) ;
146150 } else {
147151 path . remove ( ) ;
148152 }
You can’t perform that action at this time.
0 commit comments