Skip to content

Commit 694c5a2

Browse files
authored
refactor: rename module arguments to rspack specific (#12350)
1 parent a83b9cb commit 694c5a2

File tree

263 files changed

+791
-791
lines changed

Some content is hidden

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

263 files changed

+791
-791
lines changed

crates/rspack_core/src/context_module.rs

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ impl ContextModule {
542542
);
543543
let async_context = if has_no_chunk {
544544
formatdoc! {r#"
545-
function webpackAsyncContext(req) {{
545+
function __rspack_async_context(req) {{
546546
return Promise.resolve().then(function() {{
547547
if(!{}(map, req)) {{
548548
var e = new Error("Cannot find module '" + req + "'");
@@ -564,7 +564,7 @@ impl ContextModule {
564564
}
565565
} else {
566566
formatdoc! {r#"
567-
function webpackAsyncContext(req) {{
567+
function __rspack_async_context(req) {{
568568
if(!{}(map, req)) {{
569569
return Promise.resolve().then(function() {{
570570
var e = new Error("Cannot find module '" + req + "'");
@@ -585,9 +585,9 @@ impl ContextModule {
585585
formatdoc! {r#"
586586
var map = {map};
587587
{async_context}
588-
webpackAsyncContext.keys = {keys};
589-
webpackAsyncContext.id = {id};
590-
module.exports = webpackAsyncContext;
588+
__rspack_async_context.keys = {keys};
589+
__rspack_async_context.id = {id};
590+
module.exports = __rspack_async_context;
591591
"#,
592592
map = json_stringify(&map),
593593
keys = compilation.runtime_template.returning_function("Object.keys(map)", ""),
@@ -632,10 +632,10 @@ impl ContextModule {
632632
var map = {map};
633633
{fake_map_init_statement}
634634
635-
function webpackAsyncContext(req) {{
636-
return webpackAsyncContextResolve(req).then({then_function});
635+
function __rspack_async_context(req) {{
636+
return __rspack_async_context_resolve(req).then({then_function});
637637
}}
638-
function webpackAsyncContextResolve(req) {{
638+
function __rspack_async_context_resolve(req) {{
639639
return {promise}.then(function() {{
640640
if(!{has_own_property}(map, req)) {{
641641
var e = new Error("Cannot find module '" + req + "'");
@@ -645,10 +645,10 @@ impl ContextModule {
645645
return map[req];
646646
}})
647647
}}
648-
webpackAsyncContext.keys = {keys};
649-
webpackAsyncContext.resolve = webpackAsyncContextResolve;
650-
webpackAsyncContext.id = {id};
651-
module.exports = webpackAsyncContext;
648+
__rspack_async_context.keys = {keys};
649+
__rspack_async_context.resolve = __rspack_async_context_resolve;
650+
__rspack_async_context.id = {id};
651+
module.exports = __rspack_async_context;
652652
"#,
653653
map = json_stringify(&map),
654654
fake_map_init_statement = self.get_fake_map_init_statement(&fake_map),
@@ -672,8 +672,8 @@ impl ContextModule {
672672
var map = {map};
673673
{fake_map_init_statement}
674674
675-
function webpackAsyncContext(req) {{
676-
return webpackAsyncContextResolve(req).then(function(id) {{
675+
function __rspack_async_context(req) {{
676+
return __rspack_async_context_resolve(req).then(function(id) {{
677677
if(!{module_factories}[id]) {{
678678
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
679679
e.code = 'MODULE_NOT_FOUND';
@@ -682,7 +682,7 @@ impl ContextModule {
682682
{return_module_object}
683683
}});
684684
}}
685-
function webpackAsyncContextResolve(req) {{
685+
function __rspack_async_context_resolve(req) {{
686686
// Here Promise.resolve().then() is used instead of new Promise() to prevent
687687
// uncaught exception popping up in devtools
688688
return Promise.resolve().then(function() {{
@@ -694,10 +694,10 @@ impl ContextModule {
694694
return map[req];
695695
}})
696696
}}
697-
webpackAsyncContext.keys = {keys};
698-
webpackAsyncContext.resolve = webpackAsyncContextResolve;
699-
webpackAsyncContext.id = {id};
700-
module.exports = webpackAsyncContext;
697+
__rspack_async_context.keys = {keys};
698+
__rspack_async_context.resolve = __rspack_async_context_resolve;
699+
__rspack_async_context.id = {id};
700+
module.exports = __rspack_async_context;
701701
"#,
702702
map = json_stringify(&map),
703703
fake_map_init_statement = self.get_fake_map_init_statement(&fake_map),
@@ -722,27 +722,27 @@ impl ContextModule {
722722
var map = {map};
723723
{fake_map_init_statement}
724724
725-
function webpackContext(req) {{
726-
var id = webpackContextResolve(req);
725+
function __rspack_context(req) {{
726+
var id = __rspack_context_resolve(req);
727727
if(!{module_factories}[id]) {{
728728
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
729729
e.code = 'MODULE_NOT_FOUND';
730730
throw e;
731731
}}
732732
{return_module_object}
733733
}}
734-
function webpackContextResolve(req) {{
734+
function __rspack_context_resolve(req) {{
735735
if(!{has_own_property}(map, req)) {{
736736
var e = new Error("Cannot find module '" + req + "'");
737737
e.code = 'MODULE_NOT_FOUND';
738738
throw e;
739739
}}
740740
return map[req];
741741
}}
742-
webpackContext.keys = {keys};
743-
webpackContext.resolve = webpackContextResolve;
744-
webpackContext.id = {id};
745-
module.exports = webpackContext;
742+
__rspack_context.keys = {keys};
743+
__rspack_context.resolve = __rspack_context_resolve;
744+
__rspack_context.id = {id};
745+
module.exports = __rspack_context;
746746
"#,
747747
map = json_stringify(&map),
748748
fake_map_init_statement = self.get_fake_map_init_statement(&fake_map),
@@ -777,10 +777,10 @@ impl ContextModule {
777777
var map = {map};
778778
{fake_map_init_statement}
779779
780-
function webpackAsyncContext(req) {{
781-
return webpackAsyncContextResolve(req).then({then_function});
780+
function __rspack_async_context(req) {{
781+
return __rspack_async_context_resolve(req).then({then_function});
782782
}}
783-
function webpackAsyncContextResolve(req) {{
783+
function __rspack_async_context_resolve(req) {{
784784
// Here Promise.resolve().then() is used instead of new Promise() to prevent
785785
// uncaught exception popping up in devtools
786786
return Promise.resolve().then(function() {{
@@ -792,10 +792,10 @@ impl ContextModule {
792792
return map[req];
793793
}})
794794
}}
795-
webpackAsyncContext.keys = {keys};
796-
webpackAsyncContext.resolve = webpackAsyncContextResolve;
797-
webpackAsyncContext.id = {id};
798-
module.exports = webpackAsyncContext;
795+
__rspack_async_context.keys = {keys};
796+
__rspack_async_context.resolve = __rspack_async_context_resolve;
797+
__rspack_async_context.id = {id};
798+
module.exports = __rspack_async_context;
799799
"#,
800800
map = json_stringify(&map),
801801
fake_map_init_statement = self.get_fake_map_init_statement(&fake_map),
@@ -819,24 +819,24 @@ impl ContextModule {
819819
var map = {map};
820820
{fake_map_init_statement}
821821
822-
function webpackContext(req) {{
823-
var id = webpackContextResolve(req);
822+
function __rspack_context(req) {{
823+
var id = __rspack_context_resolve(req);
824824
{return_module_object}
825825
}}
826-
function webpackContextResolve(req) {{
826+
function __rspack_context_resolve(req) {{
827827
if(!{has_own_property}(map, req)) {{
828828
var e = new Error("Cannot find module '" + req + "'");
829829
e.code = 'MODULE_NOT_FOUND';
830830
throw e;
831831
}}
832832
return map[req];
833833
}}
834-
webpackContext.keys = function webpackContextKeys() {{
834+
__rspack_context.keys = function webpackContextKeys() {{
835835
return Object.keys(map);
836836
}};
837-
webpackContext.resolve = webpackContextResolve;
838-
module.exports = webpackContext;
839-
webpackContext.id = {id};
837+
__rspack_context.resolve = __rspack_context_resolve;
838+
module.exports = __rspack_context;
839+
__rspack_context.id = {id};
840840
"#,
841841
map = json_stringify(&map),
842842
fake_map_init_statement = self.get_fake_map_init_statement(&fake_map),

crates/rspack_core/src/runtime_template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ impl RuntimeTemplate {
12451245

12461246
pub fn throw_missing_module_error_function(&self, request: &str) -> String {
12471247
format!(
1248-
"function webpackMissingModule() {{ {} }}",
1248+
"function __rspack_missing_module() {{ {} }}",
12491249
self.throw_missing_module_error_block(request)
12501250
)
12511251
}

crates/rspack_plugin_javascript/src/parser_plugin/compatibility_plugin.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{
1414
visitors::{JavascriptParser, Statement, TagInfoData, VariableDeclaration, expr_name},
1515
};
1616

17-
pub const NESTED_IDENTIFIER_TAG: &str = "_identifier__nested_webpack_identifier__";
17+
pub const NESTED_IDENTIFIER_TAG: &str = "_identifier__nested_rspack_identifier__";
1818

1919
#[derive(Debug, Clone)]
2020
pub struct NestedRequireData {
@@ -121,7 +121,7 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
121121
let start_str = start_buffer.format(start);
122122
let mut end_buffer = itoa::Buffer::new();
123123
let end_str = end_buffer.format(end);
124-
format!("__nested_webpack_require_{}_{}__", start_str, end_str)
124+
format!("__nested_rspack_require_{}_{}__", start_str, end_str)
125125
},
126126
parser.in_short_hand,
127127
start,
@@ -136,7 +136,7 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
136136
self.tag_nested_require_data(
137137
parser,
138138
ident.sym.clone(),
139-
"__nested_webpack_exports__".to_string(),
139+
"__nested_rspack_exports__".to_string(),
140140
parser.in_short_hand,
141141
ident.span().real_lo(),
142142
ident.span().real_hi(),
@@ -161,7 +161,7 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
161161
self.tag_nested_require_data(
162162
parser,
163163
ident.sym.clone(),
164-
"__nested_webpack_exports__".to_string(),
164+
"__nested_rspack_exports__".to_string(),
165165
parser.in_short_hand,
166166
ident.span().real_lo(),
167167
ident.span().real_hi(),
@@ -182,7 +182,7 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
182182
let start_str = start_buffer.format(start);
183183
let mut end_buffer = itoa::Buffer::new();
184184
let end_str = end_buffer.format(end);
185-
format!("__nested_webpack_require_{}_{}__", start_str, end_str)
185+
format!("__nested_rspack_require_{}_{}__", start_str, end_str)
186186
},
187187
parser.in_short_hand,
188188
start,
@@ -210,7 +210,7 @@ impl JavascriptParserPlugin for CompatibilityPlugin {
210210
{
211211
let mut lo_buffer = itoa::Buffer::new();
212212
let lo_str = lo_buffer.format(fn_decl.span().real_lo());
213-
format!("__nested_webpack_require_{}__", lo_str)
213+
format!("__nested_rspack_require_{}__", lo_str)
214214
},
215215
parser.in_short_hand,
216216
ident.span().real_lo(),

crates/rspack_plugin_javascript/src/parser_plugin/import_parser_plugin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl JavascriptParserPlugin for ImportParserPlugin {
288288
.map(|name| vec![Atom::from(name.as_str())])
289289
.collect::<Vec<_>>()
290290
});
291-
let has_webpack_exports_comment = exports.is_some();
291+
let has_exports_magic_comment = exports.is_some();
292292

293293
let referenced_in_destructuring = parser
294294
.destructuring_assignment_properties
@@ -309,7 +309,7 @@ impl JavascriptParserPlugin for ImportParserPlugin {
309309
let is_statical = referenced_in_destructuring.is_some()
310310
|| referenced_in_member.is_some()
311311
|| referenced_fulfilled_ns_obj.is_some();
312-
if is_statical && has_webpack_exports_comment {
312+
if is_statical && has_exports_magic_comment {
313313
let mut error: Error = create_traceable_error(
314314
"Useless magic comments".into(),
315315
"You don't need `webpackExports` if the usage of dynamic import is statically analyse-able. You can safely remove the `webpackExports` magic comment.".into(),

crates/rspack_plugin_javascript/src/parser_plugin/provide_plugin/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl ProvideParserPlugin {
3131
if let Some(requests) = self.provide.get(name) {
3232
let name_identifier = if name.contains(SOURCE_DOT) {
3333
format!(
34-
"__webpack_provide_{}",
34+
"__rspack_provide_{}",
3535
name.cow_replace(SOURCE_DOT, MODULE_DOT)
3636
)
3737
} else {

crates/rspack_plugin_javascript/src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub async fn render_module(
207207
args.push(if need_module {
208208
module_argument
209209
} else {
210-
format!("__unused_webpack_{module_argument}")
210+
format!("__unused_rspack_{module_argument}")
211211
});
212212
}
213213

@@ -218,7 +218,7 @@ pub async fn render_module(
218218
args.push(if need_exports {
219219
exports_argument
220220
} else {
221-
format!("__unused_webpack_{exports_argument}")
221+
format!("__unused_rspack_{exports_argument}")
222222
});
223223
}
224224
if need_require {

crates/rspack_plugin_library/src/modern_module_library_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub fn render_as_default_export_impl(exports: &[(String, Option<String>)]) -> St
413413
}
414414

415415
format!(
416-
"var __webpack_exports_default__ = {{ {} }};\nexport default __webpack_exports_default__;\n",
416+
"var __rspack_exports_default = {{ {} }};\nexport default __rspack_exports_default;\n",
417417
exports
418418
.iter()
419419
.map(|(local, exported)| {

crates/rspack_plugin_runtime/src/module_chunk_format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ async fn render_chunk(
236236
let mut index_buffer = itoa::Buffer::new();
237237
let index_str = index_buffer.format(index);
238238
startup_source.push(format!(
239-
"import * as __webpack_chunk_${}__ from '{}';",
239+
"import * as __rspack_chunk_{} from '{}';",
240240
index_str,
241241
get_relative_path(&base_chunk_output_name, &other_chunk_output_name)
242242
));
243243
let mut index_buffer2 = itoa::Buffer::new();
244244
let index_str2 = index_buffer2.format(index);
245245
startup_source.push(format!(
246-
"{}(__webpack_chunk_${}__);",
246+
"{}(__rspack_chunk_{});",
247247
compilation
248248
.runtime_template
249249
.render_runtime_globals(&RuntimeGlobals::EXTERNAL_INSTALL_CHUNK),
@@ -331,7 +331,7 @@ async fn render_startup(
331331

332332
let dependant_chunk = compilation.chunk_by_ukey.expect_get(&ck);
333333

334-
let named_import = format!("__webpack_imports__{}", index);
334+
let named_import = format!("__rspack_imports_{}", index);
335335

336336
let dependant_chunk_name = get_chunk_output_name(dependant_chunk, compilation).await?;
337337

crates/rspack_plugin_wasm/src/parser_and_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl ParserAndGenerator for AsyncWasmParserAndGenerator {
289289
.insert(RuntimeGlobals::ASYNC_MODULE);
290290
let promises = promises.join(", ");
291291
let decl = format!(
292-
"var __webpack_instantiate__ = function ([{promises}]) {{\n{imports_compat_code}return {instantiate_call};\n}}\n",
292+
"var __rspack_instantiate__ = function ([{promises}]) {{\n{imports_compat_code}return {instantiate_call};\n}}\n",
293293
);
294294
let async_dependencies = format!(
295295
"{}(module, async function (__rspack_load_async_deps, __rspack_async_done) {{

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
@@ -1,7 +1,7 @@
11
```js title=main.js
22
"use strict";
33
(self["webpackChunkwebpack"] = self["webpackChunkwebpack"] || []).push([["main"], {
4-
"./index.js"(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
4+
"./index.js"(__unused_rspack_module, __webpack_exports__, __webpack_require__) {
55
__webpack_require__.r(__webpack_exports__);
66
/* import */ var _images_file_svg__rspack_import_0 = __webpack_require__("./images/file.svg");
77

0 commit comments

Comments
 (0)