@swc/plugin-jest 0.1.13 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +5 -6
- package/package.json +12 -24
- package/src/lib.rs +19 -19
- package/swc_plugin_jest.wasm +0 -0
package/Cargo.toml
CHANGED
|
@@ -4,16 +4,15 @@ description = "Jest plugin for https://swc.rs"
|
|
|
4
4
|
edition = "2018"
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
name = "swc_plugin_jest"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.11.0"
|
|
8
8
|
|
|
9
9
|
[lib]
|
|
10
10
|
crate-type = ["cdylib", "rlib"]
|
|
11
11
|
|
|
12
12
|
[dependencies]
|
|
13
|
-
abi_stable = "0.10.2"
|
|
14
13
|
phf = {version = "0.10.0", features = ["macros"]}
|
|
15
14
|
serde = {version = "1.0.130", features = ["derive"]}
|
|
16
|
-
swc_atoms = "0.2.
|
|
17
|
-
swc_common = {version = "0.
|
|
18
|
-
swc_ecmascript = { features = ["utils", "visit"], version = "0.
|
|
19
|
-
swc_plugin = "0.
|
|
15
|
+
swc_atoms = "0.2.9"
|
|
16
|
+
swc_common = { version = "0.17.18", features = ["concurrent"] }
|
|
17
|
+
swc_ecmascript = { features = ["utils", "visit"], version = "0.139.0" }
|
|
18
|
+
swc_plugin = "0.37.0"
|
package/package.json
CHANGED
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
{
|
|
2
|
-
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
|
3
|
-
"bugs": {
|
|
4
|
-
"url": "https://github.com/swc-project/plugins/issues"
|
|
5
|
-
},
|
|
6
|
-
"description": "Jest transform plugin for https://swc.rs",
|
|
7
|
-
"homepage": "https://swc.rs",
|
|
8
|
-
"keywords": [],
|
|
9
|
-
"license": "Apache-2.0",
|
|
10
|
-
"main": "index.js",
|
|
11
2
|
"name": "@swc/plugin-jest",
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"@swc/plugin-jest-linux-arm64-gnu": "0.1.13",
|
|
18
|
-
"@swc/plugin-jest-linux-x64-gnu": "0.1.13",
|
|
19
|
-
"@swc/plugin-jest-linux-x64-musl": "0.1.13",
|
|
20
|
-
"@swc/plugin-jest-win32-arm64-msvc": "0.1.13",
|
|
21
|
-
"@swc/plugin-jest-win32-ia32-msvc": "0.1.13",
|
|
22
|
-
"@swc/plugin-jest-win32-x64-msvc": "0.1.13"
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Jest transform plugin for https://swc.rs",
|
|
5
|
+
"main": "swc_plugin_jest.wasm",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"prepack": "cp ../../target/wasm32-wasi/release/swc_plugin_jest.wasm ."
|
|
23
8
|
},
|
|
9
|
+
"homepage": "https://swc.rs",
|
|
24
10
|
"repository": {
|
|
25
11
|
"type": "git",
|
|
26
12
|
"url": "+https://github.com/swc-project/plugins.git"
|
|
27
13
|
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/swc-project/plugins/issues"
|
|
30
16
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
17
|
+
"author": "강동윤 <kdy1997.dev@gmail.com>",
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"license": "Apache-2.0"
|
|
20
|
+
}
|
package/src/lib.rs
CHANGED
|
@@ -4,10 +4,11 @@ use swc_common::util::take::Take;
|
|
|
4
4
|
use swc_ecmascript::{
|
|
5
5
|
ast::*,
|
|
6
6
|
utils::{prepend_stmts, StmtLike},
|
|
7
|
-
visit::{
|
|
7
|
+
visit::{noop_visit_mut_type, VisitMut, VisitMutWith},
|
|
8
8
|
};
|
|
9
|
+
use swc_plugin::plugin_transform;
|
|
9
10
|
|
|
10
|
-
swc_plugin::define_js_plugin!(jest);
|
|
11
|
+
// swc_plugin::define_js_plugin!(jest);
|
|
11
12
|
|
|
12
13
|
static HOIST_METHODS: phf::Set<&str> = phf_set![
|
|
13
14
|
"mock",
|
|
@@ -17,8 +18,11 @@ static HOIST_METHODS: phf::Set<&str> = phf_set![
|
|
|
17
18
|
"deepUnmock"
|
|
18
19
|
];
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
#[plugin_transform]
|
|
22
|
+
fn jest(mut program: Program, _plugin_config: String, _: String) -> Program {
|
|
23
|
+
program.visit_mut_with(&mut Jest);
|
|
24
|
+
|
|
25
|
+
program
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
#[derive(Deserialize)]
|
|
@@ -45,27 +49,23 @@ impl Jest {
|
|
|
45
49
|
Ok(stmt) => match &stmt {
|
|
46
50
|
Stmt::Expr(ExprStmt { expr, .. }) => match &**expr {
|
|
47
51
|
Expr::Call(CallExpr {
|
|
48
|
-
callee:
|
|
52
|
+
callee: Callee::Expr(callee),
|
|
49
53
|
..
|
|
50
54
|
}) => match &**callee {
|
|
51
55
|
Expr::Member(
|
|
52
|
-
callee
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
computed: false, ..
|
|
56
|
+
callee @ MemberExpr {
|
|
57
|
+
prop: MemberProp::Ident(prop),
|
|
58
|
+
..
|
|
56
59
|
},
|
|
57
|
-
) => match
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
_ => new.push(T::from_stmt(stmt)),
|
|
66
|
-
},
|
|
60
|
+
) => match &*callee.obj {
|
|
61
|
+
Expr::Ident(i) if i.sym == *"jest" => match prop {
|
|
62
|
+
_ if HOIST_METHODS.contains(&*prop.sym) => {
|
|
63
|
+
hoisted.push(T::from_stmt(stmt));
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
67
66
|
_ => new.push(T::from_stmt(stmt)),
|
|
68
67
|
},
|
|
68
|
+
_ => new.push(T::from_stmt(stmt)),
|
|
69
69
|
},
|
|
70
70
|
_ => new.push(T::from_stmt(stmt)),
|
|
71
71
|
},
|
|
Binary file
|