From 361c3fee7d2f8e8337d8fe0503eff121ccbc207b Mon Sep 17 00:00:00 2001 From: Hana Date: Mon, 4 Dec 2023 19:31:18 +0800 Subject: [PATCH] refactor: unexpected should not always rely on --- crates/node_binding/src/plugins/mod.rs | 89 +++++++++---------- crates/rspack_ast/src/lib.rs | 16 ---- .../src/options/raw_builtins/raw_banner.rs | 2 +- .../src/options/raw_external.rs | 2 +- .../src/options/raw_module/js_loader.rs | 4 +- .../src/options/raw_module/mod.rs | 8 +- .../raw_split_chunk_cache_group_test.rs | 1 - .../raw_split_chunks/raw_split_chunk_name.rs | 1 - .../src/code_generation_results.rs | 31 +++---- crates/rspack_core/src/context_module.rs | 22 ++--- crates/rspack_core/src/module_graph/mod.rs | 8 +- crates/rspack_core/src/module_graph_module.rs | 18 ++-- crates/rspack_loader_react_refresh/src/lib.rs | 6 +- crates/rspack_loader_runner/src/runner.rs | 2 +- crates/rspack_loader_sass/src/lib.rs | 29 +++--- crates/rspack_loader_swc/src/lib.rs | 4 +- crates/rspack_plugin_asset/src/lib.rs | 2 +- .../src/parser_and_generator/mod.rs | 12 +-- .../src/plugin/impl_plugin_for_css_plugin.rs | 2 +- .../rspack_plugin_css/src/swc_css_compiler.rs | 2 +- crates/rspack_plugin_devtool/src/lib.rs | 4 +- .../src/ast/stringify.rs | 2 +- .../src/parser_and_generator/mod.rs | 2 +- .../rspack_plugin_javascript/src/runtime.rs | 3 +- crates/rspack_plugin_json/src/lib.rs | 4 +- .../sharing/consume_shared_runtime_module.rs | 7 +- .../src/sharing/share_runtime_module.rs | 2 +- .../src/module_chunk_format.rs | 5 +- .../rspack_plugin_swc_js_minimizer/src/lib.rs | 2 +- crates/rspack_plugin_wasm/src/wasm_plugin.rs | 2 +- 30 files changed, 120 insertions(+), 174 deletions(-) diff --git a/crates/node_binding/src/plugins/mod.rs b/crates/node_binding/src/plugins/mod.rs index 9f2f24ef1e68..dc54964c78e5 100644 --- a/crates/node_binding/src/plugins/mod.rs +++ b/crates/node_binding/src/plugins/mod.rs @@ -13,7 +13,6 @@ use rspack_core::{ChunkAssetArgs, ModuleIdentifier, NormalModuleAfterResolveArgs use rspack_core::{NormalModuleBeforeResolveArgs, PluginNormalModuleFactoryAfterResolveOutput}; use rspack_core::{PluginNormalModuleFactoryBeforeResolveOutput, ResourceData}; use rspack_core::{PluginNormalModuleFactoryResolveForSchemeOutput, PluginShouldEmitHookOutput}; -use rspack_error::internal_error; use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode}; use rspack_napi_shared::NapiResultExt; @@ -96,7 +95,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call compilation: {err}")) } async fn this_compilation( @@ -119,7 +118,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn chunk_asset(&self, args: &ChunkAssetArgs) -> rspack_error::Result<()> { @@ -135,7 +134,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to chunk asset: {err}"))? + .unwrap_or_else(|err| panic!("Failed to chunk asset: {err}")) } #[tracing::instrument(name = "js_hooks_adapter::make", skip_all)] @@ -155,7 +154,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call make: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call make: {err}")) } async fn before_resolve( @@ -171,7 +170,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) { Ok((ret, resolve_data)) => { args.request = resolve_data.request; @@ -195,7 +194,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn context_module_before_resolve( &self, @@ -207,7 +206,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.clone().into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")) } async fn normal_module_factory_resolve_for_scheme( &self, @@ -222,7 +221,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args.into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call this_compilation: {err}"))?; + .unwrap_or_else(|err| panic!("Failed to call this_compilation: {err}")); res.map(|res| { let JsResolveForSchemeResult { resource_data, @@ -251,7 +250,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage additional: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage additional: {err}")) } async fn process_assets_stage_pre_process( @@ -268,7 +267,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage pre-process: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage pre-process: {err}")) } async fn process_assets_stage_derived( @@ -285,7 +284,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage derived: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage derived: {err}")) } async fn process_assets_stage_additions( @@ -302,7 +301,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage additions: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage additions: {err}")) } async fn process_assets_stage_none( @@ -319,7 +318,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets: {err}")) } async fn process_assets_stage_optimize( @@ -336,7 +335,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage optimize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize: {err}")) } async fn process_assets_stage_optimize_count( @@ -353,9 +352,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err( - |err| internal_error!("Failed to call process assets stage optimize count: {err}",), - )? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize count: {err}")) } async fn process_assets_stage_optimize_compatibility( @@ -372,9 +369,9 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize compatibility: {err}",) - })? + .unwrap_or_else(|err| { + panic!("Failed to call process assets stage optimize compatibility: {err}") + }) } async fn process_assets_stage_optimize_size( @@ -391,7 +388,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage optimize size: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize size: {err}")) } async fn process_assets_stage_dev_tooling( @@ -408,7 +405,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage dev tooling: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage dev tooling: {err}")) } async fn process_assets_stage_optimize_inline( @@ -425,9 +422,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize inline: {err}",) - })? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize inline: {err}")) } async fn process_assets_stage_summarize( @@ -445,7 +440,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage summarize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage summarize: {err}")) } async fn process_assets_stage_optimize_hash( @@ -462,7 +457,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage summarize: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage summarize: {err}")) } async fn process_assets_stage_optimize_transfer( @@ -479,9 +474,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call process assets stage optimize transfer: {err}",) - })? + .unwrap_or_else(|err| panic!("Failed to call process assets stage optimize transfer: {err}")) } async fn process_assets_stage_analyse( @@ -498,7 +491,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage analyse: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage analyse: {err}")) } async fn process_assets_stage_report( @@ -515,7 +508,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call process assets stage report: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call process assets stage report: {err}")) } async fn optimize_modules( @@ -535,7 +528,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::Blocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call optimize modules: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call optimize modules: {err}")) } async fn optimize_tree( @@ -550,7 +543,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call optimize tree: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call optimize tree: {err}")) } async fn optimize_chunk_modules( @@ -572,7 +565,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to compilation: {err}"))? + .unwrap_or_else(|err| panic!("Failed to compilation: {err}")) } async fn before_compile( @@ -588,7 +581,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call({}, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call before compile: {err}",))? + .unwrap_or_else(|err| panic!("Failed to call before compile: {err}")) } async fn after_compile( @@ -610,7 +603,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call after compile: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call after compile: {err}")) } async fn finish_make( @@ -632,7 +625,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call finish make: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call finish make: {err}")) } async fn build_module(&self, module: &mut dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -648,7 +641,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call build module: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call build module: {err}")) } async fn finish_modules( @@ -670,7 +663,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to finish modules: {err}"))? + .unwrap_or_else(|err| panic!("Failed to finish modules: {err}")) } async fn emit(&self, _: &mut rspack_core::Compilation) -> rspack_error::Result<()> { @@ -683,7 +676,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call emit: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call emit: {err}")) } async fn asset_emitted(&self, args: &rspack_core::AssetEmittedArgs) -> rspack_error::Result<()> { @@ -697,7 +690,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(args, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call asset emitted: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call asset emitted: {err}")) } async fn should_emit( @@ -719,7 +712,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(compilation, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await; - res.map_err(|err| internal_error!("Failed to call should emit: {err}"))? + res.unwrap_or_else(|err| panic!("Failed to call should emit: {err}")) } async fn after_emit(&self, _: &mut rspack_core::Compilation) -> rspack_error::Result<()> { @@ -732,7 +725,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call((), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call after emit: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call after emit: {err}")) } async fn succeed_module(&self, args: &dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -747,7 +740,7 @@ impl rspack_core::Plugin for JsHooksAdapter { .call(js_module, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call succeed_module hook: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call succeed_module hook: {err}")) } async fn still_valid_module(&self, args: &dyn rspack_core::Module) -> rspack_error::Result<()> { @@ -763,7 +756,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call still_valid_module hook: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call still_valid_module hook: {err}")) } fn execute_module( @@ -791,7 +784,7 @@ impl rspack_core::Plugin for JsHooksAdapter { ) .into_rspack_result()? .blocking_recv() - .map_err(|recv_err| rspack_error::internal_error!(recv_err.to_string()))? + .unwrap_or_else(|recv_err| panic!("{}", recv_err.to_string())) } } diff --git a/crates/rspack_ast/src/lib.rs b/crates/rspack_ast/src/lib.rs index 438aa0cdfcdc..c29cbd9b5172 100644 --- a/crates/rspack_ast/src/lib.rs +++ b/crates/rspack_ast/src/lib.rs @@ -1,7 +1,5 @@ mod ast; -use rspack_error::{internal_error, Result}; - pub use crate::ast::css; use crate::ast::css::Ast as CssAst; pub use crate::ast::javascript; @@ -17,20 +15,6 @@ pub enum RspackAst { } impl RspackAst { - pub fn try_into_javascript(self) -> Result { - match self { - RspackAst::JavaScript(program) => Ok(program), - RspackAst::Css(_) => Err(internal_error!("Failed to cast `CSS` AST to `JavaScript`")), - } - } - - pub fn try_into_css(self) -> Result { - match self { - RspackAst::Css(stylesheet) => Ok(stylesheet), - RspackAst::JavaScript(_) => Err(internal_error!("Failed to cast `JavaScript` AST to `CSS`")), - } - } - pub fn as_javascript(&self) -> Option<&JsAst> { match self { RspackAst::JavaScript(program) => Some(program), diff --git a/crates/rspack_binding_options/src/options/raw_builtins/raw_banner.rs b/crates/rspack_binding_options/src/options/raw_builtins/raw_banner.rs index 1cbfe496ce7f..3b38fe0cfae0 100644 --- a/crates/rspack_binding_options/src/options/raw_builtins/raw_banner.rs +++ b/crates/rspack_binding_options/src/options/raw_builtins/raw_banner.rs @@ -53,7 +53,7 @@ impl TryFrom for BannerContent { .call(ctx.into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call rule.use function: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call rule.use function: {err}")) }) }, ))) diff --git a/crates/rspack_binding_options/src/options/raw_external.rs b/crates/rspack_binding_options/src/options/raw_external.rs index e266e7d73b15..95e5851d675e 100644 --- a/crates/rspack_binding_options/src/options/raw_external.rs +++ b/crates/rspack_binding_options/src/options/raw_external.rs @@ -106,7 +106,7 @@ impl TryFrom for ExternalItem { .call(ctx.into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call external function: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call external function: {err}")) .map(|r| r.into()) }) }))) diff --git a/crates/rspack_binding_options/src/options/raw_module/js_loader.rs b/crates/rspack_binding_options/src/options/raw_module/js_loader.rs index 294e4dbb20e4..508f339c6690 100644 --- a/crates/rspack_binding_options/src/options/raw_module/js_loader.rs +++ b/crates/rspack_binding_options/src/options/raw_module/js_loader.rs @@ -133,7 +133,7 @@ impl Loader for JsLoaderAdapter { .call(js_loader_context, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call loader: {err}"))??; + .unwrap_or_else(|err| panic!("Failed to call loader: {err}"))?; if let Some(loader_result) = loader_result { // This indicate that the JS loaders pitched(return something) successfully @@ -163,7 +163,7 @@ impl Loader for JsLoaderAdapter { .call(js_loader_context, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call loader: {err}"))??; + .unwrap_or_else(|err| panic!("Failed to call loader: {err}"))?; if let Some(loader_result) = loader_result { sync_loader_context(loader_result, loader_context)?; diff --git a/crates/rspack_binding_options/src/options/raw_module/mod.rs b/crates/rspack_binding_options/src/options/raw_module/mod.rs index 129b34686117..6e998fc5fe73 100644 --- a/crates/rspack_binding_options/src/options/raw_module/mod.rs +++ b/crates/rspack_binding_options/src/options/raw_module/mod.rs @@ -239,9 +239,9 @@ impl TryFrom for rspack_core::RuleSetCondition { .call(data, ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| { - internal_error!("Failed to call RuleSetCondition func_matcher: {err}") - })? + .unwrap_or_else(|err| { + panic!("Failed to call RuleSetCondition func_matcher: {err}") + }) }) })) } @@ -609,7 +609,7 @@ impl RawOptionsApply for RawModuleRule { .call(ctx.into(), ThreadsafeFunctionCallMode::NonBlocking) .into_rspack_result()? .await - .map_err(|err| internal_error!("Failed to call rule.use function: {err}"))? + .unwrap_or_else(|err| panic!("Failed to call rule.use function: {err}")) .map(|uses| { uses .into_iter() diff --git a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs index c08565a05182..0ce78e5e1416 100644 --- a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs +++ b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_cache_group_test.rs @@ -4,7 +4,6 @@ use napi::bindgen_prelude::Either3; use napi::{Env, JsFunction}; use napi_derive::napi; use rspack_binding_values::{JsModule, ToJsModule}; -use rspack_error::internal_error; use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode}; use rspack_napi_shared::{get_napi_env, JsRegExp, JsRegExpExt, NapiResultExt}; use rspack_plugin_split_chunks_new::{CacheGroupTest, CacheGroupTestFnCtx}; diff --git a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs index fab1bf4c0cab..28f164881450 100644 --- a/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs +++ b/crates/rspack_binding_options/src/options/raw_split_chunks/raw_split_chunk_name.rs @@ -4,7 +4,6 @@ use napi::bindgen_prelude::Either3; use napi::{Env, JsFunction}; use napi_derive::napi; use rspack_binding_values::{JsModule, ToJsModule}; -use rspack_error::internal_error; use rspack_napi_shared::threadsafe_function::{ThreadsafeFunction, ThreadsafeFunctionCallMode}; use rspack_napi_shared::{get_napi_env, NapiResultExt}; use rspack_plugin_split_chunks_new::{ChunkNameGetter, ChunkNameGetterFnCtx}; diff --git a/crates/rspack_core/src/code_generation_results.rs b/crates/rspack_core/src/code_generation_results.rs index 5d181049d012..4fdd02c0d8e6 100644 --- a/crates/rspack_core/src/code_generation_results.rs +++ b/crates/rspack_core/src/code_generation_results.rs @@ -4,7 +4,6 @@ use std::ops::{Deref, DerefMut}; use std::sync::atomic::AtomicU32; use anymap::CloneAny; -use rspack_error::{internal_error, Result}; use rspack_hash::{HashDigest, HashFunction, HashSalt, RspackHash, RspackHashDigest}; use rspack_identifier::IdentifierMap; use rspack_sources::BoxSource; @@ -182,7 +181,7 @@ impl CodeGenerationResults { &self, module_identifier: &ModuleIdentifier, runtime: Option<&RuntimeSpec>, - ) -> Result<&CodeGenerationResult> { + ) -> &CodeGenerationResult { if let Some(entry) = self.map.get(module_identifier) { if let Some(runtime) = runtime { entry @@ -190,8 +189,8 @@ impl CodeGenerationResults { .and_then(|m| { self.module_generation_result_map.get(m) }) - .ok_or_else(|| { - internal_error!( + .unwrap_or_else(|| { + panic!( "Failed to code generation result for {module_identifier} with runtime {runtime:?} \n {entry:?}" ) }) @@ -199,16 +198,16 @@ impl CodeGenerationResults { if entry.size() > 1 { let results = entry.get_values(); if results.len() != 1 { - return Err(internal_error!( + panic!( "No unique code generation entry for unspecified runtime for {module_identifier} ", - )); + ); } return results .first() .copied() .and_then(|m| self.module_generation_result_map.get(m)) - .ok_or_else(|| internal_error!("Expected value exists")); + .unwrap_or_else(|| panic!("Expected value exists")); } entry @@ -216,14 +215,14 @@ impl CodeGenerationResults { .first() .copied() .and_then(|m| self.module_generation_result_map.get(m)) - .ok_or_else(|| internal_error!("Expected value exists")) + .unwrap_or_else(|| panic!("Expected value exists")) } } else { - Err(internal_error!( + panic!( "No code generation entry for {} (existing entries: {:?})", module_identifier, self.map.keys().collect::>() - )) + ) } } @@ -250,13 +249,7 @@ impl CodeGenerationResults { module_identifier: &ModuleIdentifier, runtime: Option<&RuntimeSpec>, ) -> RuntimeGlobals { - match self.get(module_identifier, runtime) { - Ok(result) => result.runtime_requirements, - Err(_) => { - eprintln!("Failed to get runtime requirements for {module_identifier}"); - Default::default() - } - } + self.get(module_identifier, runtime).runtime_requirements } #[allow(clippy::unwrap_in_result)] @@ -265,9 +258,7 @@ impl CodeGenerationResults { module_identifier: &ModuleIdentifier, runtime: Option<&RuntimeSpec>, ) -> Option<&RspackHashDigest> { - let code_generation_result = self - .get(module_identifier, runtime) - .expect("should have code generation result"); + let code_generation_result = self.get(module_identifier, runtime); code_generation_result.hash.as_ref() } diff --git a/crates/rspack_core/src/context_module.rs b/crates/rspack_core/src/context_module.rs index 9d77f072c362..0495b8870c9b 100644 --- a/crates/rspack_core/src/context_module.rs +++ b/crates/rspack_core/src/context_module.rs @@ -360,18 +360,18 @@ impl ContextModule { } #[inline] - fn get_source_string(&self, compilation: &Compilation) -> Result { + fn get_source_string(&self, compilation: &Compilation) -> BoxSource { match self.options.context_options.mode { - ContextMode::Lazy => Ok(self.get_lazy_source(compilation)), + ContextMode::Lazy => self.get_lazy_source(compilation), ContextMode::LazyOnce => { let block = self .get_blocks() .first() - .ok_or_else(|| internal_error!("LazyOnce ContextModule should have first block"))?; + .expect("LazyOnce ContextModule should have first block"); let block = compilation .module_graph .block_by_id(block) - .ok_or_else(|| internal_error!("should have block"))?; + .expect("should have block"); self.generate_source(block.get_dependencies(), compilation) } _ => self.generate_source(self.get_dependencies(), compilation), @@ -430,11 +430,7 @@ impl ContextModule { source.boxed() } - fn generate_source( - &self, - dependencies: &[DependencyId], - compilation: &Compilation, - ) -> Result { + fn generate_source(&self, dependencies: &[DependencyId], compilation: &Compilation) -> BoxSource { let map = self.get_user_request_map(dependencies, compilation); let fake_map = self.get_fake_map(dependencies, compilation); let mode = &self.options.context_options.mode; @@ -522,7 +518,7 @@ impl ContextModule { source.add(RawSource::from(format!( "webpackContext.id = '{}';\n", serde_json::to_string(self.id(&compilation.chunk_graph)) - .map_err(|e| internal_error!(e.to_string()))? + .unwrap_or_else(|e| panic!("{}", e.to_string())) ))); source.add(RawSource::from( r#" @@ -533,7 +529,7 @@ impl ContextModule { module.exports = webpackContext; "#, )); - Ok(source.boxed()) + source.boxed() } } @@ -640,7 +636,7 @@ impl Module for ContextModule { let block = compilation .module_graph .block_by_id(block) - .ok_or_else(|| internal_error!("should have block in ContextModule code_generation"))?; + .expect("should have block in ContextModule code_generation"); all_deps.extend(block.get_dependencies()); } let fake_map = self.get_fake_map(all_deps.iter(), compilation); @@ -649,7 +645,7 @@ impl Module for ContextModule { .runtime_requirements .insert(RuntimeGlobals::CREATE_FAKE_NAMESPACE_OBJECT); } - code_generation_result.add(SourceType::JavaScript, self.get_source_string(compilation)?); + code_generation_result.add(SourceType::JavaScript, self.get_source_string(compilation)); code_generation_result.set_hash( &compilation.options.output.hash_function, &compilation.options.output.hash_digest, diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index 9ea767754f46..025b9786459b 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -3,7 +3,7 @@ use std::collections::hash_map::Entry; use std::path::PathBuf; use dashmap::DashMap; -use rspack_error::{internal_error, Result}; +use rspack_error::Result; use rspack_hash::RspackHashDigest; use rspack_identifier::{Identifiable, IdentifierMap}; use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet}; @@ -230,11 +230,11 @@ impl ModuleGraph { { let mgm = self .module_graph_module_by_identifier_mut(&module_identifier) - .ok_or_else(|| { - internal_error!( + .unwrap_or_else(|| { + panic!( "Failed to set resolved module: Module linked to module identifier {module_identifier} cannot be found" ) - })?; + }); mgm.add_incoming_connection(connection_id); } diff --git a/crates/rspack_core/src/module_graph_module.rs b/crates/rspack_core/src/module_graph_module.rs index 85ec0e47899b..bcceb54bfde7 100644 --- a/crates/rspack_core/src/module_graph_module.rs +++ b/crates/rspack_core/src/module_graph_module.rs @@ -1,4 +1,4 @@ -use rspack_error::{internal_error, Result}; +use rspack_error::Result; use rustc_hash::FxHashSet as HashSet; use crate::ExportsInfoId; @@ -83,13 +83,11 @@ impl ModuleGraphModule { .map(|connection_id| { module_graph .connection_by_connection_id(connection_id) - .ok_or_else(|| { - internal_error!( - "connection_id_to_connection does not have connection_id: {connection_id:?}" - ) + .unwrap_or_else(|| { + panic!("connection_id_to_connection does not have connection_id: {connection_id:?}") }) }) - .collect::>>()? + .collect::>() .into_iter(); Ok(result) @@ -105,13 +103,11 @@ impl ModuleGraphModule { .map(|connection_id| { module_graph .connection_by_connection_id(connection_id) - .ok_or_else(|| { - internal_error!( - "connection_id_to_connection does not have connection_id: {connection_id:?}" - ) + .unwrap_or_else(|| { + panic!("connection_id_to_connection does not have connection_id: {connection_id:?}") }) }) - .collect::>>()? + .collect::>() .into_iter(); Ok(result) diff --git a/crates/rspack_loader_react_refresh/src/lib.rs b/crates/rspack_loader_react_refresh/src/lib.rs index 4a52e09909ec..db5901b79fc3 100644 --- a/crates/rspack_loader_react_refresh/src/lib.rs +++ b/crates/rspack_loader_react_refresh/src/lib.rs @@ -1,5 +1,5 @@ use rspack_core::LoaderRunnerContext; -use rspack_error::{internal_error, Result}; +use rspack_error::Result; use rspack_loader_runner::{Identifiable, Identifier, Loader, LoaderContext}; pub struct ReactRefreshLoader { @@ -27,9 +27,7 @@ impl ReactRefreshLoader { #[async_trait::async_trait] impl Loader for ReactRefreshLoader { async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { - let Some(content) = std::mem::take(&mut loader_context.content) else { - return Err(internal_error!("Content should be available")); - }; + let content = std::mem::take(&mut loader_context.content).expect("Content should be available"); let mut source = content.try_into_string()?; source += r#" function $RefreshSig$() { diff --git a/crates/rspack_loader_runner/src/runner.rs b/crates/rspack_loader_runner/src/runner.rs index dd8106b0a470..5d75124f33a2 100644 --- a/crates/rspack_loader_runner/src/runner.rs +++ b/crates/rspack_loader_runner/src/runner.rs @@ -378,7 +378,7 @@ impl TryFrom> for TWithDiagnosticArray { let loader = loader_context.__loader_items[0].to_string(); internal_error!("Final loader({loader}) didn't return a Buffer or String") } else { - internal_error!("Content is not available, it is a bug") + panic!("content should be available"); } })?; diff --git a/crates/rspack_loader_sass/src/lib.rs b/crates/rspack_loader_sass/src/lib.rs index 4192d4928a13..48247d14904d 100644 --- a/crates/rspack_loader_sass/src/lib.rs +++ b/crates/rspack_loader_sass/src/lib.rs @@ -486,23 +486,20 @@ impl Loader for SassLoader { })? .render(sass_options) .map_err(sass_exception_to_error)?; - let source_map = result - .map - .map(|map| -> Result { - let mut map = SourceMap::from_slice(&map).map_err(|e| internal_error!(e.to_string()))?; - for source in map.sources_mut() { - if source.starts_with("file:") { - *source = Url::parse(source) - .expect("TODO:") - .to_file_path() - .expect("TODO:") - .display() - .to_string(); - } + let source_map = result.map.map(|map| { + let mut map = SourceMap::from_slice(&map).expect("should be able to generate source-map"); + for source in map.sources_mut() { + if source.starts_with("file:") { + *source = Url::parse(source) + .expect("TODO:") + .to_file_path() + .expect("TODO:") + .display() + .to_string(); } - Ok(map) - }) - .transpose()?; + } + map + }); loader_context.content = Some(result.css.into()); loader_context.source_map = source_map; diff --git a/crates/rspack_loader_swc/src/lib.rs b/crates/rspack_loader_swc/src/lib.rs index cbabcdf0e358..f1e38fa7eb8a 100644 --- a/crates/rspack_loader_swc/src/lib.rs +++ b/crates/rspack_loader_swc/src/lib.rs @@ -47,9 +47,7 @@ pub const SWC_LOADER_IDENTIFIER: &str = "builtin:swc-loader"; impl Loader for SwcLoader { async fn run(&self, loader_context: &mut LoaderContext<'_, LoaderRunnerContext>) -> Result<()> { let resource_path = loader_context.resource_path.to_path_buf(); - let Some(content) = std::mem::take(&mut loader_context.content) else { - return Err(internal_error!("Content should be available")); - }; + let content = std::mem::take(&mut loader_context.content).expect("content should be available"); let swc_options = { let mut swc_options = self.options_with_additional.swc_options.clone(); diff --git a/crates/rspack_plugin_asset/src/lib.rs b/crates/rspack_plugin_asset/src/lib.rs index 3c57817f503c..7347300f59ef 100644 --- a/crates/rspack_plugin_asset/src/lib.rs +++ b/crates/rspack_plugin_asset/src/lib.rs @@ -536,7 +536,7 @@ impl Plugin for AssetPlugin { .map(|m| { let code_gen_result = compilation .code_generation_results - .get(&m.identifier(), Some(&chunk.runtime))?; + .get(&m.identifier(), Some(&chunk.runtime)); let result = code_gen_result.get(&SourceType::Asset).map(|source| { let asset_filename = code_gen_result diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index 3ba8f221a97e..88294a205fb9 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -15,7 +15,7 @@ use rspack_core::{ ParseContext, ParseResult, ParserAndGenerator, SourceType, TemplateContext, }; use rspack_core::{ModuleInitFragments, RuntimeGlobals}; -use rspack_error::{internal_error, IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; +use rspack_error::{IntoTWithDiagnosticArray, Result, TWithDiagnosticArray}; use rustc_hash::FxHashSet; use sugar_path::SugarPath; use swc_core::{css::parser::parser::ParserConfig, ecma::atoms::JsWord}; @@ -201,7 +201,7 @@ impl ParserAndGenerator for CssParserAndGenerator { value: source_code, name: module_user_request, source_map: SourceMap::from_slice(&source_map) - .map_err(|e| internal_error!(e.to_string()))?, + .expect("should be able to generate source-map"), // Safety: original source exists in code generation original_source: Some(source.source().to_string()), // Safety: original source exists in code generation @@ -280,13 +280,13 @@ impl ParserAndGenerator for CssParserAndGenerator { .insert(RuntimeGlobals::MODULE); Ok(RawSource::from(locals).boxed()) } - _ => Err(internal_error!( + _ => unreachable!( "Unsupported source type: {:?}", generate_context.requested_source_type - )), - }?; + ), + }; - Ok(result) + result } fn store(&self, extra_data: &mut HashMap) { let data = self.exports.to_owned(); diff --git a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs index 8d08c826120b..90700a163c5d 100644 --- a/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs +++ b/crates/rspack_plugin_css/src/plugin/impl_plugin_for_css_plugin.rs @@ -37,7 +37,7 @@ impl CssPlugin { let module_id = &module.identifier(); let code_gen_result = compilation .code_generation_results - .get(module_id, Some(&chunk.runtime))?; + .get(module_id, Some(&chunk.runtime)); Ok( code_gen_result diff --git a/crates/rspack_plugin_css/src/swc_css_compiler.rs b/crates/rspack_plugin_css/src/swc_css_compiler.rs index 5d16efad309a..65a43ce7121e 100644 --- a/crates/rspack_plugin_css/src/swc_css_compiler.rs +++ b/crates/rspack_plugin_css/src/swc_css_compiler.rs @@ -94,7 +94,7 @@ impl SwcCssCompiler { value: code, name: filename, source_map: rspack_sources::SourceMap::from_slice(&source_map) - .map_err(|e| internal_error!(e.to_string()))?, + .expect("should be able to generate source-map"), original_source: Some(input_source), inner_source_map: input_source_map, remove_original_source: true, diff --git a/crates/rspack_plugin_devtool/src/lib.rs b/crates/rspack_plugin_devtool/src/lib.rs index 84f7b35a8347..77e3e806cb76 100644 --- a/crates/rspack_plugin_devtool/src/lib.rs +++ b/crates/rspack_plugin_devtool/src/lib.rs @@ -137,7 +137,7 @@ impl Plugin for DevtoolPlugin { let mut map_buffer = Vec::new(); map .to_writer(&mut map_buffer) - .map_err(|e| internal_error!(e.to_string()))?; + .unwrap_or_else(|e| panic!("{}", e.to_string())); Ok::, Error>(map_buffer) }) .transpose()?; @@ -284,7 +284,7 @@ pub fn wrap_eval_source_map( let mut map_buffer = Vec::new(); map .to_writer(&mut map_buffer) - .map_err(|e| internal_error!(e.to_string()))?; + .unwrap_or_else(|e| panic!("{}", e.to_string())); let base64 = rspack_base64::encode_to_string(&map_buffer); let footer = format!("\n//# sourceMappingURL=data:application/json;charset=utf-8;base64,{base64}"); diff --git a/crates/rspack_plugin_javascript/src/ast/stringify.rs b/crates/rspack_plugin_javascript/src/ast/stringify.rs index 952b0a7163d9..f96d040f71e2 100644 --- a/crates/rspack_plugin_javascript/src/ast/stringify.rs +++ b/crates/rspack_plugin_javascript/src/ast/stringify.rs @@ -126,7 +126,7 @@ pub fn print( source_map .build_source_map_with_config(&src_map_buf, None, source_map_config) .to_writer(&mut buf) - .map_err(|e| internal_error!(e.to_string()))?; + .unwrap_or_else(|e| panic!("{}", e.to_string())); // SAFETY: This buffer is already sanitized Some(unsafe { String::from_utf8_unchecked(buf) }) } else { diff --git a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs index 72872a8910ea..6906094b565b 100644 --- a/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_javascript/src/parser_and_generator/mod.rs @@ -256,7 +256,7 @@ impl ParserAndGenerator for JavaScriptParserAndGenerator { SourceMapSource::new(SourceMapSourceOptions { value: output.code, name: resource_data.resource_path.to_string_lossy().to_string(), - source_map: SourceMap::from_json(&map).map_err(|e| internal_error!(e.to_string()))?, + source_map: SourceMap::from_json(&map).unwrap_or_else(|e| panic!("{}", e.to_string())), inner_source_map: use_source_map.then_some(original_map).flatten(), remove_original_source: true, ..Default::default() diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 8d3170023726..640ca7b09082 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -34,8 +34,7 @@ pub fn render_chunk_modules( .filter_map(|mgm| { let code_gen_result = compilation .code_generation_results - .get(&mgm.module_identifier, Some(&chunk.runtime)) - .expect("should have code generation result"); + .get(&mgm.module_identifier, Some(&chunk.runtime)); if let Some(origin_source) = code_gen_result.get(&SourceType::JavaScript) { let render_module_result = plugin_driver .render_module_content(RenderModuleContentArgs { diff --git a/crates/rspack_plugin_json/src/lib.rs b/crates/rspack_plugin_json/src/lib.rs index 128e52481576..8fc4704cb02a 100644 --- a/crates/rspack_plugin_json/src/lib.rs +++ b/crates/rspack_plugin_json/src/lib.rs @@ -129,10 +129,10 @@ impl ParserAndGenerator for JsonParserAndGenerator { .boxed(), ) } - _ => Err(internal_error!(format!( + _ => unreachable!( "Unsupported source type {:?} for plugin Json", generate_context.requested_source_type, - ))), + ), } } } diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs index b332e5c0cf4d..61238fc172a1 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs @@ -49,11 +49,10 @@ impl RuntimeModule for ConsumeSharedRuntimeModule { .clone() .expect("should have moduleId at ::generate"); ids.push(id.clone()); - if let Ok(code_gen) = compilation + let code_gen = compilation .code_generation_results - .get(&module, Some(&chunk.runtime)) - && let Some(data) = code_gen.data.get::() - { + .get(&module, Some(&chunk.runtime)); + if let Some(data) = code_gen.data.get::() { module_id_to_consume_data_mapping.insert(id, format!( "{{ shareScope: {}, shareKey: {}, import: {}, requiredVersion: {}, strictVersion: {}, singleton: {}, eager: {}, fallback: {} }}", json_stringify(&data.share_scope), diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 7ea990480157..271fe156b42e 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -53,7 +53,7 @@ impl RuntimeModule for ShareRuntimeModule { for m in modules { let code_gen = compilation .code_generation_results - .get(&m.identifier(), Some(&chunk.runtime)).expect("should have code_generation_result of share-init sourceType module at ::generate"); + .get(&m.identifier(), Some(&chunk.runtime)); let Some(data) = code_gen.data.get::() else { continue; }; diff --git a/crates/rspack_plugin_runtime/src/module_chunk_format.rs b/crates/rspack_plugin_runtime/src/module_chunk_format.rs index a9d869a80621..2db90423e576 100644 --- a/crates/rspack_plugin_runtime/src/module_chunk_format.rs +++ b/crates/rspack_plugin_runtime/src/module_chunk_format.rs @@ -7,7 +7,6 @@ use rspack_core::{ PluginAdditionalChunkRuntimeRequirementsOutput, PluginContext, PluginJsChunkHashHookOutput, PluginRenderChunkHookOutput, RenderChunkArgs, RenderStartupArgs, RuntimeGlobals, }; -use rspack_error::internal_error; use rspack_plugin_javascript::runtime::render_chunk_runtime_modules; use rustc_hash::FxHashSet as HashSet; @@ -91,9 +90,7 @@ impl Plugin for ModuleChunkFormatPlugin { let chunk = args.chunk(); let base_chunk_output_name = get_chunk_output_name(chunk, compilation); if matches!(chunk.kind, ChunkKind::HotUpdate) { - return Err(internal_error!( - "HMR is not implemented for module chunk format yet" - )); + unreachable!("HMR is not implemented for module chunk format yet"); } let mut sources = ConcatSource::default(); diff --git a/crates/rspack_plugin_swc_js_minimizer/src/lib.rs b/crates/rspack_plugin_swc_js_minimizer/src/lib.rs index 5fa079bc4e3e..fd44bf4370d9 100644 --- a/crates/rspack_plugin_swc_js_minimizer/src/lib.rs +++ b/crates/rspack_plugin_swc_js_minimizer/src/lib.rs @@ -223,7 +223,7 @@ impl Plugin for SwcJsMinimizerRspackPlugin { SourceMapSource::new(SourceMapSourceOptions { value: output.code, name: filename, - source_map: SourceMap::from_json(map).map_err(|e| internal_error!(e.to_string()))?, + source_map: SourceMap::from_json(map).expect("should be able to generate source-map"), original_source: None, inner_source_map: input_source_map, remove_original_source: true, diff --git a/crates/rspack_plugin_wasm/src/wasm_plugin.rs b/crates/rspack_plugin_wasm/src/wasm_plugin.rs index 8f8f6441fe4e..d3334724a94b 100644 --- a/crates/rspack_plugin_wasm/src/wasm_plugin.rs +++ b/crates/rspack_plugin_wasm/src/wasm_plugin.rs @@ -92,7 +92,7 @@ impl Plugin for AsyncWasmPlugin { .map(|m| { let code_gen_result = compilation .code_generation_results - .get(&m.identifier(), Some(&chunk.runtime))?; + .get(&m.identifier(), Some(&chunk.runtime)); let result = code_gen_result.get(&SourceType::Wasm).map(|source| { let (output_path, asset_info) = self