rspack_plugin_wasm 0.102.3

rspack wasm plugin
Documentation
use rspack_cacheable::{cacheable, cacheable_dyn, with::AsPreset};
use rspack_core::{
  AsContextDependency, AsDependencyCodeGeneration, Dependency, DependencyCategory, DependencyId,
  DependencyRange, DependencyType, ExportsInfoArtifact, ModuleDependency, ModuleGraph,
  ModuleGraphCacheArtifact, ReferencedExport, RuntimeSpec,
};
use rspack_intern::Atom;

#[allow(dead_code)]
#[cacheable]
#[derive(Debug)]
pub struct WasmImportDependency {
  id: DependencyId,
  #[cacheable(with=AsPreset)]
  name: Atom,
  request: String,
  // only_direct_import: bool,
  span: Option<DependencyRange>,
}

impl WasmImportDependency {
  pub fn new(request: String, name: String) -> Self {
    Self {
      id: DependencyId::new(),
      name: name.into(),
      request,
      // only_direct_import,
      span: None,
    }
  }

  pub fn name(&self) -> &Atom {
    &self.name
  }
}

#[cacheable_dyn]
impl Dependency for WasmImportDependency {
  fn id(&self) -> &DependencyId {
    &self.id
  }

  fn category(&self) -> &DependencyCategory {
    &DependencyCategory::Wasm
  }

  fn dependency_type(&self) -> &DependencyType {
    &DependencyType::WasmImport
  }

  fn get_referenced_exports(
    &self,
    _module_graph: &ModuleGraph,
    _module_graph_cache: &ModuleGraphCacheArtifact,
    _exports_info_artifact: &ExportsInfoArtifact,
    _runtime: Option<&RuntimeSpec>,
  ) -> Vec<ReferencedExport> {
    vec![ReferencedExport::from(&self.name)]
  }

  fn could_affect_referencing_module(&self) -> rspack_core::AffectType {
    rspack_core::AffectType::True
  }
}

#[cacheable_dyn]
impl ModuleDependency for WasmImportDependency {
  fn request(&self) -> &str {
    &self.request
  }

  fn user_request(&self) -> &str {
    &self.request
  }
}

impl AsDependencyCodeGeneration for WasmImportDependency {}

impl AsContextDependency for WasmImportDependency {}