From 331e132b99ca785e9387231dd12c2464a2b42c95 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Tue, 9 Jul 2024 10:45:56 +0800 Subject: [PATCH 1/3] fix: panic when get max target in find target --- crates/rspack_core/src/exports_info.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index b76c882e9b9..7697b884484 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -1293,11 +1293,17 @@ impl ExportInfoId { if !export_info.target_is_set || export_info.target.is_empty() { return FindTargetRetEnum::Undefined; } - let raw_target = export_info - .get_max_target_readonly() - .values() - .next() - .cloned(); + + let raw_target = if export_info.max_target_is_set { + export_info + .get_max_target_readonly() + .values() + .next() + .cloned() + } else { + export_info._get_max_target().values().next().cloned() + }; + let Some(raw_target) = raw_target else { return FindTargetRetEnum::Undefined; }; From bc4f712bfc33880cbb8f1511a8ba6c5f2973ac70 Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Tue, 9 Jul 2024 12:11:12 +0800 Subject: [PATCH 2/3] fix: panic when get max target in find target --- .../get-max-target-panic/index.js | 5 +++++ .../node_modules/mocklib/core.js | 2 ++ .../node_modules/mocklib/empty.js | 0 .../node_modules/mocklib/lib.js | 1 + .../node_modules/mocklib/package.json | 8 ++++++++ .../node_modules/mocklib/queryclient.js | 1 + .../get-max-target-panic/rspack.config.js | 13 +++++++++++++ 7 files changed, 30 insertions(+) create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/empty.js create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js create mode 100644 packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js new file mode 100644 index 00000000000..09eff7dcb6d --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/index.js @@ -0,0 +1,5 @@ +import { QueryClient } from 'mocklib'; + +it("should compile", () => { + expect(QueryClient).toBe(1) +}); \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js new file mode 100644 index 00000000000..40cf7612cc1 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/core.js @@ -0,0 +1,2 @@ +export { QueryClient } from './queryclient'; +export * from './empty'; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/empty.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/empty.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js new file mode 100644 index 00000000000..4b0e0413762 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/lib.js @@ -0,0 +1 @@ +export * from './core'; diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json new file mode 100644 index 00000000000..81f0a344a40 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/package.json @@ -0,0 +1,8 @@ +{ + "name": "mocklib", + "main": "./lib.js", + "module": "./lib.js", + "sideEffects": [ + "lib.js" + ] +} \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js new file mode 100644 index 00000000000..8bf3dbf7e52 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/node_modules/mocklib/queryclient.js @@ -0,0 +1 @@ +export var QueryClient = 1; \ No newline at end of file diff --git a/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js new file mode 100644 index 00000000000..749dca0efc0 --- /dev/null +++ b/packages/rspack-test-tools/tests/configCases/concatenate-modules/get-max-target-panic/rspack.config.js @@ -0,0 +1,13 @@ +/**@type {import("@rspack/core").Configuration}*/ +module.exports = { + mode: "development", + entry: { + main: "./index.js" + }, + optimization: { + providedExports: true, + usedExports: true, + concatenateModules: true, + minimize: false + }, +}; From 6815d02b262d3a29402bd89c9aa08d7658663d5c Mon Sep 17 00:00:00 2001 From: LingyuCoder Date: Tue, 9 Jul 2024 14:10:54 +0800 Subject: [PATCH 3/3] fix: panic when get max target in find target --- crates/rspack_core/src/exports_info.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/rspack_core/src/exports_info.rs b/crates/rspack_core/src/exports_info.rs index 7697b884484..cdeae4ebdab 100644 --- a/crates/rspack_core/src/exports_info.rs +++ b/crates/rspack_core/src/exports_info.rs @@ -1724,6 +1724,8 @@ impl ExportInfo { map } + /// Panics: + /// Panics if max target is not set before. fn get_max_target_readonly(&self) -> &HashMap, ExportInfoTargetValue> { assert!(self.max_target_is_set); &self.max_target