@swc/plugin-swc-magic 1.5.93

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 ADDED
@@ -0,0 +1,18 @@
1
+ [package]
2
+ authors = ["강동윤 <kdy1997.dev@gmail.com>"]
3
+ description = "SWC Plugin for swc-magic"
4
+ edition = "2021"
5
+ license = "Apache-2.0"
6
+ name = "swc_plugin_swc_magic"
7
+ publish = false
8
+ version = "0.1.0"
9
+
10
+ [lib]
11
+ crate-type = ["cdylib", "rlib"]
12
+
13
+ [dependencies]
14
+ serde_json = "1.0.107"
15
+ swc_core = { version = "0.86.16", features = ["ecma_plugin_transform"] }
16
+
17
+
18
+ swc_magic = { path = "./transform" }
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # @swc/plugin-swc-magic
2
+
3
+ ## Usage
4
+
5
+ .swcrc:
6
+
7
+ ```json
8
+ {
9
+ "jsc": {
10
+ "experimental": {
11
+ "plugins": ["@swc/plugin-swc-magic"]
12
+ }
13
+ }
14
+ }
15
+ ```
16
+
17
+ ```js
18
+ import { markAsPure } from "@swc/magic";
19
+
20
+ markAsPure(() => console.log("This will be removed by the SWC minifier"));
21
+ ```
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@swc/plugin-swc-magic",
3
+ "version": "1.5.93",
4
+ "description": "SWC plugin for swc-magic",
5
+ "main": "swc_plugin_swc_magic.wasm",
6
+ "scripts": {
7
+ "prepack": "cp ../../target/wasm32-wasi/release/swc_plugin_swc_magic.wasm ."
8
+ },
9
+ "homepage": "https://swc.rs",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "+https://github.com/swc-project/plugins.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/swc-project/plugins/issues"
16
+ },
17
+ "author": "강동윤 <kdy1997.dev@gmail.com>",
18
+ "keywords": [],
19
+ "license": "Apache-2.0",
20
+ "preferUnplugged": true
21
+ }
package/src/lib.rs ADDED
@@ -0,0 +1,30 @@
1
+ #![allow(clippy::not_unsafe_ptr_arg_deref)]
2
+ #![feature(box_patterns)]
3
+
4
+ use swc_core::{
5
+ ecma::{ast::Program, visit::VisitMutWith},
6
+ plugin::{
7
+ plugin_transform,
8
+ proxies::{PluginCommentsProxy, TransformPluginProgramMetadata},
9
+ },
10
+ };
11
+
12
+ #[plugin_transform]
13
+ fn swc_magic_plugin(mut program: Program, data: TransformPluginProgramMetadata) -> Program {
14
+ let config = serde_json::from_str::<swc_magic::Config>(
15
+ &data
16
+ .get_transform_plugin_config()
17
+ .expect("failed to get plugin config for swc-magic"),
18
+ )
19
+ .expect("invalid config for swc-magic");
20
+
21
+ let unresolved_mark = data.unresolved_mark;
22
+
23
+ program.visit_mut_with(&mut swc_magic::swc_magic(
24
+ unresolved_mark,
25
+ config,
26
+ PluginCommentsProxy,
27
+ ));
28
+
29
+ program
30
+ }
Binary file