@@ -485,17 +485,9 @@ function getFilter(filter, resourcePath) {
485
485
}
486
486
487
487
function getValidLocalName ( localName , exportLocalsConvention ) {
488
- if ( typeof exportLocalsConvention === "function" ) {
489
- const result = exportLocalsConvention ( localName ) ;
488
+ const result = exportLocalsConvention ( localName ) ;
490
489
491
- return Array . isArray ( result ) ? result [ 0 ] : result ;
492
- }
493
-
494
- if ( exportLocalsConvention === "dashesOnly" ) {
495
- return dashesCamelCase ( localName ) ;
496
- }
497
-
498
- return camelCase ( localName ) ;
490
+ return Array . isArray ( result ) ? result [ 0 ] : result ;
499
491
}
500
492
501
493
const IS_MODULES = / \. m o d u l e ( s ) ? \. \w + $ / i;
@@ -552,6 +544,32 @@ function getModulesOptions(rawOptions, loaderContext) {
552
544
...rawModulesOptions ,
553
545
} ;
554
546
547
+ let exportLocalsConventionType ;
548
+
549
+ if ( typeof modulesOptions . exportLocalsConvention === "string" ) {
550
+ exportLocalsConventionType = modulesOptions . exportLocalsConvention ;
551
+
552
+ modulesOptions . exportLocalsConvention = ( name ) => {
553
+ switch ( exportLocalsConventionType ) {
554
+ case "camelCase" : {
555
+ return [ name , camelCase ( name ) ] ;
556
+ }
557
+ case "camelCaseOnly" : {
558
+ return camelCase ( name ) ;
559
+ }
560
+ case "dashes" : {
561
+ return [ name , dashesCamelCase ( name ) ] ;
562
+ }
563
+ case "dashesOnly" : {
564
+ return dashesCamelCase ( name ) ;
565
+ }
566
+ case "asIs" :
567
+ default :
568
+ return name ;
569
+ }
570
+ } ;
571
+ }
572
+
555
573
if ( typeof modulesOptions . auto === "boolean" ) {
556
574
const isModules = modulesOptions . auto && IS_MODULES . test ( resourcePath ) ;
557
575
@@ -594,9 +612,9 @@ function getModulesOptions(rawOptions, loaderContext) {
594
612
}
595
613
596
614
if (
597
- typeof modulesOptions . exportLocalsConvention === "string" &&
598
- modulesOptions . exportLocalsConvention !== "camelCaseOnly" &&
599
- modulesOptions . exportLocalsConvention !== "dashesOnly"
615
+ typeof exportLocalsConventionType === "string" &&
616
+ exportLocalsConventionType !== "camelCaseOnly" &&
617
+ exportLocalsConventionType !== "dashesOnly"
600
618
) {
601
619
throw new Error (
602
620
'The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "camelCaseOnly" or "dashesOnly"'
@@ -983,42 +1001,7 @@ function getExportCode(exports, replacements, needToUseIcssPlugin, options) {
983
1001
} ;
984
1002
985
1003
for ( const { name, value } of exports ) {
986
- if ( typeof options . modules . exportLocalsConvention === "function" ) {
987
- addExportToLocalsCode (
988
- options . modules . exportLocalsConvention ( name ) ,
989
- value
990
- ) ;
991
-
992
- // eslint-disable-next-line no-continue
993
- continue ;
994
- }
995
-
996
- switch ( options . modules . exportLocalsConvention ) {
997
- case "camelCase" : {
998
- const modifiedName = camelCase ( name ) ;
999
-
1000
- addExportToLocalsCode ( [ name , modifiedName ] , value ) ;
1001
- break ;
1002
- }
1003
- case "camelCaseOnly" : {
1004
- addExportToLocalsCode ( camelCase ( name ) , value ) ;
1005
- break ;
1006
- }
1007
- case "dashes" : {
1008
- const modifiedName = dashesCamelCase ( name ) ;
1009
-
1010
- addExportToLocalsCode ( [ name , modifiedName ] , value ) ;
1011
- break ;
1012
- }
1013
- case "dashesOnly" : {
1014
- addExportToLocalsCode ( dashesCamelCase ( name ) , value ) ;
1015
- break ;
1016
- }
1017
- case "asIs" :
1018
- default :
1019
- addExportToLocalsCode ( name , value ) ;
1020
- break ;
1021
- }
1004
+ addExportToLocalsCode ( options . modules . exportLocalsConvention ( name ) , value ) ;
1022
1005
}
1023
1006
1024
1007
for ( const item of replacements ) {
0 commit comments