@@ -550,16 +550,12 @@ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) {
550
550
namedExport,
551
551
} ;
552
552
553
- let exportLocalsConventionType ;
554
-
555
553
if ( typeof modulesOptions . exportLocalsConvention === "string" ) {
556
- exportLocalsConventionType = modulesOptions . exportLocalsConvention ;
554
+ // eslint-disable-next-line no-shadow
555
+ const { exportLocalsConvention } = modulesOptions ;
557
556
558
- modulesOptions . useExportsAs =
559
- exportLocalsConventionType === "as-is" ||
560
- exportLocalsConventionType === "asIs" ;
561
557
modulesOptions . exportLocalsConvention = ( name ) => {
562
- switch ( exportLocalsConventionType ) {
558
+ switch ( exportLocalsConvention ) {
563
559
case "camel-case" :
564
560
case "camelCase" : {
565
561
return [ name , camelCase ( name ) ] ;
@@ -640,26 +636,10 @@ function getModulesOptions(rawOptions, esModule, exportType, loaderContext) {
640
636
}
641
637
}
642
638
643
- if ( modulesOptions . namedExport === true ) {
644
- if ( esModule === false ) {
645
- throw new Error (
646
- "The 'modules.namedExport' option requires the 'esModule' option to be enabled" ,
647
- ) ;
648
- }
649
-
650
- /* if (
651
- typeof exportLocalsConventionType === "string" &&
652
- exportLocalsConventionType !== "asIs" &&
653
- exportLocalsConventionType !== "as-is" &&
654
- exportLocalsConventionType !== "camelCaseOnly" &&
655
- exportLocalsConventionType !== "camel-case-only" &&
656
- exportLocalsConventionType !== "dashesOnly" &&
657
- exportLocalsConventionType !== "dashes-only"
658
- ) {
659
- throw new Error(
660
- 'The "modules.namedExport" option requires the "modules.exportLocalsConvention" option to be "as-is", "camel-case-only" or "dashes-only"',
661
- );
662
- }*/
639
+ if ( modulesOptions . namedExport === true && esModule === false ) {
640
+ throw new Error (
641
+ "The 'modules.namedExport' option requires the 'esModule' option to be enabled" ,
642
+ ) ;
663
643
}
664
644
665
645
return modulesOptions ;
@@ -1123,6 +1103,69 @@ function dashesCamelCase(str) {
1123
1103
) ;
1124
1104
}
1125
1105
1106
+ const validIdentifier = / ^ [ a - z A - Z _ $ ] [ a - z A - Z 0 - 9 _ $ ] * $ / u;
1107
+ const keywords = new Set ( [
1108
+ "abstract" ,
1109
+ "boolean" ,
1110
+ "break" ,
1111
+ "byte" ,
1112
+ "case" ,
1113
+ "catch" ,
1114
+ "char" ,
1115
+ "class" ,
1116
+ "const" ,
1117
+ "continue" ,
1118
+ "debugger" ,
1119
+ "default" ,
1120
+ "delete" ,
1121
+ "do" ,
1122
+ "double" ,
1123
+ "else" ,
1124
+ "enum" ,
1125
+ "export" ,
1126
+ "extends" ,
1127
+ "false" ,
1128
+ "final" ,
1129
+ "finally" ,
1130
+ "float" ,
1131
+ "for" ,
1132
+ "function" ,
1133
+ "goto" ,
1134
+ "if" ,
1135
+ "implements" ,
1136
+ "import" ,
1137
+ "in" ,
1138
+ "instanceof" ,
1139
+ "int" ,
1140
+ "interface" ,
1141
+ "long" ,
1142
+ "native" ,
1143
+ "new" ,
1144
+ "null" ,
1145
+ "package" ,
1146
+ "private" ,
1147
+ "protected" ,
1148
+ "public" ,
1149
+ "return" ,
1150
+ "short" ,
1151
+ "static" ,
1152
+ "super" ,
1153
+ "switch" ,
1154
+ "synchronized" ,
1155
+ "this" ,
1156
+ "throw" ,
1157
+ "throws" ,
1158
+ "transient" ,
1159
+ "true" ,
1160
+ "try" ,
1161
+ "typeof" ,
1162
+ "var" ,
1163
+ "void" ,
1164
+ "volatile" ,
1165
+ "while" ,
1166
+ "with" ,
1167
+ ] ) ;
1168
+
1126
1169
function getExportCode (
1127
1170
exports ,
1128
1171
replacements ,
@@ -1145,10 +1188,13 @@ function getExportCode(
1145
1188
const serializedValue = isTemplateLiteralSupported
1146
1189
? convertToTemplateLiteral ( value )
1147
1190
: JSON . stringify ( value ) ;
1191
+
1148
1192
if ( options . modules . namedExport ) {
1149
- if ( options . modules . useExportsAs ) {
1193
+ if ( ! validIdentifier . test ( name ) || keywords . has ( name ) ) {
1150
1194
identifierId += 1 ;
1195
+
1151
1196
const id = `_${ identifierId . toString ( 16 ) } ` ;
1197
+
1152
1198
localsCode += `var ${ id } = ${ serializedValue } ;\n` ;
1153
1199
localsCode += `export { ${ id } as ${ JSON . stringify ( name ) } };\n` ;
1154
1200
} else {
0 commit comments