Skip to content

Commit

Permalink
Update swc_core to 0.104.2 (#42)
Browse files Browse the repository at this point in the history
Co-authored-by: Asakura Mizu <[email protected]>
  • Loading branch information
Thisen and AsakuraMizu authored Nov 28, 2024
1 parent c03a22f commit 8c91121
Show file tree
Hide file tree
Showing 10 changed files with 328 additions and 158 deletions.
383 changes: 287 additions & 96 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
[workspace]
resolver = "2"
members = ["crates/common", "crates/debug_label", "crates/react_refresh"]

members = [
"crates/common",
"crates/debug_label",
"crates/react_refresh",
]
[workspace.dependencies]
swc_core = "0.104.2"

[profile.release]
# This removes more dead code
Expand All @@ -13,4 +12,4 @@ lto = true
# Optimize for size
opt-level = "s"
# Strip debug symbols
strip = "symbols"
strip = "symbols"
2 changes: 1 addition & 1 deletion crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2021"
[dependencies]
serde = "1.0.160"
serde_json = "1.0.96"
swc_core = { version = "0.90.37", features = ["common", "ecma_ast"] }
swc_core = { workspace = true, features = ["common", "ecma_ast"] }
2 changes: 1 addition & 1 deletion crates/common/src/atom_import_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl AtomImportMap {
..
}) => {
if let Expr::Ident(obj) = &**obj {
if let Some(..) = self.namespace_imports.get(&obj.sym) {
if self.namespace_imports.get(&obj.sym).is_some() {
return ATOM_IMPORTS.contains(&&*prop.sym);
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/debug_label/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
common = { path = "../common" }
swc_core = { version = "0.90.37", features = [
swc_core = { workspace = true, features = [
"ecma_ast",
"ecma_parser",
"ecma_utils",
Expand All @@ -20,7 +20,7 @@ swc_core = { version = "0.90.37", features = [
] }

[dev-dependencies]
swc_core = { version = "0.90.37", features = [
swc_core = { workspace = true, features = [
"ecma_plugin_transform",
"ecma_transforms_react",
"testing_transform",
Expand Down
62 changes: 21 additions & 41 deletions crates/debug_label/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use common::{parse_plugin_config, AtomImportMap, Config};
use swc_core::{
common::DUMMY_SP,
common::{util::take::Take, FileName},
common::{util::take::Take, FileName, SyntaxContext, DUMMY_SP},
ecma::{
ast::*,
atoms::JsWord,
Expand All @@ -27,16 +26,8 @@ fn create_debug_label_assign_expr(atom_name_id: Id) -> Expr {
let atom_name = atom_name_id.0.clone();
Expr::Assign(AssignExpr {
left: AssignTarget::Simple(SimpleAssignTarget::Member(MemberExpr {
obj: Box::new(Expr::Ident(Ident {
sym: atom_name_id.0,
span: DUMMY_SP.with_ctxt(atom_name_id.1),
optional: false,
})),
prop: MemberProp::Ident(Ident {
sym: "debugLabel".into(),
span: DUMMY_SP,
optional: false,
}),
obj: Box::new(Expr::Ident(atom_name_id.into())),
prop: MemberProp::Ident("debugLabel".into()),
span: DUMMY_SP,
})),
right: Box::new(Expr::Lit(Lit::Str(Str {
Expand Down Expand Up @@ -72,7 +63,7 @@ impl DebugLabelTransformVisitor {
let stmt = match stmt.try_into_stmt() {
Ok(mut stmt) => {
stmt.visit_mut_with(self);
<T as StmtLike>::from_stmt(stmt)
T::from(stmt)
}
Err(node) => match node.try_into_module_decl() {
Ok(mut module_decl) => {
Expand Down Expand Up @@ -109,40 +100,33 @@ impl DebugLabelTransformVisitor {
};

// Variable declaration
stmts_updated.push(<T as StmtLike>::from_stmt(Stmt::Decl(
Decl::Var(Box::new(VarDecl {
stmts_updated.push(T::from(Stmt::Decl(Decl::Var(Box::new(
VarDecl {
declare: Default::default(),
decls: vec![VarDeclarator {
definite: false,
init: Some(default_export.expr),
name: Pat::Ident(
Ident::new(atom_name.clone(), DUMMY_SP).into(),
),
name: Pat::Ident(atom_name.clone().into()),
span: DUMMY_SP,
}],
kind: VarDeclKind::Const,
span: DUMMY_SP,
})),
)));
// Assign debug label
stmts_updated.push(<T as StmtLike>::from_stmt(Stmt::Expr(
ExprStmt {
span: DUMMY_SP,
expr: Box::new(create_debug_label_assign_expr((
atom_name.clone(),
Default::default(),
))),
ctxt: SyntaxContext::empty(),
},
)));
)))));
// Assign debug label
stmts_updated.push(T::from(Stmt::Expr(ExprStmt {
span: DUMMY_SP,
expr: Box::new(create_debug_label_assign_expr((
atom_name.clone(),
SyntaxContext::empty(),
))),
})));
// export default expression
stmts_updated.push(
<T as ModuleItemLike>::try_from_module_decl(
ModuleDecl::ExportDefaultExpr(ExportDefaultExpr {
expr: Box::new(Expr::Ident(Ident {
sym: atom_name.clone(),
span: DUMMY_SP,
optional: false,
})),
expr: Box::new(Expr::Ident(atom_name.into())),
span: DUMMY_SP,
}),
)
Expand All @@ -165,7 +149,7 @@ impl DebugLabelTransformVisitor {
continue;
}

stmts_updated.push(<T as StmtLike>::from_stmt(Stmt::Expr(ExprStmt {
stmts_updated.push(T::from(Stmt::Expr(ExprStmt {
span: DUMMY_SP,
expr: Box::new(self.debug_label_expr.take().unwrap()),
})))
Expand All @@ -185,12 +169,8 @@ impl VisitMut for DebugLabelTransformVisitor {
fn visit_mut_var_declarator(&mut self, var_declarator: &mut VarDeclarator) {
let old_var_declarator = self.current_var_declarator.take();

self.current_var_declarator = if let Pat::Ident(BindingIdent {
id: Ident { span, sym, .. },
..
}) = &var_declarator.name
{
Some((sym.clone(), span.ctxt))
self.current_var_declarator = if let Pat::Ident(id) = &var_declarator.name {
Some(id.to_id())
} else {
None
};
Expand Down
4 changes: 2 additions & 2 deletions crates/debug_label/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs::read_to_string, path::PathBuf};
use common::parse_plugin_config;
use swc_core::{
common::{chain, FileName, Mark},
ecma::parser::{EsConfig, Syntax},
ecma::parser::{EsSyntax, Syntax},
ecma::transforms::{
base::resolver,
react::{react, Options, RefreshOptions},
Expand All @@ -21,7 +21,7 @@ fn test(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
Syntax::Es(EsConfig {
Syntax::Es(EsSyntax {
jsx: true,
..Default::default()
}),
Expand Down
4 changes: 2 additions & 2 deletions crates/react_refresh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ crate-type = ["cdylib", "rlib"]

[dependencies]
common = { path = "../common" }
swc_core = { version = "0.90.37", features = [
swc_core = { workspace = true, features = [
"ecma_ast",
"ecma_quote",
"ecma_parser",
Expand All @@ -18,7 +18,7 @@ swc_core = { version = "0.90.37", features = [
] }

[dev-dependencies]
swc_core = { version = "0.90.37", features = [
swc_core = { workspace = true, features = [
"ecma_plugin_transform",
"ecma_transforms_react",
"testing_transform",
Expand Down
10 changes: 5 additions & 5 deletions crates/react_refresh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use common::{parse_plugin_config, AtomImportMap, Config};
use swc_core::{
common::FileName,
common::DUMMY_SP,
common::{FileName, SyntaxContext, DUMMY_SP},
ecma::{
ast::*,
visit::{as_folder, noop_visit_mut_type, Fold, FoldWith, VisitMut, VisitMutWith},
Expand Down Expand Up @@ -35,14 +34,15 @@ pub struct ReactRefreshTransformVisitor {
fn create_react_refresh_call_expr_(key: String, atom_expr: &CallExpr) -> CallExpr {
CallExpr {
span: DUMMY_SP,
ctxt: SyntaxContext::empty(),
callee: Callee::Expr(Box::new(Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: Box::new(Expr::Member(MemberExpr {
span: DUMMY_SP,
obj: Box::new(Expr::Ident(Ident::new("globalThis".into(), DUMMY_SP))),
prop: MemberProp::Ident(Ident::new("jotaiAtomCache".into(), DUMMY_SP)),
obj: Box::new(Expr::Ident("globalThis".into())),
prop: MemberProp::Ident("jotaiAtomCache".into()),
})),
prop: MemberProp::Ident(Ident::new("get".into(), DUMMY_SP)),
prop: MemberProp::Ident("get".into()),
}))),
args: vec![
ExprOrSpread {
Expand Down
4 changes: 2 additions & 2 deletions crates/react_refresh/tests/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fs::read_to_string, path::PathBuf};
use common::parse_plugin_config;
use swc_core::{
common::{chain, FileName, Mark},
ecma::parser::{EsConfig, Syntax},
ecma::parser::{EsSyntax, Syntax},
ecma::transforms::{
base::resolver,
react::{react, Options, RefreshOptions},
Expand All @@ -21,7 +21,7 @@ fn test(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
Syntax::Es(EsConfig {
Syntax::Es(EsSyntax {
jsx: true,
..Default::default()
}),
Expand Down

0 comments on commit 8c91121

Please sign in to comment.