Skip to content

Commit

Permalink
fix ident
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunisher committed Oct 12, 2024
1 parent dd1b3be commit a0bc2b2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions crates/rspack_binding_options/src/plugins/js_loader/resolver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::sync::{Arc, LazyLock};
use std::{
borrow::Cow,
sync::{Arc, LazyLock},
};

use rspack_collections::{Identifiable, Identifier};
use rspack_core::{
Expand Down Expand Up @@ -42,13 +45,17 @@ pub fn serde_error_to_miette(
miette!(labels = vec![span], "{msg}").with_source_code(content.clone())
}

static SWC_LOADER_CACHE: LazyLock<RwLock<FxHashMap<String, Arc<SwcLoader>>>> =
static SWC_LOADER_CACHE: LazyLock<RwLock<FxHashMap<(Cow<str>, Arc<str>), Arc<SwcLoader>>>> =

Check failure on line 48 in crates/rspack_binding_options/src/plugins/js_loader/resolver.rs

View workflow job for this annotation

GitHub Actions / Rust check

very complex type used. Consider factoring parts into `type` definitions
LazyLock::new(|| RwLock::new(FxHashMap::default()));

pub async fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<BoxLoader> {
let options: Arc<str> = options.unwrap_or("{}").into();
if builtin.starts_with(SWC_LOADER_IDENTIFIER) {
if let Some(loader) = SWC_LOADER_CACHE.read().await.get(options.as_ref()) {
if let Some(loader) = SWC_LOADER_CACHE
.read()
.await
.get(&(Cow::Borrowed(builtin), options.clone()))
{
return Ok(loader.clone());
}

Expand All @@ -63,10 +70,10 @@ pub async fn get_builtin_loader(builtin: &str, options: Option<&str>) -> Result<
.with_identifier(builtin.into()),
);

SWC_LOADER_CACHE
.write()
.await
.insert(options.to_string(), loader.clone());
SWC_LOADER_CACHE.write().await.insert(
(Cow::Owned(builtin.to_owned()), options.clone()),
loader.clone(),
);
return Ok(loader);
}

Expand Down

0 comments on commit a0bc2b2

Please sign in to comment.