Skip to content

Commit 221ddac

Browse files
committed
split code into two crates
1 parent 9a5755e commit 221ddac

File tree

13 files changed

+76
-45
lines changed

13 files changed

+76
-45
lines changed

Cargo.lock

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
1-
[package]
2-
name = "swc-plugin-vue-jsx"
3-
description = "SWC plugin for transforming Vue JSX."
4-
version = "0.2.0"
5-
authors = ["Pig Fang <g-plane@hotmail.com>"]
6-
license = "MIT"
7-
repository = "https://github.com/g-plane/swc-plugin-vue-jsx"
8-
edition = "2021"
9-
10-
[lib]
11-
crate-type = ["cdylib"]
1+
[workspace]
2+
members = ["plugin", "visitor"]
123

134
[profile.release]
145
lto = true
156
opt-level = "s"
167
strip = "symbols"
17-
18-
[dependencies]
19-
bitflags = "1.3"
20-
css_dataset = "0.2"
21-
indexmap = "1.9"
22-
regex = "1.6"
23-
serde = { version = "1.0", features = ["derive"] }
24-
serde_json = "1.0"
25-
swc_core = { version = "0.39", features = ["ecma_utils", "plugin_transform"] }
26-
27-
[dev-dependencies]
28-
swc_ecma_parser = "0.122"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
],
1414
"main": "swc_plugin_vue_jsx.wasm",
1515
"scripts": {
16-
"prepublishOnly": "cargo build --target wasm32-unknown-unknown --release && cp target/wasm32-unknown-unknown/release/swc_plugin_vue_jsx.wasm ."
16+
"prepublishOnly": "cargo build -p swc-plugin-vue-jsx --target wasm32-unknown-unknown --release && cp target/wasm32-unknown-unknown/release/swc_plugin_vue_jsx.wasm ."
1717
}
1818
}

plugin/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "swc-plugin-vue-jsx"
3+
description = "SWC plugin for transforming Vue JSX."
4+
version = "0.2.0"
5+
authors = ["Pig Fang <g-plane@hotmail.com>"]
6+
license = "MIT"
7+
repository = "https://github.com/g-plane/swc-plugin-vue-jsx"
8+
edition = "2021"
9+
publish = false
10+
11+
[lib]
12+
crate-type = ["cdylib"]
13+
14+
[dependencies]
15+
serde_json = "1.0"
16+
swc_core = { version = "0.39", features = ["plugin_transform"] }
17+
swc-vue-jsx-visitor = { path = "../visitor", version = "*" }

plugin/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![allow(clippy::not_unsafe_ptr_arg_deref)]
2+
3+
use swc_core::{
4+
ecma::{
5+
ast::Program,
6+
visit::{as_folder, FoldWith},
7+
},
8+
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
9+
};
10+
use swc_vue_jsx_visitor::VueJsxTransformVisitor;
11+
12+
#[plugin_transform]
13+
pub fn vue_jsx(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
14+
let options = metadata
15+
.get_transform_plugin_config()
16+
.map(|json| {
17+
serde_json::from_str(&json).expect("failed to parse config of plugin 'vue-jsx'")
18+
})
19+
.unwrap_or_default();
20+
program.fold_with(&mut as_folder(VueJsxTransformVisitor::new(
21+
options,
22+
metadata.unresolved_mark,
23+
metadata.comments,
24+
)))
25+
}

visitor/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "swc-vue-jsx-visitor"
3+
description = "SWC visitor for transforming Vue JSX."
4+
version = "0.2.0"
5+
authors = ["Pig Fang <g-plane@hotmail.com>"]
6+
license = "MIT"
7+
repository = "https://github.com/g-plane/swc-plugin-vue-jsx"
8+
edition = "2021"
9+
10+
[dependencies]
11+
bitflags = "1.3"
12+
css_dataset = "0.2"
13+
indexmap = "1.9"
14+
regex = "1.6"
15+
serde = { version = "1.0", features = ["derive"] }
16+
swc_core = { version = "0.39", features = ["ecma_utils"] }
17+
18+
[dev-dependencies]
19+
swc_ecma_parser = "0.122"
File renamed without changes.

src/lib.rs renamed to visitor/src/lib.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#![allow(clippy::not_unsafe_ptr_arg_deref)]
2-
31
use directive::{is_directive, parse_directive, Directive, NormalDirective};
42
use indexmap::IndexSet;
5-
use options::Options;
3+
pub use options::{Options, Regex};
64
use patch_flags::PatchFlags;
75
use slot_flag::SlotFlag;
86
use std::{borrow::Cow, collections::BTreeMap, mem};
@@ -12,9 +10,9 @@ use swc_core::{
1210
ast::*,
1311
atoms::JsWord,
1412
utils::{private_ident, quote_ident, quote_str},
15-
visit::{as_folder, FoldWith, VisitMut, VisitMutWith},
13+
visit::{VisitMut, VisitMutWith},
1614
},
17-
plugin::{errors::HANDLER, plugin_transform, proxies::TransformPluginProgramMetadata},
15+
plugin::errors::HANDLER,
1816
};
1917

2018
mod directive;
@@ -1293,18 +1291,3 @@ where
12931291
.splice(index..index, util::decouple_v_models(elems));
12941292
}
12951293
}
1296-
1297-
#[plugin_transform]
1298-
pub fn vue_jsx(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
1299-
let options = metadata
1300-
.get_transform_plugin_config()
1301-
.map(|json| {
1302-
serde_json::from_str(&json).expect("failed to parse config of plugin 'vue-jsx'")
1303-
})
1304-
.unwrap_or_default();
1305-
program.fold_with(&mut as_folder(VueJsxTransformVisitor::new(
1306-
options,
1307-
metadata.unresolved_mark,
1308-
metadata.comments,
1309-
)))
1310-
}
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)