@tarojs/helper 4.0.0-beta.0 → 4.0.0-canary.1
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 +2 -2
- package/dist/esbuild/index.js.map +1 -1
- package/dist/utils.js +3 -6
- package/dist/utils.js.map +1 -1
- package/package.json +4 -3
- package/swc/.gitkeep +0 -0
- package/swc/swc_plugin_compile_mode.wasm +0 -0
- package/swc/swc_plugin_define_config.wasm +0 -0
- package/swc/plugin-compile-mode/.cargo/config +0 -5
- package/swc/plugin-compile-mode/.editorconfig +0 -6
- package/swc/plugin-compile-mode/.vscode/settings.json +0 -3
- package/swc/plugin-compile-mode/Cargo.lock +0 -2021
- package/swc/plugin-compile-mode/Cargo.toml +0 -22
- package/swc/plugin-compile-mode/package.json +0 -15
- package/swc/plugin-compile-mode/src/lib.rs +0 -71
- package/swc/plugin-compile-mode/src/tests/attributes.rs +0 -54
- package/swc/plugin-compile-mode/src/tests/children.rs +0 -86
- package/swc/plugin-compile-mode/src/tests/condition.rs +0 -50
- package/swc/plugin-compile-mode/src/tests/entry.rs +0 -20
- package/swc/plugin-compile-mode/src/tests/harmony/attributes.rs +0 -45
- package/swc/plugin-compile-mode/src/tests/harmony/children.rs +0 -74
- package/swc/plugin-compile-mode/src/tests/harmony/condition.rs +0 -79
- package/swc/plugin-compile-mode/src/tests/harmony/entry.rs +0 -67
- package/swc/plugin-compile-mode/src/tests/harmony/looping.rs +0 -62
- package/swc/plugin-compile-mode/src/tests/harmony/mod.rs +0 -45
- package/swc/plugin-compile-mode/src/tests/looping.rs +0 -84
- package/swc/plugin-compile-mode/src/tests/mod.rs +0 -100
- package/swc/plugin-compile-mode/src/tests/shake.rs +0 -27
- package/swc/plugin-compile-mode/src/transform.rs +0 -474
- package/swc/plugin-compile-mode/src/transform_harmony.rs +0 -526
- package/swc/plugin-compile-mode/src/utils/constants.rs +0 -152
- package/swc/plugin-compile-mode/src/utils/harmony/components.rs +0 -61
- package/swc/plugin-compile-mode/src/utils/harmony/mod.rs +0 -1
- package/swc/plugin-compile-mode/src/utils/mod.rs +0 -347
- package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_handle_events.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_keep_static_attrs_only_in_templates.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_turn_dynamic_attrs.js +0 -11
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_native_component.js +0 -7
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_react_component.js +0 -7
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_fragment.js +0 -44
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_render_fn.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_and_expr.js +0 -14
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_conditional_expr.js +0 -15
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/entry.rs/should_support_multi_compile_mode.js +0 -10
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_handle_events.js +0 -183
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_turn_dynamic_attrs.js +0 -186
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_render_react_component.js +0 -76
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_fragment.js +0 -341
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_render_fn.js +0 -186
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_and_expr.js +0 -211
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_complex_condition.js +0 -244
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_and_unkonw_component.js +0 -139
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_expr.js +0 -344
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_compile_child_node.js +0 -141
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_component_not_in_config.js +0 -91
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_multi_compile_mode.js +0 -209
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_single_compile_mode.js +0 -66
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +0 -76
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt_and_set_parent_dynamic_id.js +0 -89
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_function_expr.js +0 -86
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_expr.js +0 -6
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_function_expr.js +0 -20
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_support_nested_loop.js +0 -15
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/shake.rs/should_static_jsx_being_shaked.js +0 -20
- package/swc/plugin-define-config/.cargo/config +0 -5
- package/swc/plugin-define-config/Cargo.lock +0 -2110
- package/swc/plugin-define-config/Cargo.toml +0 -18
- package/swc/plugin-define-config/src/lib.rs +0 -141
- package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_app.js +0 -2
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_page.js +0 -2
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_exports.js +0 -11
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_app.js +0 -3
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_page.js +0 -3
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
pub fn get_component_attr_str (node_name: &str, tag_name: &str) -> String {
|
|
2
|
-
if tag_name == "text" {
|
|
3
|
-
format!(".textStyle(getNormalAttributes(this.{} as TaroElement))\n.textAttr(getFontAttributes(this.{} as TaroElement))", node_name, node_name)
|
|
4
|
-
} else if tag_name == "image" {
|
|
5
|
-
format!(".attrsImage(getNormalAttributes(this.{} as TaroElement))", node_name)
|
|
6
|
-
} else {
|
|
7
|
-
format!(".attrs(getNormalAttributes(this.{} as TaroElement))", node_name)
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
pub fn get_component_style_str (node_name: &str, tag_name: &str) -> String {
|
|
12
|
-
format!(
|
|
13
|
-
r#"{}
|
|
14
|
-
.onVisibleAreaChange(getNodeThresholds(this.{node_id} as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.{node_id} as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
|
|
15
|
-
.onAreaChange(getComponentEventCallback(this.{node_id} as TaroElement, AREA_CHANGE_EVENT_NAME, res => {{
|
|
16
|
-
const eventResult: TaroAny = res.eventResult
|
|
17
|
-
this.nodeInfoMap[this.{node_id}._nid].areaInfo = eventResult[1]
|
|
18
|
-
}}))"#,
|
|
19
|
-
get_component_attr_str(node_name, tag_name),
|
|
20
|
-
node_id = node_name,
|
|
21
|
-
)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
pub fn get_view_component_str (node_name: &str, child_content: &str) -> String {
|
|
26
|
-
format!("Flex(FlexManager.flexOptions(this.{node_id} as TaroElement)) {{{children}}}\n{style}",
|
|
27
|
-
node_id = node_name,
|
|
28
|
-
children = match child_content {
|
|
29
|
-
"" => "".to_string(),
|
|
30
|
-
_ => format!("\n{}", child_content)
|
|
31
|
-
},
|
|
32
|
-
style = get_component_style_str(node_name, "view")
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
pub fn get_image_component_str (node_name: &str) -> String {
|
|
37
|
-
format!("Image((this.{node_id} as TaroElement).getAttribute('src'))\n.objectFit(getImageMode((this.{node_id} as TaroElement).getAttribute('mode')))\n{style}",
|
|
38
|
-
node_id = node_name,
|
|
39
|
-
style = get_component_style_str(node_name, "image")
|
|
40
|
-
)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
pub fn get_text_component_str (node_name: &str) -> String {
|
|
44
|
-
format!("Text(this.{node_id}.textContent)\n{style}",
|
|
45
|
-
node_id = node_name,
|
|
46
|
-
style = get_component_style_str(node_name, "text")
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
pub fn create_component_event (event_name: &str, node_name: &str) -> String {
|
|
52
|
-
let process_event_trigger_name = |name: &str| -> String {
|
|
53
|
-
if name == "touch" {
|
|
54
|
-
String::from("TOUCH_EVENT_MAP.get(e.type)")
|
|
55
|
-
} else {
|
|
56
|
-
format!("'{}'", name)
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
format!("\n.{}(e => eventHandler(e, {}, this.{} as TaroElement))", event_name, process_event_trigger_name(&event_name.get(2..).unwrap().to_lowercase()), node_name)
|
|
61
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
pub mod components;
|
|
@@ -1,347 +0,0 @@
|
|
|
1
|
-
use swc_core::{
|
|
2
|
-
ecma::{
|
|
3
|
-
atoms::Atom,
|
|
4
|
-
ast::*,
|
|
5
|
-
utils::quote_str,
|
|
6
|
-
},
|
|
7
|
-
common::{
|
|
8
|
-
iter::IdentifyLast,
|
|
9
|
-
util::take::Take,
|
|
10
|
-
DUMMY_SP as span
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
use std::collections::HashMap;
|
|
14
|
-
|
|
15
|
-
use self::{constants::*, harmony::components::get_text_component_str};
|
|
16
|
-
use crate::PluginConfig;
|
|
17
|
-
use crate::transform_harmony::TransformVisitor;
|
|
18
|
-
|
|
19
|
-
pub mod harmony;
|
|
20
|
-
pub mod constants;
|
|
21
|
-
|
|
22
|
-
pub fn named_iter (str: String) -> impl FnMut() -> String {
|
|
23
|
-
let mut count = -1;
|
|
24
|
-
return move || {
|
|
25
|
-
count += 1;
|
|
26
|
-
format!("{str}{count}")
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
pub fn jsx_text_to_string (atom: &Atom) -> String {
|
|
31
|
-
let content = atom.replace("\t", " ");
|
|
32
|
-
|
|
33
|
-
let res = content
|
|
34
|
-
.lines()
|
|
35
|
-
.enumerate()
|
|
36
|
-
.identify_last()
|
|
37
|
-
.fold(String::new(), |mut acc, (is_last, (index, line))| {
|
|
38
|
-
// 首行不 trim 头
|
|
39
|
-
let line = if index == 0 {
|
|
40
|
-
line
|
|
41
|
-
} else {
|
|
42
|
-
line.trim_start()
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// 尾行不 trim 尾
|
|
46
|
-
let line = if is_last {
|
|
47
|
-
line
|
|
48
|
-
} else {
|
|
49
|
-
line.trim_end()
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
if !acc.is_empty() && !line.is_empty() {
|
|
53
|
-
acc.push(' ');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
acc.push_str(line);
|
|
57
|
-
acc
|
|
58
|
-
});
|
|
59
|
-
res
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 将驼峰写法转换为 kebab-case,即 aBcD -> a-bc-d
|
|
63
|
-
pub fn to_kebab_case (val: &str) -> String {
|
|
64
|
-
let mut res = String::new();
|
|
65
|
-
val
|
|
66
|
-
.chars()
|
|
67
|
-
.enumerate()
|
|
68
|
-
.for_each(|(idx, c)| {
|
|
69
|
-
if idx != 0 && c.is_uppercase() {
|
|
70
|
-
res.push('-');
|
|
71
|
-
}
|
|
72
|
-
res.push(c.to_ascii_lowercase());
|
|
73
|
-
});
|
|
74
|
-
res
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
pub fn convert_jsx_attr_key (jsx_key: &str, adapter: &HashMap<String, String>) -> String {
|
|
78
|
-
if jsx_key == "className" {
|
|
79
|
-
return String::from("class");
|
|
80
|
-
} else if
|
|
81
|
-
jsx_key == COMPILE_IF ||
|
|
82
|
-
jsx_key == COMPILE_ELSE ||
|
|
83
|
-
jsx_key == COMPILE_FOR ||
|
|
84
|
-
jsx_key == COMPILE_FOR_KEY
|
|
85
|
-
{
|
|
86
|
-
let expr = match jsx_key {
|
|
87
|
-
COMPILE_IF => "if",
|
|
88
|
-
COMPILE_ELSE => "else",
|
|
89
|
-
COMPILE_FOR => "for",
|
|
90
|
-
COMPILE_FOR_KEY => "key",
|
|
91
|
-
_ => ""
|
|
92
|
-
};
|
|
93
|
-
let adapter = adapter.get(expr).expect(&format!("[compile mode] 模板 {} 语法未配置", expr));
|
|
94
|
-
return adapter.clone()
|
|
95
|
-
}
|
|
96
|
-
to_kebab_case(jsx_key)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
pub fn check_is_event_attr (val: &str) -> bool {
|
|
100
|
-
val.starts_with("on") && val.chars().nth(2).is_some_and(|x| x.is_uppercase())
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
pub fn identify_jsx_event_key (val: &str) -> Option<String> {
|
|
104
|
-
if check_is_event_attr(val) {
|
|
105
|
-
let event_name = val.get(2..).unwrap().to_lowercase();
|
|
106
|
-
let event_name = if event_name == "click" {
|
|
107
|
-
"tap"
|
|
108
|
-
} else {
|
|
109
|
-
&event_name
|
|
110
|
-
};
|
|
111
|
-
Some(format!("bind{}", event_name))
|
|
112
|
-
} else {
|
|
113
|
-
return None;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
pub fn is_inner_component (el: &mut Box<JSXElement>, config: &PluginConfig) -> bool {
|
|
118
|
-
let opening = &el.opening;
|
|
119
|
-
if let JSXElementName::Ident(Ident { sym, .. }) = &opening.name {
|
|
120
|
-
let name = to_kebab_case(&sym);
|
|
121
|
-
return config.components.get(&name).is_some();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
false
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
pub fn is_static_jsx (el: &Box<JSXElement>) -> bool {
|
|
128
|
-
if el.opening.attrs.len() > 0 {
|
|
129
|
-
return false
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
for child in &el.children {
|
|
133
|
-
if let JSXElementChild::JSXText(_) = child {
|
|
134
|
-
} else {
|
|
135
|
-
return false
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
true
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
pub fn create_self_closing_jsx_element_expr (name: JSXElementName, attrs: Option<Vec<JSXAttrOrSpread>>) -> Expr {
|
|
143
|
-
Expr::JSXElement(Box::new(JSXElement {
|
|
144
|
-
span,
|
|
145
|
-
opening: JSXOpeningElement {
|
|
146
|
-
name,
|
|
147
|
-
span,
|
|
148
|
-
attrs: attrs.unwrap_or(vec![]),
|
|
149
|
-
self_closing: true,
|
|
150
|
-
type_args: None
|
|
151
|
-
},
|
|
152
|
-
children: vec![],
|
|
153
|
-
closing: None
|
|
154
|
-
}))
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
pub fn create_jsx_expr_attr (name: &str, expr: Box<Expr>) -> JSXAttrOrSpread {
|
|
158
|
-
JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
159
|
-
span,
|
|
160
|
-
name: JSXAttrName::Ident(Ident::new(name.into(), span)),
|
|
161
|
-
value: Some(JSXAttrValue::JSXExprContainer(JSXExprContainer {
|
|
162
|
-
span,
|
|
163
|
-
expr: JSXExpr::Expr(expr)
|
|
164
|
-
}))
|
|
165
|
-
})
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
pub fn create_jsx_bool_attr (name: &str) -> JSXAttrOrSpread {
|
|
169
|
-
JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
170
|
-
span,
|
|
171
|
-
name: JSXAttrName::Ident(Ident::new(name.into(), span)),
|
|
172
|
-
value: None
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
pub fn create_jsx_lit_attr (name: &str, lit: Lit) -> JSXAttrOrSpread {
|
|
177
|
-
JSXAttrOrSpread::JSXAttr(JSXAttr {
|
|
178
|
-
span,
|
|
179
|
-
name: JSXAttrName::Ident(Ident::new(name.into(), span)),
|
|
180
|
-
value: Some(JSXAttrValue::Lit(lit))
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
pub fn create_jsx_dynamic_id (el: &mut JSXElement, visitor: &mut TransformVisitor) -> String {
|
|
185
|
-
let node_name = (visitor.get_node_name)();
|
|
186
|
-
|
|
187
|
-
visitor.node_name_vec.push(node_name.clone());
|
|
188
|
-
el.opening.attrs.push(create_jsx_lit_attr(DYNAMIC_ID, node_name.clone().into()));
|
|
189
|
-
node_name
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
pub fn add_spaces_to_lines(input: &str) -> String {
|
|
193
|
-
let count = 2;
|
|
194
|
-
let mut result = String::new();
|
|
195
|
-
|
|
196
|
-
for line in input.lines() {
|
|
197
|
-
let spaces = " ".repeat(count);
|
|
198
|
-
result.push_str(&format!("{}{}\n", spaces, line));
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
result
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
pub fn get_harmony_component_style (visitor: &mut TransformVisitor) -> String {
|
|
205
|
-
let component_set = &visitor.component_set;
|
|
206
|
-
let mut harmony_component_style = String::new();
|
|
207
|
-
|
|
208
|
-
let mut build_component = |component_tag: &str, component_style: &str| {
|
|
209
|
-
if component_set.contains(component_tag) {
|
|
210
|
-
harmony_component_style.push_str(component_style);
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
build_component(VIEW_TAG, HARMONY_FLEX_STYLE_BIND);
|
|
215
|
-
build_component(IMAGE_TAG, HARMONY_IMAGE_STYLE_BIND);
|
|
216
|
-
build_component(TEXT_TAG, HARMONY_TEXT_STYLE_BIND);
|
|
217
|
-
|
|
218
|
-
harmony_component_style
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
pub fn check_jsx_element_has_compile_ignore (el: &JSXElement) -> bool {
|
|
222
|
-
for attr in &el.opening.attrs {
|
|
223
|
-
if let JSXAttrOrSpread::JSXAttr(JSXAttr { name, .. }) = attr {
|
|
224
|
-
if let JSXAttrName::Ident(Ident { sym, .. }) = name {
|
|
225
|
-
if sym == COMPILE_IGNORE {
|
|
226
|
-
return true
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
false
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* identify: `xx.map(function () {})` or `xx.map(() => {})`
|
|
236
|
-
*/
|
|
237
|
-
pub fn is_call_expr_of_loop (callee_expr: &mut Box<Expr>, args: &mut Vec<ExprOrSpread>) -> bool {
|
|
238
|
-
if let Expr::Member(MemberExpr { prop: MemberProp::Ident(Ident { sym, ..}), .. }) = &mut **callee_expr {
|
|
239
|
-
if sym == "map" {
|
|
240
|
-
if let Some(ExprOrSpread { expr, .. }) = args.get_mut(0) {
|
|
241
|
-
return expr.is_arrow() || expr.is_fn_expr()
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return false
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
pub fn is_render_fn (callee_expr: &mut Box<Expr>) -> bool {
|
|
249
|
-
fn is_starts_with_render (name: &str) -> bool {
|
|
250
|
-
name.starts_with("render")
|
|
251
|
-
}
|
|
252
|
-
match &**callee_expr {
|
|
253
|
-
Expr::Member(MemberExpr { prop: MemberProp::Ident(Ident { sym: name, .. }), .. }) => {
|
|
254
|
-
is_starts_with_render(name)
|
|
255
|
-
},
|
|
256
|
-
Expr::Ident(Ident { sym: name, .. }) => {
|
|
257
|
-
is_starts_with_render(name)
|
|
258
|
-
},
|
|
259
|
-
_ => false
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
pub fn extract_jsx_loop <'a> (callee_expr: &mut Box<Expr>, args: &'a mut Vec<ExprOrSpread>) -> Option<&'a mut Box<JSXElement>> {
|
|
264
|
-
if is_call_expr_of_loop(callee_expr, args) {
|
|
265
|
-
if let Some(ExprOrSpread { expr, .. }) = args.get_mut(0) {
|
|
266
|
-
fn update_return_el (return_value: &mut Box<Expr>) -> Option<&mut Box<JSXElement>> {
|
|
267
|
-
if let Expr::Paren(ParenExpr { expr, .. }) = &mut **return_value {
|
|
268
|
-
*return_value = expr.take()
|
|
269
|
-
}
|
|
270
|
-
if return_value.is_jsx_element() {
|
|
271
|
-
let el = return_value.as_mut_jsx_element().unwrap();
|
|
272
|
-
el.opening.attrs.push(create_jsx_bool_attr(COMPILE_FOR));
|
|
273
|
-
el.opening.attrs.push(create_jsx_lit_attr(COMPILE_FOR_KEY, Lit::Str(quote_str!("sid"))));
|
|
274
|
-
return Some(el)
|
|
275
|
-
}
|
|
276
|
-
None
|
|
277
|
-
}
|
|
278
|
-
match &mut **expr {
|
|
279
|
-
Expr::Fn(FnExpr { function, .. }) => {
|
|
280
|
-
if let Function { body: Some(BlockStmt { stmts, .. }), .. } = &mut **function {
|
|
281
|
-
if let Some(Stmt::Return(ReturnStmt { arg: Some(return_value), .. })) = stmts.last_mut() {
|
|
282
|
-
return update_return_el(return_value);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
},
|
|
286
|
-
Expr::Arrow(ArrowExpr { body, .. }) => {
|
|
287
|
-
match &mut **body {
|
|
288
|
-
BlockStmtOrExpr::BlockStmt(BlockStmt { stmts, .. }) => {
|
|
289
|
-
if let Some(Stmt::Return(ReturnStmt { arg: Some(return_value), .. })) = stmts.last_mut() {
|
|
290
|
-
return update_return_el(return_value);
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
BlockStmtOrExpr::Expr(return_value) => {
|
|
294
|
-
return update_return_el(return_value);
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
},
|
|
298
|
-
_ => ()
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
None
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
pub fn check_jsx_element_children_exist_loop (el: &mut JSXElement) -> bool {
|
|
306
|
-
for child in el.children.iter_mut() {
|
|
307
|
-
if let JSXElementChild::JSXExprContainer(JSXExprContainer { expr: JSXExpr::Expr(expr), .. }) = child {
|
|
308
|
-
if let Expr::Call(CallExpr { callee: Callee::Expr(callee_expr), args, .. }) = &mut **expr {
|
|
309
|
-
if is_call_expr_of_loop(callee_expr, args) {
|
|
310
|
-
return true
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
false
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
pub fn create_original_node_renderer_foreach (visitor: &mut TransformVisitor) -> String {
|
|
320
|
-
add_spaces_to_lines(format!("ForEach(this.{}.childNodes, (item: TaroElement) => {{\n createNode(item)\n}}, (item: TaroElement) => item._nid)", visitor.get_current_node_path()).as_str())
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
pub fn create_original_node_renderer (visitor: &mut TransformVisitor) -> String {
|
|
324
|
-
add_spaces_to_lines(format!("createNode(this.{} as TaroElement)", visitor.get_current_node_path()).as_str())
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
pub fn create_normal_text_template (visitor: &mut TransformVisitor) -> String {
|
|
328
|
-
let node_path = visitor.get_current_node_path();
|
|
329
|
-
let code = add_spaces_to_lines(get_text_component_str(&node_path).as_str());
|
|
330
|
-
|
|
331
|
-
visitor.component_set.insert(TEXT_TAG.clone().to_string());
|
|
332
|
-
|
|
333
|
-
code
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
pub fn gen_template_v (node_path: &str) -> String {
|
|
337
|
-
format!("{{{{{}.v}}}}", node_path)
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
#[test]
|
|
341
|
-
fn test_jsx_text () {
|
|
342
|
-
assert_eq!(" span ", jsx_text_to_string(&" span ".into()));
|
|
343
|
-
assert_eq!(" s xxx ", jsx_text_to_string(&" s\n \n \n xxx ".into()));
|
|
344
|
-
assert_eq!("a b", jsx_text_to_string(&" \n \n a b \n ".into()));
|
|
345
|
-
assert_eq!("", jsx_text_to_string(&"\n\n\n\n\n\n \n\n ".into()));
|
|
346
|
-
assert_eq!("", jsx_text_to_string(&"".into()));
|
|
347
|
-
}
|
|
Binary file
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view bindtap="eh" data-sid="{{i.cn[0].sid}}" id="{{i.cn[0].sid}}"></view><view bindanimationstart="eh" data-sid="{{i.cn[1].sid}}" id="{{i.cn[1].id}}"></view><image bindload="eh" data-sid="{{i.cn[2].sid}}" id="myImg"></image></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
<View onClick={handleViewClick}></View>
|
|
5
|
-
<View onAnimationStart={() => {}} id={myId}></View>
|
|
6
|
-
<Image onLoad={() => {}} />
|
|
7
|
-
</View>
|
|
8
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><image class="my_img" lazy-load="true" src="https://taro.com/x.png"></image></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
|
|
5
|
-
<Image key="image" ref={myRefCb}/>
|
|
6
|
-
|
|
7
|
-
</View>;
|
|
8
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view class="{{i.cn[0].cl}}"><view custom-prop="{{i.cn[0].cn[0].customProp}}" style="{{i.cn[0].cn[0].st}}"></view><view hover-stay-time="{{xs.b(i.cn[0].cn[1].p3,400)}}"><view hover-class="{{xs.b(i.cn[0].cn[1].cn[0].p1,\'none\')}}"></view></view></view></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
<View class={myClass}>
|
|
5
|
-
<View style={myStyle} customProp={myCustomProp}></View>
|
|
6
|
-
<View hoverStayTime={myTime}>
|
|
7
|
-
<View hoverClass={myHoverClass}></View>
|
|
8
|
-
</View>
|
|
9
|
-
</View>
|
|
10
|
-
</View>;
|
|
11
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><template is="{{xs.a(c, i.cn[0].nn, l)}}" data="{{i:i.cn[0],c:c+1,l:xs.f(l,i.cn[0].nn)}}" /><template is="{{xs.a(c, i.cn[1].nn, l)}}" data="{{i:i.cn[1],c:c+1,l:xs.f(l,i.cn[1].nn)}}" /></view></template>'
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
<comp />
|
|
5
|
-
<comp type="primary" loading loading-text={loadingText} onMyevent={() => {}} />
|
|
6
|
-
</View>;
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><template is="{{xs.a(c, i.cn[0].nn, l)}}" data="{{i:i.cn[0],c:c+1,l:xs.f(l,i.cn[0].nn)}}" /><template is="{{xs.a(c, i.cn[1].nn, l)}}" data="{{i:i.cn[1],c:c+1,l:xs.f(l,i.cn[1].nn)}}" /></view></template>'
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
<Foo/>
|
|
5
|
-
<Foo title={myTitle} loading onClick={()=>{}}/>
|
|
6
|
-
</View>;
|
|
7
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view>{{i.cn[0].v}}<view>{{i.cn[1].cn[0].v}}</view><view>hello</view><view><view>{{i.cn[2].cn[0].cn[0].v}}</view><view>hello!</view></view><view>{{i.cn[3].cn[0].v}}</view><view>{{i.cn[4].cn[0].v}}</view><view>{{i.cn[5].cn[0].v}}</view><view>hello!!</view><view>hello!!!</view><view>{{i.cn[6].cn[0].v}}</view></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
|
|
5
|
-
{content0}
|
|
6
|
-
|
|
7
|
-
<>
|
|
8
|
-
|
|
9
|
-
<View>{content1}</View>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<View>
|
|
14
|
-
|
|
15
|
-
<>
|
|
16
|
-
|
|
17
|
-
<View>{content2}</View>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
</>
|
|
22
|
-
|
|
23
|
-
</View>
|
|
24
|
-
|
|
25
|
-
<View>{content3}</View>
|
|
26
|
-
|
|
27
|
-
</>
|
|
28
|
-
|
|
29
|
-
<View>{content4}</View>
|
|
30
|
-
|
|
31
|
-
<>
|
|
32
|
-
|
|
33
|
-
<View>{content5}</View>
|
|
34
|
-
|
|
35
|
-
</>
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
<View>{content6}</View>
|
|
42
|
-
|
|
43
|
-
</View>;
|
|
44
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view><template is="{{xs.a(c, i.cn[0].cn[0].nn, l)}}" data="{{i:i.cn[0].cn[0],c:c+1,l:xs.f(l,i.cn[0].cn[0].nn)}}" /></view><view><template is="{{xs.a(c, i.cn[1].cn[0].nn, l)}}" data="{{i:i.cn[1].cn[0],c:c+1,l:xs.f(l,i.cn[1].cn[0].nn)}}" /></view><view>{{i.cn[2].cn[0].v}}</view></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
<View>{renderHeader()}</View>
|
|
5
|
-
<View>{this.methods.renderFooter()}</View>
|
|
6
|
-
<View>{normalFunc()}</View>
|
|
7
|
-
</View>;
|
|
8
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(i.cn[0].p1,\'none\')}}" wx:if="{{i.cn[0].compileIf}}">{{i.cn[0].cn[0].v}}</view><view hover-class="{{xs.b(i.cn[1].p1,\'none\')}}" wx:if="{{i.cn[1].compileIf}}">{{i.cn[1].cn[0].v}}</view><view hover-class="{{xs.b(i.cn[2].p1,\'none\')}}" wx:if="{{i.cn[2].compileIf}}">{{i.cn[2].cn[0].v}}</view>{{i.cn[3].v==="compileIgnore"?"":i.cn[3].v}}<view bindtap="eh" data-sid="{{i.cn[4].sid}}" id="{{i.cn[4].sid}}" wx:if="{{i.cn[4].compileIf}}"></view><view hover-class="{{xs.b(i.cn[5].p1,\'none\')}}"></view><view><block wx:if="{{i.cn[6].cn[0].compileIf}}">{{i.cn[6].cn[0].cn[0].v}}</block></view><view><block wx:if="{{i.cn[7].cn[0].compileIf}}">{{i.cn[7].cn[0].cn[0].v}}</block></view><view><block wx:if="{{i.cn[8].cn[0].compileIf}}">{{i.cn[8].cn[0].cn[0].v}}</block></view></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <View/>}
|
|
5
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <View/>}
|
|
6
|
-
{condition1 && "condition2" && condition3 ? <View hoverClass={myClass} compileIf={condition1 && "condition2" && condition3}>{content}</View> : <View/>}
|
|
7
|
-
{condition1 ? 'Hello' : "compileIgnore"}
|
|
8
|
-
{condition1 ? <View onClick={()=>condition2 && doSth()} compileIf={condition1}/> : <View/>}
|
|
9
|
-
<View hoverClass={myClass}></View>
|
|
10
|
-
<View>{condition1 ? <block compileIf={condition1}>{ident}</block> : <block/>}</View>
|
|
11
|
-
<View>{condition1 ? <block compileIf={condition1}>{obj.property}</block> : <block/>}</View>
|
|
12
|
-
<View>{condition1 ? <block compileIf={condition1}>{fn()}</block> : <block/>}</View>
|
|
13
|
-
</View>;
|
|
14
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(i.cn[0].p1,\'none\')}}" wx:if="{{i.cn[0].compileIf}}">{{i.cn[0].cn[0].v}}</view><text selectable="true" wx:else>hello</text><block wx:if="{{i.cn[1].compileIf}}"><view wx:if="{{i.cn[1].cn[0].compileIf}}">{{i.cn[1].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[1].cn[0].cn[0].v}}</text></block><view wx:else>{{i.cn[1].cn[0].v}}</view><view wx:if="{{i.cn[2].compileIf}}">{{i.cn[2].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[2].cn[0].compileIf}}">{{i.cn[2].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[2].cn[0].cn[0].v}}</text></block><view wx:if="{{i.cn[3].compileIf}}">{{i.cn[3].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[3].cn[0].compileIf}}">{{i.cn[3].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[3].cn[0].cn[0].v}}</text></block><block wx:if="{{i.cn[4].compileIf}}"><view wx:if="{{i.cn[4].cn[0].compileIf}}">{{i.cn[4].cn[0].cn[0].v}}</view></block><view wx:else>{{i.cn[4].cn[0].v}}</view><view wx:if="{{i.cn[5].compileIf}}">{{i.cn[5].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[5].cn[0].compileIf}}">{{i.cn[5].cn[0].cn[0].v}}</view></block><block wx:if="{{i.cn[6].compileIf}}">{{i.cn[6].cn[0].v}}</block><block wx:else>{{i.cn[6].cn[0].v}}</block><view class="{{i.cn[7].cl}}" wx:if="{{i.cn[7].compileIf}}"></view><view wx:else></view><view wx:if="{{i.cn[8].compileIf}}"><view wx:if="{{i.cn[8].cn[0].compileIf}}"></view><view wx:else></view></view><view wx:else></view><view hover-class="{{xs.b(i.cn[9].p1,\'none\')}}"></view></view></template>';
|
|
2
|
-
function Index() {
|
|
3
|
-
return <View compileMode="f0t0">
|
|
4
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <Text></Text>}
|
|
5
|
-
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <Text>{b}</Text>}</block> : <View>{c}</View>}
|
|
6
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
|
|
7
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
|
|
8
|
-
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <View/>}</block> : <View>{b}</View>}
|
|
9
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <View/>}</block>}
|
|
10
|
-
{condition1 ? <block compileIf={condition1}>{"someText"}</block> : <block>{789}</block>}
|
|
11
|
-
{condition1 ? <View className={condition2 ? '' : ''} compileIf={condition1}/> : <View/>}
|
|
12
|
-
{condition1 ? <View compileIf={condition1}>{condition2 ? <View compileIf={condition2}/> : <View/>}</View> : <View/>}
|
|
13
|
-
<View hoverClass={myClass}></View>
|
|
14
|
-
</View>;
|
|
15
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><image src="{{i.p3}}"></image></template>';
|
|
2
|
-
const TARO_TEMPLATES_f0t1 = '<template name="tmpl_0_f0t1"><view><text>{{i.cn[0].cn[0].v}}</text></view></template>';
|
|
3
|
-
function Index() {
|
|
4
|
-
return <View>
|
|
5
|
-
<Image src={mySrc} compileMode="f0t0" />
|
|
6
|
-
<View compileMode="f0t1">
|
|
7
|
-
<Text>{myText}</Text>
|
|
8
|
-
</View>
|
|
9
|
-
</View>;
|
|
10
|
-
}
|