diff --git a/crates/rspack_core/src/compiler/queue.rs b/crates/rspack_core/src/compiler/queue.rs index 88e99da58cc..46b02864179 100644 --- a/crates/rspack_core/src/compiler/queue.rs +++ b/crates/rspack_core/src/compiler/queue.rs @@ -257,7 +257,7 @@ impl WorkerTask for BuildTask { compiler_context: CompilerContext { options: compiler_options.clone(), resolver_factory: resolver_factory.clone(), - module: Some(module.identifier()), + module: module.identifier(), module_context: module.as_normal_module().and_then(|m| m.get_context()), }, plugin_driver: plugin_driver.clone(), diff --git a/crates/rspack_core/src/loader/loader_runner.rs b/crates/rspack_core/src/loader/loader_runner.rs index 9c19306137d..81bfc959593 100644 --- a/crates/rspack_core/src/loader/loader_runner.rs +++ b/crates/rspack_core/src/loader/loader_runner.rs @@ -8,7 +8,7 @@ use crate::{CompilerOptions, Context, ModuleIdentifier, ResolverFactory}; pub struct CompilerContext { pub options: Arc, pub resolver_factory: Arc, - pub module: Option, // current module + pub module: ModuleIdentifier, // current module pub module_context: Option>, // current module context } diff --git a/crates/rspack_core/src/module.rs b/crates/rspack_core/src/module.rs index 6d7e104cb40..5d0386b9f36 100644 --- a/crates/rspack_core/src/module.rs +++ b/crates/rspack_core/src/module.rs @@ -341,7 +341,7 @@ mod test { use std::borrow::Cow; use std::hash::Hash; - use rspack_error::{Result, TWithDiagnosticArray}; + use rspack_error::{Diagnosable, Result, TWithDiagnosticArray}; use rspack_identifier::{Identifiable, Identifier}; use rspack_sources::Source; @@ -389,6 +389,8 @@ mod test { } } + impl Diagnosable for $ident {} + impl DependenciesBlock for $ident { fn add_block_id(&mut self, _: AsyncDependenciesBlockIdentifier) { unreachable!() diff --git a/crates/rspack_core/src/module_graph/mod.rs b/crates/rspack_core/src/module_graph/mod.rs index d45b950909e..4169a094b59 100644 --- a/crates/rspack_core/src/module_graph/mod.rs +++ b/crates/rspack_core/src/module_graph/mod.rs @@ -770,7 +770,7 @@ impl ModuleGraph { mod test { use std::borrow::Cow; - use rspack_error::{Result, TWithDiagnosticArray}; + use rspack_error::{Diagnosable, Result, TWithDiagnosticArray}; use rspack_identifier::Identifiable; use rspack_sources::Source; @@ -793,6 +793,8 @@ mod test { } } + impl Diagnosable for $ident {} + impl DependenciesBlock for $ident { fn add_block_id(&mut self, _: AsyncDependenciesBlockIdentifier) { unreachable!() diff --git a/crates/rspack_core/src/normal_module.rs b/crates/rspack_core/src/normal_module.rs index ef33fe5b4fb..354dd29125a 100644 --- a/crates/rspack_core/src/normal_module.rs +++ b/crates/rspack_core/src/normal_module.rs @@ -586,15 +586,28 @@ impl Module for NormalModule { impl Diagnosable for NormalModule { fn add_diagnostic(&self, diagnostic: Diagnostic) { - self.diagnostics.lock().unwrap().push(diagnostic); + self + .diagnostics + .lock() + .expect("failed to lock diagnostics") + .push(diagnostic); } fn add_diagnostics(&self, mut diagnostics: Vec) { - self.diagnostics.lock().unwrap().append(&mut diagnostics); + self + .diagnostics + .lock() + .expect("failed to lock diagnostics") + .append(&mut diagnostics); } fn take_diagnostics(&self) -> Vec { - self.diagnostics.lock().unwrap().drain(..).collect() + self + .diagnostics + .lock() + .expect("failed to lock diagnostics") + .drain(..) + .collect() } } diff --git a/crates/rspack_loader_sass/tests/fixtures.rs b/crates/rspack_loader_sass/tests/fixtures.rs index a5418325b27..4ff75e4d8aa 100644 --- a/crates/rspack_loader_sass/tests/fixtures.rs +++ b/crates/rspack_loader_sass/tests/fixtures.rs @@ -96,7 +96,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { profile: false, }), resolver_factory: Default::default(), - module: None, + module: "".into(), module_context: None, }, ) diff --git a/crates/rspack_loader_swc/tests/fixtures.rs b/crates/rspack_loader_swc/tests/fixtures.rs index 7190d4cf3a3..a6a9031712a 100644 --- a/crates/rspack_loader_swc/tests/fixtures.rs +++ b/crates/rspack_loader_swc/tests/fixtures.rs @@ -97,7 +97,7 @@ async fn loader_test(actual: impl AsRef, expected: impl AsRef) { profile: false, }), resolver_factory: Default::default(), - module: None, + module: "".into(), module_context: None, }, )