Skip to content

Commit ca1a20f

Browse files
authored
refactor: rename webpack reexport vars to Rspack format (#12263)
* refactor: rename webpack reexport vars to Rspack format * fix: spacing
1 parent 5c09e49 commit ca1a20f

File tree

130 files changed

+359
-360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+359
-360
lines changed

crates/rspack_core/src/dependency/runtime_template.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,15 +556,15 @@ pub fn import_statement(
556556
}
557557

558558
let import_content = format!(
559-
"/* import */{opt_declaration}{import_var} = {}({module_id_expr});\n",
559+
"/* import */ {opt_declaration}{import_var} = {}({module_id_expr});\n",
560560
RuntimeGlobals::REQUIRE
561561
);
562562
if matches!(exports_type, ExportsType::Dynamic) {
563563
runtime_requirements.insert(RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT);
564564
return (
565565
import_content,
566566
format!(
567-
"/* import */{opt_declaration}{import_var}_default = /*#__PURE__*/{}({import_var});\n",
567+
"/* import */ {opt_declaration}{import_var}_default = /*#__PURE__*/{}({import_var});\n",
568568
RuntimeGlobals::COMPAT_GET_DEFAULT_EXPORT,
569569
),
570570
);

crates/rspack_core/src/external_module.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl ExternalModule {
361361
chunk_init_fragments.push(
362362
NormalInitFragment::new(
363363
format!(
364-
"import {{ createRequire as __rspack_external_createRequire }} from \"{}\";\n{} __rspack_external_createRequire_require = __rspack_external_createRequire({}.url);\n",
364+
"import {{ createRequire as __rspack_createRequire }} from \"{}\";\n{} __rspack_createRequire_require = __rspack_createRequire({}.url);\n",
365365
if need_prefix { "node:module" } else { "module" },
366366
if compilation.options.output.environment.supports_const() {
367367
"const"
@@ -386,7 +386,7 @@ impl ExternalModule {
386386
("undefined".to_string(), String::new())
387387
};
388388
format!(
389-
"{} = __rspack_external_createRequire_require({}){};",
389+
"{} = __rspack_createRequire_require({}){};",
390390
get_namespace_object_export(concatenation_scope, supports_const),
391391
request,
392392
specifiers

crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ impl ESMExportImportedSpecifierDependency {
531531
}
532532
ExportMode::Unused(ExportModeUnused { name }) => ctxt.init_fragments.push(
533533
NormalInitFragment::new(
534-
to_normal_comment(&format!("unused ESM reexport {name}")),
534+
to_normal_comment(&format!("unused reexport {name}")),
535535
InitFragmentStage::StageESMExports,
536536
1,
537537
InitFragmentKey::unique(),
@@ -701,8 +701,7 @@ impl ESMExportImportedSpecifierDependency {
701701
let key = render_used_name(used_name.as_ref());
702702

703703
if checked {
704-
let key =
705-
InitFragmentKey::ESMImport(format!("ESM reexport (checked) {import_var} {name}"));
704+
let key = InitFragmentKey::ESMImport(format!("reexport (checked) {import_var} {name}"));
706705
let runtime_condition = if self.weak() {
707706
RuntimeCondition::Boolean(false)
708707
} else if let Some(connection) = mg.connection_by_dependency_id(self.id()) {
@@ -772,25 +771,25 @@ impl ESMExportImportedSpecifierDependency {
772771
// TODO: modern, need runtimeTemplate support https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/dependencies/HarmonyExportImportedSpecifierDependency.js#L1104-L1106
773772
let mut content = format!(
774773
r"
775-
/* ESM reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {{}};
776-
/* ESM reexport (unknown) */ for( var __WEBPACK_IMPORT_KEY__ in {import_var}) "
774+
/* reexport */ var __rspack_reexport = {{}};
775+
/* reexport */ for( var __rspack_import_key in {import_var}) "
777776
);
778777

779778
if ignored.len() > 1 {
780779
content += &format!(
781-
"if({}.indexOf(__WEBPACK_IMPORT_KEY__) < 0) ",
780+
"if({}.indexOf(__rspack_import_key) < 0) ",
782781
serde_json::to_string(&ignored).expect("should serialize to array")
783782
);
784783
} else if let Some(item) = ignored.iter().next() {
785784
content += &format!(
786-
"if(__WEBPACK_IMPORT_KEY__ !== {}) ",
785+
"if(__rspack_import_key !== {}) ",
787786
serde_json::to_string(item).expect("should serialize to string")
788787
);
789788
}
790-
content += "__WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] =";
789+
content += "__rspack_reexport[__rspack_import_key] =";
791790
// TODO should decide if `modern` is true
792791
content +=
793-
&format!("function(key) {{ return {import_var}[key]; }}.bind(0, __WEBPACK_IMPORT_KEY__)");
792+
&format!("function(key) {{ return {import_var}[key]; }}.bind(0, __rspack_import_key)");
794793
runtime_requirements.insert(RuntimeGlobals::EXPORTS);
795794
runtime_requirements.insert(RuntimeGlobals::DEFINE_PROPERTY_GETTERS);
796795

@@ -802,7 +801,7 @@ impl ESMExportImportedSpecifierDependency {
802801
ctxt.init_fragments.push(
803802
NormalInitFragment::new(
804803
format!(
805-
"{content}\n/* ESM reexport (unknown) */ {}({}, __WEBPACK_REEXPORT_OBJECT__);\n",
804+
"{content}\n/* reexport */ {}({}, __rspack_reexport);\n",
806805
RuntimeGlobals::DEFINE_PROPERTY_GETTERS,
807806
exports_name
808807
),

crates/rspack_plugin_javascript/src/parser_plugin/api_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl JavascriptParserPlugin for APIPlugin {
198198
API_NON_REQUIRE => {
199199
let content = if self.options.module {
200200
parser.build_info.need_create_require = true;
201-
"__rspack_external_createRequire_require".into()
201+
"__rspack_createRequire_require".into()
202202
} else {
203203
"require".into()
204204
};

crates/rspack_plugin_javascript/src/plugin/api_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async fn render_module_content(
4545
init_fragments.push(
4646
NormalInitFragment::new(
4747
format!(
48-
"import {{ createRequire as __rspack_external_createRequire }} from \"{}\";\n{} __rspack_external_createRequire_require = __rspack_external_createRequire({}.url);\n",
48+
"import {{ createRequire as __rspack_createRequire }} from \"{}\";\n{} __rspack_createRequire_require = __rspack_createRequire({}.url);\n",
4949
if need_prefix { "node:module" } else { "module" },
5050
if compilation.options.output.environment.supports_const() {
5151
"const"

tests/rspack-test/builtinCases/plugin-asset/asset-advanced/__snapshots__/output.snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
44
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
55
__webpack_require__.r(__webpack_exports__);
6-
/* import */var _images_file_svg__rspack_import_0 = __webpack_require__("./images/file.svg");
6+
/* import */ var _images_file_svg__rspack_import_0 = __webpack_require__("./images/file.svg");
77

88

99
const container = document.createElement("div");

tests/rspack-test/builtinCases/plugin-asset/asset-simple/__snapshots__/output.snap.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
44
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
55
__webpack_require__.r(__webpack_exports__);
6-
/* import */var _images_file_png__rspack_import_0 = __webpack_require__("./images/file.png");
7-
/* import */var _images_file_jpg__rspack_import_1 = __webpack_require__("./images/file.jpg");
8-
/* import */var _images_file_svg__rspack_import_2 = __webpack_require__("./images/file.svg");
6+
/* import */ var _images_file_png__rspack_import_0 = __webpack_require__("./images/file.png");
7+
/* import */ var _images_file_jpg__rspack_import_1 = __webpack_require__("./images/file.jpg");
8+
/* import */ var _images_file_svg__rspack_import_2 = __webpack_require__("./images/file.svg");
99

1010

1111

tests/rspack-test/builtinCases/plugin-asset/asset-source/__snapshots__/output.snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
44
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
55
__webpack_require__.r(__webpack_exports__);
6-
/* import */var _data_txt__rspack_import_0 = __webpack_require__("./data.txt");
6+
/* import */ var _data_txt__rspack_import_0 = __webpack_require__("./data.txt");
77

88

99
console.log(_data_txt__rspack_import_0);

tests/rspack-test/builtinCases/plugin-css-modules/modules-composes/__snapshots__/output.snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
4949
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
5050
__webpack_require__.r(__webpack_exports__);
51-
/* import */var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css");
51+
/* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css");
5252

5353

5454

tests/rspack-test/builtinCases/plugin-css-modules/modules-ident-name/__snapshots__/output.snap.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
1111
"./index.js": (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
1212
__webpack_require__.r(__webpack_exports__);
13-
/* import */var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css");
13+
/* import */ var _style_module_css__rspack_import_0 = __webpack_require__("./style.module.css");
1414

1515

1616
console.log(_style_module_css__rspack_import_0);

0 commit comments

Comments
 (0)