Skip to content

Commit

Permalink
feat(estree/compat): Remove dependency on rayon (#9393)
Browse files Browse the repository at this point in the history
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
  • Loading branch information
dsherret and kdy1 committed Aug 12, 2024
1 parent 1bf467d commit 34d1b27
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 24 deletions.
6 changes: 6 additions & 0 deletions .changeset/fresh-windows-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_estree_compat: patch
swc_core: patch
---

feat(estree/compat): Add concurrent feature
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/swc_estree_compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ version = "0.208.0"
[lib]
bench = false

[features]

[dependencies]
ahash = { workspace = true, features = ["compile-time-rng"] }
anyhow = { workspace = true }
copyless = { workspace = true }
rayon = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }

swc_atoms = { version = "0.6.5", path = "../swc_atoms" }
swc_common = { version = "0.37.0", path = "../swc_common", features = [
"concurrent",
"sourcemap",
"tty-emitter",
] }
Expand Down
15 changes: 2 additions & 13 deletions crates/swc_estree_compat/src/babelify/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
use std::sync::Arc;

use rayon::prelude::*;
use serde::{de::DeserializeOwned, Serialize};
use swc_common::{
comments::{CommentKind, Comments},
Expand Down Expand Up @@ -28,7 +25,7 @@ mod typescript;

#[derive(Clone)]
pub struct Context {
pub fm: Arc<SourceFile>,
pub fm: Lrc<SourceFile>,
pub cm: Lrc<SourceMap>,
pub comments: SwcComments,
}
Expand Down Expand Up @@ -150,15 +147,7 @@ where
type Output = Vec<T::Output>;

fn babelify(self, ctx: &Context) -> Self::Output {
if T::parallel(self.len()) {
let flavor = Flavor::current();

self.into_par_iter()
.map(|v| flavor.with(|| v.babelify(ctx)))
.collect()
} else {
self.into_iter().map(|v| v.babelify(ctx)).collect()
}
self.into_iter().map(|v| v.babelify(ctx)).collect()
}
}

Expand Down
14 changes: 6 additions & 8 deletions crates/swc_estree_compat/src/swcify/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use std::sync::Arc;

use swc_common::{BytePos, FileName, SourceFile, SourceMap, Span, DUMMY_SP};
use swc_common::{sync::Lrc, BytePos, FileName, SourceFile, SourceMap, Span, DUMMY_SP};
use swc_estree_ast::{BaseNode, LineCol, Loc};
use swc_node_comments::SwcComments;

pub struct Context {
#[allow(unused)]
pub(crate) cm: Arc<SourceMap>,
pub(crate) fm: Arc<SourceFile>,
pub(crate) cm: Lrc<SourceMap>,
pub(crate) fm: Lrc<SourceFile>,
#[allow(unused)]
pub(crate) comments: SwcComments,
}
Expand Down Expand Up @@ -57,15 +55,15 @@ impl Context {
/// stored as interned.
///
/// This method allocate a new [SourceFile] in the given `cm`.
pub fn new(cm: Arc<SourceMap>, comments: SwcComments, filename: FileName, src: String) -> Self {
pub fn new(cm: Lrc<SourceMap>, comments: SwcComments, filename: FileName, src: String) -> Self {
let fm = cm.new_source_file(filename.into(), src);
Self::new_without_alloc(cm, comments, fm)
}

pub fn new_without_alloc(
cm: Arc<SourceMap>,
cm: Lrc<SourceMap>,
comments: SwcComments,
fm: Arc<SourceFile>,
fm: Lrc<SourceFile>,
) -> Self {
Self { cm, comments, fm }
}
Expand Down

0 comments on commit 34d1b27

Please sign in to comment.