@tarojs/helper 3.8.0-canary.0 → 4.0.0-alpha.2

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.
Files changed (38) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +25 -0
  3. package/dist/constants.d.ts +5 -3
  4. package/dist/constants.js +24 -22
  5. package/dist/constants.js.map +1 -1
  6. package/dist/dotenv.js.map +1 -1
  7. package/dist/esbuild/index.js +7 -5
  8. package/dist/esbuild/index.js.map +1 -1
  9. package/dist/npm.d.ts +2 -2
  10. package/dist/npm.js +6 -6
  11. package/dist/npm.js.map +1 -1
  12. package/dist/swcRegister.d.ts +0 -6
  13. package/dist/swcRegister.js +0 -15
  14. package/dist/swcRegister.js.map +1 -1
  15. package/dist/utils.d.ts +33 -1
  16. package/dist/utils.js +83 -33
  17. package/dist/utils.js.map +1 -1
  18. package/package.json +24 -18
  19. package/swc/.gitkeep +0 -0
  20. package/swc/swc_plugin_compile_mode.wasm +0 -0
  21. package/swc/swc_plugin_define_config.wasm +0 -0
  22. package/swc/plugin-compile-mode/Cargo.lock +0 -2086
  23. package/swc/plugin-compile-mode/Cargo.toml +0 -20
  24. package/swc/plugin-compile-mode/src/lib.rs +0 -52
  25. package/swc/plugin-compile-mode/src/tests/attributes.rs +0 -85
  26. package/swc/plugin-compile-mode/src/tests/condition.rs +0 -71
  27. package/swc/plugin-compile-mode/src/tests/entry.rs +0 -32
  28. package/swc/plugin-compile-mode/src/tests/looping.rs +0 -134
  29. package/swc/plugin-compile-mode/src/tests/mod.rs +0 -98
  30. package/swc/plugin-compile-mode/src/tests/shake.rs +0 -41
  31. package/swc/plugin-compile-mode/src/transform.rs +0 -466
  32. package/swc/plugin-compile-mode/src/utils/constants.rs +0 -11
  33. package/swc/plugin-compile-mode/src/utils/mod.rs +0 -236
  34. package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
  35. package/swc/plugin-define-config/Cargo.lock +0 -2034
  36. package/swc/plugin-define-config/Cargo.toml +0 -27
  37. package/swc/plugin-define-config/src/lib.rs +0 -188
  38. package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
@@ -1,27 +0,0 @@
1
- [package]
2
- name = "swc-plugin-define-config"
3
- version = "0.1.0"
4
- edition = "2021"
5
-
6
- [lib]
7
- crate-type = ["cdylib"]
8
-
9
- [profile.release]
10
- # This removes more dead code
11
- codegen-units = 1
12
- lto = true
13
- # Optimize for size
14
- opt-level = "s"
15
- # Optimize for performance, this is default so you don't need to specify it
16
- # opt-level = "z"
17
- # Strip debug symbols
18
- strip = "symbols"
19
-
20
- [dependencies]
21
- serde = "1"
22
- swc_core = { version = "0.40.*", features = ["plugin_transform"] }
23
-
24
- # .cargo/config defines few alias to build plugin.
25
- # cargo build-wasi generates wasm-wasi32 binary
26
- # cargo build-wasm32 generates wasm32-unknown-unknown binary.
27
-
@@ -1,188 +0,0 @@
1
- use swc_core::ecma::{
2
- ast::*,
3
- transforms::testing::test,
4
- visit::{as_folder, FoldWith, VisitMut, VisitMutWith},
5
- };
6
- use swc_core::common::{DUMMY_SP, SyntaxContext};
7
- use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata};
8
-
9
- struct DefineConfig {
10
- found: bool,
11
- fn_name: String,
12
- ctxt: SyntaxContext
13
- }
14
-
15
- impl DefineConfig {
16
- fn new() -> Self {
17
- Self {
18
- found: false,
19
- fn_name: String::from(""),
20
- ctxt: SyntaxContext::empty()
21
- }
22
- }
23
- }
24
-
25
- impl VisitMut for DefineConfig {
26
- fn visit_mut_call_expr(&mut self, node: &mut CallExpr) {
27
- node.visit_mut_children_with(self);
28
-
29
- let callee = &node.callee;
30
- if let Some(expr_box) = callee.as_expr() {
31
- if let Expr::Ident(ident) = &**expr_box {
32
- if &ident.sym == "defineAppConfig" || &ident.sym == "definePageConfig" {
33
- self.found = true;
34
- self.fn_name = String::from(&*ident.sym);
35
- self.ctxt = ident.span.ctxt;
36
- }
37
- }
38
- }
39
- }
40
- }
41
-
42
- pub struct TransformVisitor;
43
-
44
- impl VisitMut for TransformVisitor {
45
- fn visit_mut_module_items(&mut self, module_item: &mut Vec<ModuleItem>) {
46
- module_item.visit_mut_children_with(self);
47
-
48
- let mut define_config = DefineConfig::new();
49
- let mut line_to_be_insert: usize = 0;
50
-
51
- for (idx, item) in module_item.iter_mut().enumerate() {
52
- match item {
53
- ModuleItem::Stmt(stmt) => {
54
- stmt.visit_mut_with(&mut define_config);
55
- if define_config.found {
56
- line_to_be_insert = idx;
57
- break;
58
- }
59
- }
60
- ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultExpr(expr)) => {
61
- expr.visit_mut_with(&mut define_config);
62
- if define_config.found {
63
- line_to_be_insert = idx;
64
- break;
65
- }
66
- }
67
- _ => ()
68
- }
69
- }
70
-
71
- if define_config.found {
72
- let func = Stmt::Decl(Decl::Fn(FnDecl {
73
- ident: Ident::new(define_config.fn_name.into(), DUMMY_SP.with_ctxt(define_config.ctxt)),
74
- declare: false,
75
- function: Box::new(Function {
76
- span: DUMMY_SP,
77
- params: vec![Param {
78
- span: DUMMY_SP,
79
- decorators: Default::default(),
80
- pat: Pat::Ident(BindingIdent::from(Ident::new("config".into(), DUMMY_SP))),
81
- }],
82
- body: Some(BlockStmt {
83
- span: DUMMY_SP,
84
- stmts: vec![Stmt::Return(ReturnStmt {
85
- span: DUMMY_SP,
86
- arg: Some(Box::new(Expr::Ident(Ident::new("config".into(), DUMMY_SP)))),
87
- })],
88
- }),
89
- is_generator: false,
90
- is_async: false,
91
- type_params: Default::default(),
92
- decorators: Default::default(),
93
- return_type: Default::default(),
94
- }),
95
- }));
96
-
97
- module_item.insert(line_to_be_insert, ModuleItem::Stmt(func));
98
- }
99
- }
100
- }
101
-
102
- /// An example plugin function with macro support.
103
- /// `plugin_transform` macro interop pointers into deserialized structs, as well
104
- /// as returning ptr back to host.
105
- ///
106
- /// It is possible to opt out from macro by writing transform fn manually
107
- /// if plugin need to handle low-level ptr directly via
108
- /// `__transform_plugin_process_impl(
109
- /// ast_ptr: *const u8, ast_ptr_len: i32,
110
- /// unresolved_mark: u32, should_enable_comments_proxy: i32) ->
111
- /// i32 /* 0 for success, fail otherwise.
112
- /// Note this is only for internal pointer interop result,
113
- /// not actual transform result */`
114
- ///
115
- /// This requires manual handling of serialization / deserialization from ptrs.
116
- /// Refer swc_plugin_macro to see how does it work internally.
117
- #[plugin_transform]
118
- pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
119
- program.fold_with(&mut as_folder(TransformVisitor))
120
- }
121
-
122
- // An example to test plugin transform.
123
- // Recommended strategy to test plugin's transform is verify
124
- // the Visitor's behavior, instead of trying to run `process_transform` with mocks
125
- // unless explicitly required to do so.
126
- test!(
127
- Default::default(),
128
- |_| as_folder(TransformVisitor),
129
- module_decl_default_app,
130
- // Input codes
131
- r#"
132
- export default defineAppConfig({})
133
- "#,
134
- // Output codes after transformed with plugin
135
- r#"
136
- function defineAppConfig(config) {return config}
137
- export default defineAppConfig({})
138
- "#
139
- );
140
-
141
- test!(
142
- Default::default(),
143
- |_| as_folder(TransformVisitor),
144
- module_decl_default_page,
145
- // Input codes
146
- r#"
147
- export default definePageConfig({})
148
- "#,
149
- // Output codes after transformed with plugin
150
- r#"
151
- function definePageConfig(config) {return config}
152
- export default definePageConfig({})
153
- "#
154
- );
155
-
156
- test!(
157
- Default::default(),
158
- |_| as_folder(TransformVisitor),
159
- var_decl_app,
160
- // Input codes
161
- r#"
162
- const config = defineAppConfig({})
163
- export default config
164
- "#,
165
- // Output codes after transformed with plugin
166
- r#"
167
- function defineAppConfig(config) {return config}
168
- const config = defineAppConfig({})
169
- export default config
170
- "#
171
- );
172
-
173
- test!(
174
- Default::default(),
175
- |_| as_folder(TransformVisitor),
176
- var_decl_page,
177
- // Input codes
178
- r#"
179
- const config = definePageConfig({})
180
- export default config
181
- "#,
182
- // Output codes after transformed with plugin
183
- r#"
184
- function definePageConfig(config) {return config}
185
- const config = definePageConfig({})
186
- export default config
187
- "#
188
- );