Skip to content

Commit 34d1b27

Browse files
dsherretkdy1
andauthoredAug 12, 2024··
feat(estree/compat): Remove dependency on rayon (#9393)
Co-authored-by: Donny/강동윤 <kdy1997.dev@gmail.com>
1 parent 1bf467d commit 34d1b27

File tree

5 files changed

+16
-24
lines changed

5 files changed

+16
-24
lines changed
 

‎.changeset/fresh-windows-kick.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
swc_estree_compat: patch
3+
swc_core: patch
4+
---
5+
6+
feat(estree/compat): Add concurrent feature

‎Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/swc_estree_compat/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ version = "0.208.0"
1515
[lib]
1616
bench = false
1717

18+
[features]
19+
1820
[dependencies]
1921
ahash = { workspace = true, features = ["compile-time-rng"] }
2022
anyhow = { workspace = true }
2123
copyless = { workspace = true }
22-
rayon = { workspace = true }
2324
serde = { workspace = true, features = ["derive"] }
2425
serde_json = { workspace = true }
2526

2627
swc_atoms = { version = "0.6.5", path = "../swc_atoms" }
2728
swc_common = { version = "0.37.0", path = "../swc_common", features = [
28-
"concurrent",
2929
"sourcemap",
3030
"tty-emitter",
3131
] }

‎crates/swc_estree_compat/src/babelify/mod.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
use std::sync::Arc;
2-
3-
use rayon::prelude::*;
41
use serde::{de::DeserializeOwned, Serialize};
52
use swc_common::{
63
comments::{CommentKind, Comments},
@@ -28,7 +25,7 @@ mod typescript;
2825

2926
#[derive(Clone)]
3027
pub struct Context {
31-
pub fm: Arc<SourceFile>,
28+
pub fm: Lrc<SourceFile>,
3229
pub cm: Lrc<SourceMap>,
3330
pub comments: SwcComments,
3431
}
@@ -150,15 +147,7 @@ where
150147
type Output = Vec<T::Output>;
151148

152149
fn babelify(self, ctx: &Context) -> Self::Output {
153-
if T::parallel(self.len()) {
154-
let flavor = Flavor::current();
155-
156-
self.into_par_iter()
157-
.map(|v| flavor.with(|| v.babelify(ctx)))
158-
.collect()
159-
} else {
160-
self.into_iter().map(|v| v.babelify(ctx)).collect()
161-
}
150+
self.into_iter().map(|v| v.babelify(ctx)).collect()
162151
}
163152
}
164153

‎crates/swc_estree_compat/src/swcify/ctx.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
use std::sync::Arc;
2-
3-
use swc_common::{BytePos, FileName, SourceFile, SourceMap, Span, DUMMY_SP};
1+
use swc_common::{sync::Lrc, BytePos, FileName, SourceFile, SourceMap, Span, DUMMY_SP};
42
use swc_estree_ast::{BaseNode, LineCol, Loc};
53
use swc_node_comments::SwcComments;
64

75
pub struct Context {
86
#[allow(unused)]
9-
pub(crate) cm: Arc<SourceMap>,
10-
pub(crate) fm: Arc<SourceFile>,
7+
pub(crate) cm: Lrc<SourceMap>,
8+
pub(crate) fm: Lrc<SourceFile>,
119
#[allow(unused)]
1210
pub(crate) comments: SwcComments,
1311
}
@@ -57,15 +55,15 @@ impl Context {
5755
/// stored as interned.
5856
///
5957
/// This method allocate a new [SourceFile] in the given `cm`.
60-
pub fn new(cm: Arc<SourceMap>, comments: SwcComments, filename: FileName, src: String) -> Self {
58+
pub fn new(cm: Lrc<SourceMap>, comments: SwcComments, filename: FileName, src: String) -> Self {
6159
let fm = cm.new_source_file(filename.into(), src);
6260
Self::new_without_alloc(cm, comments, fm)
6361
}
6462

6563
pub fn new_without_alloc(
66-
cm: Arc<SourceMap>,
64+
cm: Lrc<SourceMap>,
6765
comments: SwcComments,
68-
fm: Arc<SourceFile>,
66+
fm: Lrc<SourceFile>,
6967
) -> Self {
7068
Self { cm, comments, fm }
7169
}

0 commit comments

Comments
 (0)
Please sign in to comment.