From cf41f17ecd8a0da23ac9b006abc17328f2a519e0 Mon Sep 17 00:00:00 2001 From: Gengkun Date: Mon, 12 Aug 2024 10:59:18 +0800 Subject: [PATCH] fix: use intersection runtime for concat module code gen (#7523) --- crates/rspack_core/src/concatenated_module.rs | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 731062c2bdde..dcc6cbe2eb38 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -614,19 +614,23 @@ impl Module for ConcatenatedModule { fn code_generation( &self, compilation: &Compilation, - runtime: Option<&RuntimeSpec>, + generation_runtime: Option<&RuntimeSpec>, _: Option, ) -> Result { let mut runtime_requirements = RuntimeGlobals::default(); - let generation_runtime = runtime.cloned().expect("should have runtime"); - let merged_runtime = if let Some(ref runtime) = self.runtime { - generation_runtime - .intersection(runtime) - .cloned() - .collect::() + let runtime = if let Some(self_runtime) = &self.runtime + && let Some(generation_runtime) = generation_runtime + { + Some(Cow::Owned( + generation_runtime + .intersection(self_runtime) + .cloned() + .collect::(), + )) } else { - generation_runtime + generation_runtime.map(Cow::Borrowed) }; + let runtime = runtime.as_deref(); let context = compilation.options.context.clone(); let (modules_with_info, module_to_info_map) = @@ -642,12 +646,8 @@ impl Module for ConcatenatedModule { let tmp: Vec> = arc_map .par_iter() .map(|(id, info)| { - let updated_module_info = self.analyze_module( - compilation, - Arc::clone(&arc_map), - info.clone(), - Some(&merged_runtime), - )?; + let updated_module_info = + self.analyze_module(compilation, Arc::clone(&arc_map), info.clone(), runtime)?; Ok((*id, updated_module_info)) }) .collect::>();