Skip to content

Commit

Permalink
refactor: swc transformers (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia authored Dec 11, 2023
1 parent 13ef2f2 commit d8a1c3e
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 18 deletions.
29 changes: 28 additions & 1 deletion Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ members = [
"crates/node_binding",
"crates/loader_compilation",
"crates/plugin_manifest",
"crates/swc_env_replacement",
"crates/swc_keep_export",
"crates/swc_remove_export",
"crates/plugin_specilize_module_name"
]
resolver = "2"
Expand Down
4 changes: 3 additions & 1 deletion crates/loader_compilation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ anyhow = { workspace = true }
async-trait = { workspace = true }
dashmap = { workspace = true }
either = "1"
fxhash = "0.2.1"
lazy_static = "1.4.0"
once_cell = { workspace = true }
rspack_ast = { path = "../.rspack_crates/rspack_ast" }
Expand All @@ -30,6 +29,9 @@ swc_core = { workspace = true, features = [
] }
swc_emotion = { workspace = true }
xxhash-rust = { workspace = true, features = ["xxh32"] }
swc_env_replacement = { path = "../swc_env_replacement" }
swc_keep_export = { path = "../swc_keep_export" }
swc_remove_export = { path = "../swc_remove_export" }

[dev-dependencies]
indexmap = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/loader_compilation/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(box_patterns)]
use std::{path::Path, collections::HashMap, sync::Mutex};
use lazy_static::lazy_static;
use rspack_ast::RspackAst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ use swc_core::common::chain;
use swc_core::ecma::{
transforms::base::pass::noop, visit::Fold,
};

mod keep_export;
mod remove_export;
mod env_replacement;

use keep_export::keep_export;
use remove_export::remove_export;
use env_replacement::env_replacement;
use swc_keep_export::keep_export;
use swc_remove_export::remove_export;
use swc_env_replacement::env_replacement;

macro_rules! either {
($config:expr, $f:expr) => {
Expand Down
11 changes: 11 additions & 0 deletions crates/swc_env_replacement/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "swc_env_replacement"
version = "0.1.0"
edition = "2021"

[dependencies]
swc_core = { workspace = true, features = [
"base",
"ecma_ast",
"common"
] }
3 changes: 3 additions & 0 deletions crates/swc_env_replacement/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![feature(box_patterns)]
mod transform;
pub use transform::*;
File renamed without changes.
13 changes: 13 additions & 0 deletions crates/swc_keep_export/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "swc_keep_export"
version = "0.1.0"
edition = "2021"

[dependencies]
fxhash = "0.2.1"
swc_core = { workspace = true, features = [
"base",
"ecma_ast",
"common"
] }
rspack_error = { path = "../.rspack_crates/rspack_error" }
2 changes: 2 additions & 0 deletions crates/swc_keep_export/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod transform;
pub use transform::*;
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// https://github.com/ice-lab/swc-plugins/tree/main/packages/keep-export
use fxhash::FxHashSet;
use std::mem::take;
use swc_core::ecma::{
ast::*,
visit::{Fold, FoldWith, noop_fold_type},
};
use swc_core::common::{
DUMMY_SP, pass::{Repeat, Repeated}
use swc_core::{
common::{
DUMMY_SP, pass::{Repeat, Repeated}
},
ecma::{
ast::*,
visit::{Fold, FoldWith, noop_fold_type}
}
};

/// State of the transforms. Shared by the analyzer and the transform.
#[derive(Debug, Default)]
struct State {
Expand Down
13 changes: 13 additions & 0 deletions crates/swc_remove_export/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "swc_remove_export"
version = "0.1.0"
edition = "2021"

[dependencies]
fxhash = "0.2.1"
swc_core = { workspace = true, features = [
"base",
"ecma_ast",
"common"
] }
rspack_error = { path = "../.rspack_crates/rspack_error" }
2 changes: 2 additions & 0 deletions crates/swc_remove_export/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod transform;
pub use transform::*;
File renamed without changes.

0 comments on commit d8a1c3e

Please sign in to comment.