@tarojs/helper 3.6.9-alpha.6 → 3.6.9-alpha.8
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/dist/esbuild/index.js +1 -0
- package/dist/esbuild/index.js.map +1 -1
- package/dist/swcRegister.d.ts +0 -6
- package/dist/swcRegister.js +0 -15
- package/dist/swcRegister.js.map +1 -1
- package/dist/utils.d.ts +5 -1
- package/dist/utils.js +5 -1
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/swc/plugin-define-config/Cargo.lock +492 -340
- package/swc/plugin-define-config/Cargo.toml +3 -11
- package/swc/plugin-define-config/src/lib.rs +126 -120
- package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "swc-plugin-define-config"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib"]
|
|
8
8
|
|
|
9
9
|
[profile.release]
|
|
10
|
-
# This removes more dead code
|
|
11
|
-
codegen-units = 1
|
|
12
10
|
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
11
|
|
|
20
12
|
[dependencies]
|
|
21
13
|
serde = "1"
|
|
22
|
-
swc_core = { version = "0.
|
|
14
|
+
swc_core = { version = "0.79.*", features = ["ecma_plugin_transform"] }
|
|
15
|
+
swc_ecma_utils = "0.120.1"
|
|
23
16
|
|
|
24
17
|
# .cargo/config defines few alias to build plugin.
|
|
25
18
|
# cargo build-wasi generates wasm-wasi32 binary
|
|
26
19
|
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
|
|
27
|
-
|
|
@@ -1,102 +1,75 @@
|
|
|
1
|
-
use swc_core::
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
use swc_core::{
|
|
2
|
+
ecma::{
|
|
3
|
+
ast::*,
|
|
4
|
+
transforms::testing::test,
|
|
5
|
+
visit::{as_folder, FoldWith, VisitMut, VisitMutWith},
|
|
6
|
+
},
|
|
7
|
+
common::{
|
|
8
|
+
DUMMY_SP,
|
|
9
|
+
SyntaxContext
|
|
10
|
+
},
|
|
5
11
|
};
|
|
6
|
-
use
|
|
12
|
+
use swc_ecma_utils::{quote_ident, FunctionFactory};
|
|
7
13
|
use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata};
|
|
8
14
|
|
|
9
|
-
struct
|
|
10
|
-
found: bool,
|
|
11
|
-
fn_name: String,
|
|
12
|
-
ctxt: SyntaxContext
|
|
13
|
-
}
|
|
15
|
+
pub struct TransformVisitor;
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
found: false,
|
|
19
|
-
fn_name: String::from(""),
|
|
20
|
-
ctxt: SyntaxContext::empty()
|
|
21
|
-
}
|
|
22
|
-
}
|
|
17
|
+
struct DefineFoler {
|
|
18
|
+
name: Option<String>,
|
|
19
|
+
ctxt: Option<SyntaxContext>,
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
impl VisitMut for
|
|
26
|
-
fn visit_mut_call_expr(&mut self,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
self.ctxt = ident.span.ctxt;
|
|
36
|
-
}
|
|
22
|
+
impl VisitMut for DefineFoler {
|
|
23
|
+
fn visit_mut_call_expr(&mut self, expr: &mut CallExpr) {
|
|
24
|
+
expr.visit_mut_children_with(self);
|
|
25
|
+
if let Callee::Expr(expr) = &expr.callee {
|
|
26
|
+
if let Expr::Ident(ident) = &**expr {
|
|
27
|
+
if &*ident.sym == "defineAppConfig" || &*ident.sym == "definePageConfig" {
|
|
28
|
+
self.name = Some(String::from(&*ident.sym));
|
|
29
|
+
self.ctxt = Some(ident.span.ctxt);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
37
32
|
}
|
|
38
|
-
}
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
|
|
42
|
-
pub struct TransformVisitor;
|
|
43
|
-
|
|
44
36
|
impl VisitMut for TransformVisitor {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
let mut define_config = DefineConfig::new();
|
|
37
|
+
fn visit_mut_module_items(&mut self, items: &mut Vec<ModuleItem>) {
|
|
38
|
+
let mut folder = DefineFoler { name: None, ctxt: None };
|
|
49
39
|
let mut line_to_be_insert: usize = 0;
|
|
50
40
|
|
|
51
|
-
for (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
line_to_be_insert = idx;
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
41
|
+
for (index, item) in items.iter_mut().enumerate() {
|
|
42
|
+
item.visit_mut_with(&mut folder);
|
|
43
|
+
if folder.name.is_some() {
|
|
44
|
+
line_to_be_insert = index;
|
|
45
|
+
break
|
|
59
46
|
}
|
|
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
47
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 {
|
|
48
|
+
if let Some(name) = &folder.name {
|
|
49
|
+
let func_name = quote_ident!(DUMMY_SP.with_ctxt(folder.ctxt.unwrap()), name.as_str());
|
|
50
|
+
let func = Function {
|
|
78
51
|
span: DUMMY_SP,
|
|
79
52
|
decorators: Default::default(),
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
53
|
+
params: vec![Param {
|
|
54
|
+
span: DUMMY_SP,
|
|
55
|
+
decorators: Default::default(),
|
|
56
|
+
pat: Pat::Ident(quote_ident!("config").into()),
|
|
57
|
+
}],
|
|
58
|
+
body: Some(BlockStmt {
|
|
59
|
+
span: DUMMY_SP,
|
|
60
|
+
stmts: vec![Stmt::Return(ReturnStmt {
|
|
61
|
+
span: DUMMY_SP,
|
|
62
|
+
arg: Some(Box::new(quote_ident!("config").into())),
|
|
63
|
+
})],
|
|
64
|
+
}),
|
|
65
|
+
is_async: false,
|
|
66
|
+
is_generator: false,
|
|
67
|
+
type_params: None,
|
|
68
|
+
return_type: None,
|
|
69
|
+
};
|
|
70
|
+
items.insert(line_to_be_insert, ModuleItem::Stmt(Stmt::Decl(Decl::Fn(func.into_fn_decl(func_name)))));
|
|
98
71
|
}
|
|
99
|
-
|
|
72
|
+
}
|
|
100
73
|
}
|
|
101
74
|
|
|
102
75
|
/// An example plugin function with macro support.
|
|
@@ -116,7 +89,7 @@ impl VisitMut for TransformVisitor {
|
|
|
116
89
|
/// Refer swc_plugin_macro to see how does it work internally.
|
|
117
90
|
#[plugin_transform]
|
|
118
91
|
pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
|
|
119
|
-
|
|
92
|
+
program.fold_with(&mut as_folder(TransformVisitor))
|
|
120
93
|
}
|
|
121
94
|
|
|
122
95
|
// An example to test plugin transform.
|
|
@@ -124,65 +97,98 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
|
|
|
124
97
|
// the Visitor's behavior, instead of trying to run `process_transform` with mocks
|
|
125
98
|
// unless explicitly required to do so.
|
|
126
99
|
test!(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
"#
|
|
100
|
+
Default::default(),
|
|
101
|
+
|_| as_folder(TransformVisitor),
|
|
102
|
+
module_decl_default_app,
|
|
103
|
+
// Input codes
|
|
104
|
+
r#"
|
|
105
|
+
export default defineAppConfig({})
|
|
106
|
+
"#,
|
|
107
|
+
// Output codes after transformed with plugin
|
|
108
|
+
r#"
|
|
109
|
+
function defineAppConfig(config) {return config}
|
|
110
|
+
export default defineAppConfig({})
|
|
111
|
+
"#
|
|
154
112
|
);
|
|
155
113
|
|
|
156
114
|
test!(
|
|
157
115
|
Default::default(),
|
|
158
116
|
|_| as_folder(TransformVisitor),
|
|
159
|
-
|
|
117
|
+
module_decl_default_page,
|
|
160
118
|
// Input codes
|
|
161
119
|
r#"
|
|
162
|
-
|
|
163
|
-
export default config
|
|
120
|
+
export default definePageConfig({})
|
|
164
121
|
"#,
|
|
165
122
|
// Output codes after transformed with plugin
|
|
166
123
|
r#"
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
export default config
|
|
124
|
+
function definePageConfig(config) {return config}
|
|
125
|
+
export default definePageConfig({})
|
|
170
126
|
"#
|
|
171
127
|
);
|
|
172
128
|
|
|
129
|
+
test!(
|
|
130
|
+
Default::default(),
|
|
131
|
+
|_| as_folder(TransformVisitor),
|
|
132
|
+
var_decl_app,
|
|
133
|
+
// Input codes
|
|
134
|
+
r#"
|
|
135
|
+
const config = defineAppConfig({})
|
|
136
|
+
export default config
|
|
137
|
+
"#,
|
|
138
|
+
// Output codes after transformed with plugin
|
|
139
|
+
r#"
|
|
140
|
+
function defineAppConfig(config) {return config}
|
|
141
|
+
const config = defineAppConfig({})
|
|
142
|
+
export default config
|
|
143
|
+
"#
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
test!(
|
|
147
|
+
Default::default(),
|
|
148
|
+
|_| as_folder(TransformVisitor),
|
|
149
|
+
var_decl_page,
|
|
150
|
+
// Input codes
|
|
151
|
+
r#"
|
|
152
|
+
const config = definePageConfig({})
|
|
153
|
+
export default config
|
|
154
|
+
"#,
|
|
155
|
+
// Output codes after transformed with plugin
|
|
156
|
+
r#"
|
|
157
|
+
function definePageConfig(config) {return config}
|
|
158
|
+
const config = definePageConfig({})
|
|
159
|
+
export default config
|
|
160
|
+
"#
|
|
161
|
+
);
|
|
162
|
+
|
|
173
163
|
test!(
|
|
174
164
|
Default::default(),
|
|
175
165
|
|_| as_folder(TransformVisitor),
|
|
176
|
-
|
|
166
|
+
module_exports,
|
|
177
167
|
// Input codes
|
|
178
168
|
r#"
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
var require_index_config = __commonJS({
|
|
170
|
+
"src/pages/index/index.config.ts": function(exports1, module) {
|
|
171
|
+
var config = definePageConfig({
|
|
172
|
+
navigationBarTitleText: "首页",
|
|
173
|
+
usingComponents: {}
|
|
174
|
+
});
|
|
175
|
+
module.exports = config;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
var _default = require_index_config();
|
|
181
179
|
"#,
|
|
182
180
|
// Output codes after transformed with plugin
|
|
183
181
|
r#"
|
|
184
182
|
function definePageConfig(config) {return config}
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
var require_index_config = __commonJS({
|
|
184
|
+
"src/pages/index/index.config.ts": function(exports1, module) {
|
|
185
|
+
var config = definePageConfig({
|
|
186
|
+
navigationBarTitleText: "首页",
|
|
187
|
+
usingComponents: {}
|
|
188
|
+
});
|
|
189
|
+
module.exports = config;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
var _default = require_index_config();
|
|
187
193
|
"#
|
|
188
194
|
);
|