Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade swc_core #16

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,343 changes: 597 additions & 746 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ members = [
"packages/node-transform"
]

[workspace.dependencies]
anyhow = "1.0.83"
fxhash = "0.2.1"
serde = "1.0.203"
serde_json = "1.0.117"
swc_atoms = "2.0.0"
swc_common = "1.0.0"
swc_core = "1.0.0"
swc_ecma_ast = "1.0.0"
swc_ecma_parser = "1.0.0"
swc_ecma_utils = "1.0.0"
swc_ecma_visit = "1.0.0"
swc_plugin_macro = "1.0.0"
swc_plugin_proxy = "1.0.0"
testing = "1.0.0"
tracing = "0.1.40"

[profile.release]
# This removes more dead code
codegen-units = 1
Expand Down
17 changes: 9 additions & 8 deletions packages/keep-export/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
serde = "1"
fxhash= "0.2.1"
easy-error = "1.0.0"
tracing = { version="0.1.34", features = ["release_max_level_info"] }
swc_core = {version = "0.79.56", features = [
serde ={ workspace = true }
fxhash= { workspace = true }
tracing = { workspace = true, features = ["release_max_level_info"] }
swc_core = { workspace = true, features = [
"ecma_plugin_transform",
"ecma_utils",
"ecma_visit",
"ecma_ast",
"common",
]}
swc_common = { version = "0.31.18", features = ["concurrent"] }
serde_json = {version = "1", features = ["unbounded_depth"]}
swc_common = { workspace = true, features = ["concurrent"] }
serde_json = { workspace = true, features = ["unbounded_depth"]}
swc_plugin_macro = { workspace = true }
swc_plugin_proxy = { workspace = true }

[dev-dependencies]
testing = "0.33.21"
testing = { workspace = true }
2 changes: 1 addition & 1 deletion packages/keep-export/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/swc-plugin-keep-export",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",
"keywords": ["swc-plugin"],
"main": "swc_plugin_keep_export.wasm",
Expand Down
40 changes: 10 additions & 30 deletions packages/keep-export/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#![allow(clippy::not_unsafe_ptr_arg_deref)]
use fxhash::FxHashSet;
use std::mem::take;
use swc_common::pass::{Repeat, Repeated};
use swc_common::DUMMY_SP;
use swc_core::{
ecma::{
ast::*,
visit::{Fold, FoldWith, noop_fold_type},
},
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
use swc_core::ecma::{
ast::*,
visit::{Fold, FoldWith, noop_fold_type},
};
use swc_plugin_proxy::TransformPluginProgramMetadata;
use swc_plugin_macro::plugin_transform;

/// Note: This paths requires running `resolver` **before** running this.
pub fn keep_exprs(keep_exports: Vec<String>) -> impl Fold {
Repeat::new(KeepExportsExprs {
state: State {
keep_exports: keep_exports,
keep_exports,
..Default::default()
},
in_lhs_of_var: false,
Expand Down Expand Up @@ -379,7 +379,7 @@ impl Fold for KeepExportsExprs {
tracing::trace!(
"Dropping import `{}{:?}` because it should be removed",
local.sym,
local.span.ctxt
local.span
);

self.state.should_run_again = true;
Expand Down Expand Up @@ -421,7 +421,7 @@ impl Fold for KeepExportsExprs {
specifiers: Vec::new(),
src: None,
type_only: false,
asserts: None
with: None
})));
}

Expand Down Expand Up @@ -509,7 +509,7 @@ impl Fold for KeepExportsExprs {
tracing::trace!(
"Dropping var `{}{:?}` because it should be removed",
name.id.sym,
name.id.span.ctxt
name.id.span
);

return Pat::Invalid(Invalid { span: DUMMY_SP });
Expand Down Expand Up @@ -630,26 +630,6 @@ impl Fold for KeepExportsExprs {
}
}


/// An example plugin function with macro support.
/// `plugin_transform` macro interop pointers into deserialized structs, as well
/// as returning ptr back to host.
///
/// It is possible to opt out from macro by writing transform fn manually via
/// `__plugin_process_impl(
/// ast_ptr: *const u8,
/// ast_ptr_len: i32,
/// config_str_ptr: *const u8,
/// config_str_ptr_len: i32,
/// context_str_ptr: *const u8,
/// context_str_ptr_len: i32) ->
/// i32 /* 0 for success, fail otherwise.
/// Note this is only for internal pointer interop result,
/// not actual transform result */
///
/// if plugin need to handle low-level ptr directly. However, there are
/// important steps manually need to be performed like sending transformed
/// results back to host. Refer swc_plugin_macro how does it work internally.
#[plugin_transform]
pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
let tr = serde_json::from_str::<Vec<String>>(
Expand Down
17 changes: 9 additions & 8 deletions packages/keep-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
serde = "1"
fxhash= "0.2.1"
serde = { workspace = true }
fxhash= { workspace = true }
lazy_static = "1.4.0"
easy-error = "1.0.0"
tracing = { version="0.1.34", features = ["release_max_level_info"] }
swc_core = { version = "0.79.56", features = [
tracing = { workspace = true, features = ["release_max_level_info"] }
swc_core = { workspace = true, features = [
"ecma_plugin_transform",
"ecma_utils",
"ecma_visit",
"ecma_ast",
"common",
]}
swc_common = { version = "0.31.18", features = ["concurrent"] }
serde_json = {version = "1", features = ["unbounded_depth"]}
swc_common = { workspace = true, features = ["concurrent"] }
serde_json = { workspace = true, features = ["unbounded_depth"]}
swc_plugin_macro = { workspace = true }
swc_plugin_proxy = { workspace = true }

[dev-dependencies]
testing = "0.33.21"
testing = "1.0.0"
2 changes: 1 addition & 1 deletion packages/keep-platform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/swc-plugin-keep-platform",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",
"keywords": ["swc-plugin"],
"main": "swc_plugin_keep_platform.wasm",
Expand Down
25 changes: 12 additions & 13 deletions packages/keep-platform/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use swc_common::DUMMY_SP;
use swc_core::{
ecma::{
ast::*,
atoms::JsWord,
visit::{Fold, FoldWith},
},
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
use swc_common::{SyntaxContext, DUMMY_SP};
use swc_core::ecma::{
ast::*,
atoms::JsWord,
visit::{Fold, FoldWith},
};
use swc_plugin_proxy::TransformPluginProgramMetadata;
use swc_plugin_macro::plugin_transform;

#[derive(Debug, Deserialize, Default, Clone)]
pub struct KeepPlatformPatcher {
Expand Down Expand Up @@ -169,18 +168,18 @@ fn insert_decls_into_module_items(decls: Vec<VarDeclarator>, module_items: &mut
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: false,
decls: decls,
decls,
ctxt: SyntaxContext::empty()
})))),
)
}
}

// Create Ident by jsword.
fn create_jsword_ident(value: &str) -> Ident {
Ident {
fn create_jsword_ident(value: &str) -> IdentName {
IdentName {
span: DUMMY_SP,
sym: JsWord::from(value),
optional: Default::default(),
sym: JsWord::from(value)
}
}

Expand Down
17 changes: 9 additions & 8 deletions packages/node-transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@ edition = "2021"
crate-type = ["cdylib", "rlib"]

[dependencies]
serde = "1"
fxhash= "0.2.1"
easy-error = "1.0.0"
tracing = { version="0.1.34", features = ["release_max_level_info"] }
swc_core = { version = "0.79.56", features = [
serde = { workspace = true }
fxhash= { workspace = true }
tracing = { workspace = true, features = ["release_max_level_info"] }
swc_core = { workspace = true, features = [
"ecma_plugin_transform",
"ecma_utils",
"ecma_visit",
"ecma_ast",
"common",
]}
swc_common = { version = "0.31.18", features = ["concurrent"] }
serde_json = {version = "1", features = ["unbounded_depth"]}
swc_common = { workspace = true, features = ["concurrent"] }
serde_json = { workspace = true, features = ["unbounded_depth"]}
swc_plugin_macro = { workspace = true }
swc_plugin_proxy = { workspace = true }

[dev-dependencies]
testing = "0.33.21"
testing = { workspace = true }
2 changes: 1 addition & 1 deletion packages/node-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ice/swc-plugin-node-transform",
"version": "0.2.0",
"version": "0.3.0",
"license": "MIT",
"keywords": ["swc-plugin"],
"main": "swc_plugin_node_transform.wasm",
Expand Down
Loading
Loading