Skip to content

Commit 068ccbb

Browse files
committed
feat: should rename default import based on source
1 parent 5408616 commit 068ccbb

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

crates/rspack_core/src/concatenated_module.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,11 @@ impl Module for ConcatenatedModule {
795795
}
796796

797797
let new_name = if all_used_names.contains(atom) {
798-
let new_name = find_new_name(atom, &all_used_names, None, &readable_identifier);
798+
let new_name = if atom == "default" {
799+
find_new_name("", &all_used_names, None, &source.replace("\"", ""))
800+
} else {
801+
find_new_name(atom, &all_used_names, None, &readable_identifier)
802+
};
799803
all_used_names.insert(new_name.clone());
800804
// if the imported symbol is exported, we rename the export as well
801805
if let Some(raw_export_map) = info.raw_export_map.as_mut()

packages/rspack-test-tools/tests/configCases/library/modern-module-export-char/rspack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ module.exports = {
3131
const bundle = Object.values(assets)[0]._value;
3232
expect(bundle)
3333
.toContain(`var __webpack_exports__cjsInterop = (foo_default());
34-
export { external_external_module_default as defaultImport, namedImport, __webpack_exports__cjsInterop as cjsInterop };`);
34+
export { external_module as defaultImport, namedImport, __webpack_exports__cjsInterop as cjsInterop };`);
3535
expect(bundle).toContain(
36-
'import external_external_module_default, { namedImport } from "external-module";'
36+
'import external_module, { namedImport } from "external-module";'
3737
);
3838
});
3939
};

packages/rspack-test-tools/tests/configCases/library/modern-module-named-import-externals/rspack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = {
3535
expect(source).toMatchInlineSnapshot(`
3636
import { HomeLayout as external_externals0_HomeLayout, a } from "externals0";
3737
import { a as external_externals1_a } from "externals1";
38-
import external_externals2_default from "externals2";
38+
import externals2 from "externals2";
3939
import "externals4";
4040
import * as __WEBPACK_EXTERNAL_MODULE_externals3__ from "externals3";
4141
@@ -76,7 +76,7 @@ module.exports = {
7676
7777
7878
external_externals1_a;
79-
external_externals2_default;
79+
externals2;
8080
__WEBPACK_EXTERNAL_MODULE_externals3__;
8181
8282
export { a };

tests/webpack-test/configCases/externals/module-import/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("path");
33

44
it("module-import should correctly get fallback type", function() {
55
const content = fs.readFileSync(path.resolve(__dirname, "a.js"), "utf-8");
6-
expect(content).toContain(`import external_external0_default from \"external0\";`); // module
6+
expect(content).toContain(`import external0 from \"external0\";`); // module
77
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external1__ from "external1"`); // module
88
expect(content).toContain(`module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("external2")`); // node-commonjs
99
expect(content).toContain(`import * as __WEBPACK_EXTERNAL_MODULE_external3__ from "external3"`); // module

0 commit comments

Comments
 (0)