@tarojs/helper 3.6.9-alpha.8 → 3.6.9
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/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/esbuild/index.js +0 -1
- package/dist/esbuild/index.js.map +1 -1
- package/dist/swcRegister.d.ts +6 -0
- package/dist/swcRegister.js +15 -0
- package/dist/swcRegister.js.map +1 -1
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +9 -5
- package/dist/utils.js.map +1 -1
- package/package.json +4 -4
- package/swc/plugin-define-config/Cargo.lock +340 -492
- package/swc/plugin-define-config/Cargo.toml +11 -3
- package/swc/plugin-define-config/src/lib.rs +120 -126
- package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "swc-plugin-define-config"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.1.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
|
|
10
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"
|
|
11
19
|
|
|
12
20
|
[dependencies]
|
|
13
21
|
serde = "1"
|
|
14
|
-
swc_core = { version = "0.
|
|
15
|
-
swc_ecma_utils = "0.120.1"
|
|
22
|
+
swc_core = { version = "0.40.*", features = ["plugin_transform"] }
|
|
16
23
|
|
|
17
24
|
# .cargo/config defines few alias to build plugin.
|
|
18
25
|
# cargo build-wasi generates wasm-wasi32 binary
|
|
19
26
|
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
|
|
27
|
+
|
|
@@ -1,75 +1,102 @@
|
|
|
1
|
-
use swc_core::{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
visit::{as_folder, FoldWith, VisitMut, VisitMutWith},
|
|
6
|
-
},
|
|
7
|
-
common::{
|
|
8
|
-
DUMMY_SP,
|
|
9
|
-
SyntaxContext
|
|
10
|
-
},
|
|
1
|
+
use swc_core::ecma::{
|
|
2
|
+
ast::*,
|
|
3
|
+
transforms::testing::test,
|
|
4
|
+
visit::{as_folder, FoldWith, VisitMut, VisitMutWith},
|
|
11
5
|
};
|
|
12
|
-
use
|
|
6
|
+
use swc_core::common::{DUMMY_SP, SyntaxContext};
|
|
13
7
|
use swc_core::plugin::{plugin_transform, proxies::TransformPluginProgramMetadata};
|
|
14
8
|
|
|
15
|
-
|
|
9
|
+
struct DefineConfig {
|
|
10
|
+
found: bool,
|
|
11
|
+
fn_name: String,
|
|
12
|
+
ctxt: SyntaxContext
|
|
13
|
+
}
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
impl DefineConfig {
|
|
16
|
+
fn new() -> Self {
|
|
17
|
+
Self {
|
|
18
|
+
found: false,
|
|
19
|
+
fn_name: String::from(""),
|
|
20
|
+
ctxt: SyntaxContext::empty()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
impl VisitMut for
|
|
23
|
-
fn visit_mut_call_expr(&mut self,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
}
|
|
32
37
|
}
|
|
38
|
+
}
|
|
33
39
|
}
|
|
34
40
|
}
|
|
35
41
|
|
|
42
|
+
pub struct TransformVisitor;
|
|
43
|
+
|
|
36
44
|
impl VisitMut for TransformVisitor {
|
|
37
|
-
|
|
38
|
-
|
|
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();
|
|
39
49
|
let mut line_to_be_insert: usize = 0;
|
|
40
50
|
|
|
41
|
-
for (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
+
}
|
|
46
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
|
+
}
|
|
47
69
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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 {
|
|
51
78
|
span: DUMMY_SP,
|
|
52
79
|
decorators: Default::default(),
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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));
|
|
71
98
|
}
|
|
72
|
-
|
|
99
|
+
}
|
|
73
100
|
}
|
|
74
101
|
|
|
75
102
|
/// An example plugin function with macro support.
|
|
@@ -89,7 +116,7 @@ impl VisitMut for TransformVisitor {
|
|
|
89
116
|
/// Refer swc_plugin_macro to see how does it work internally.
|
|
90
117
|
#[plugin_transform]
|
|
91
118
|
pub fn process_transform(program: Program, _metadata: TransformPluginProgramMetadata) -> Program {
|
|
92
|
-
|
|
119
|
+
program.fold_with(&mut as_folder(TransformVisitor))
|
|
93
120
|
}
|
|
94
121
|
|
|
95
122
|
// An example to test plugin transform.
|
|
@@ -97,98 +124,65 @@ pub fn process_transform(program: Program, _metadata: TransformPluginProgramMeta
|
|
|
97
124
|
// the Visitor's behavior, instead of trying to run `process_transform` with mocks
|
|
98
125
|
// unless explicitly required to do so.
|
|
99
126
|
test!(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
+
"#
|
|
112
154
|
);
|
|
113
155
|
|
|
114
156
|
test!(
|
|
115
157
|
Default::default(),
|
|
116
158
|
|_| as_folder(TransformVisitor),
|
|
117
|
-
|
|
159
|
+
var_decl_app,
|
|
118
160
|
// Input codes
|
|
119
161
|
r#"
|
|
120
|
-
|
|
162
|
+
const config = defineAppConfig({})
|
|
163
|
+
export default config
|
|
121
164
|
"#,
|
|
122
165
|
// Output codes after transformed with plugin
|
|
123
166
|
r#"
|
|
124
|
-
function
|
|
125
|
-
|
|
167
|
+
function defineAppConfig(config) {return config}
|
|
168
|
+
const config = defineAppConfig({})
|
|
169
|
+
export default config
|
|
126
170
|
"#
|
|
127
171
|
);
|
|
128
172
|
|
|
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
|
-
|
|
163
173
|
test!(
|
|
164
174
|
Default::default(),
|
|
165
175
|
|_| as_folder(TransformVisitor),
|
|
166
|
-
|
|
176
|
+
var_decl_page,
|
|
167
177
|
// Input codes
|
|
168
178
|
r#"
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
var config = definePageConfig({
|
|
172
|
-
navigationBarTitleText: "首页",
|
|
173
|
-
usingComponents: {}
|
|
174
|
-
});
|
|
175
|
-
module.exports = config;
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
var _default = require_index_config();
|
|
179
|
+
const config = definePageConfig({})
|
|
180
|
+
export default config
|
|
179
181
|
"#,
|
|
180
182
|
// Output codes after transformed with plugin
|
|
181
183
|
r#"
|
|
182
184
|
function definePageConfig(config) {return config}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
var config = definePageConfig({
|
|
186
|
-
navigationBarTitleText: "首页",
|
|
187
|
-
usingComponents: {}
|
|
188
|
-
});
|
|
189
|
-
module.exports = config;
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
var _default = require_index_config();
|
|
185
|
+
const config = definePageConfig({})
|
|
186
|
+
export default config
|
|
193
187
|
"#
|
|
194
188
|
);
|