@tarojs/helper 3.8.0-canary.0 → 4.0.0-beta.0

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 (85) hide show
  1. package/README.md +22 -0
  2. package/dist/constants.d.ts +5 -3
  3. package/dist/constants.js +24 -22
  4. package/dist/constants.js.map +1 -1
  5. package/dist/dotenv.js.map +1 -1
  6. package/dist/esbuild/index.js +6 -4
  7. package/dist/esbuild/index.js.map +1 -1
  8. package/dist/npm.d.ts +2 -2
  9. package/dist/npm.js +6 -6
  10. package/dist/npm.js.map +1 -1
  11. package/dist/swcRegister.d.ts +0 -6
  12. package/dist/swcRegister.js +0 -15
  13. package/dist/swcRegister.js.map +1 -1
  14. package/dist/utils.d.ts +33 -1
  15. package/dist/utils.js +87 -34
  16. package/dist/utils.js.map +1 -1
  17. package/package.json +19 -15
  18. package/swc/plugin-compile-mode/.cargo/config +5 -0
  19. package/swc/plugin-compile-mode/.editorconfig +6 -0
  20. package/swc/plugin-compile-mode/.vscode/settings.json +3 -0
  21. package/swc/plugin-compile-mode/Cargo.lock +195 -260
  22. package/swc/plugin-compile-mode/Cargo.toml +6 -4
  23. package/swc/plugin-compile-mode/package.json +15 -0
  24. package/swc/plugin-compile-mode/src/lib.rs +21 -2
  25. package/swc/plugin-compile-mode/src/tests/attributes.rs +1 -32
  26. package/swc/plugin-compile-mode/src/tests/children.rs +86 -0
  27. package/swc/plugin-compile-mode/src/tests/condition.rs +8 -29
  28. package/swc/plugin-compile-mode/src/tests/entry.rs +1 -13
  29. package/swc/plugin-compile-mode/src/tests/harmony/attributes.rs +45 -0
  30. package/swc/plugin-compile-mode/src/tests/harmony/children.rs +74 -0
  31. package/swc/plugin-compile-mode/src/tests/harmony/condition.rs +79 -0
  32. package/swc/plugin-compile-mode/src/tests/harmony/entry.rs +67 -0
  33. package/swc/plugin-compile-mode/src/tests/harmony/looping.rs +62 -0
  34. package/swc/plugin-compile-mode/src/tests/harmony/mod.rs +45 -0
  35. package/swc/plugin-compile-mode/src/tests/looping.rs +1 -51
  36. package/swc/plugin-compile-mode/src/tests/mod.rs +11 -9
  37. package/swc/plugin-compile-mode/src/tests/shake.rs +1 -15
  38. package/swc/plugin-compile-mode/src/transform.rs +142 -134
  39. package/swc/plugin-compile-mode/src/transform_harmony.rs +526 -0
  40. package/swc/plugin-compile-mode/src/utils/constants.rs +141 -0
  41. package/swc/plugin-compile-mode/src/utils/harmony/components.rs +61 -0
  42. package/swc/plugin-compile-mode/src/utils/harmony/mod.rs +1 -0
  43. package/swc/plugin-compile-mode/src/utils/mod.rs +126 -15
  44. package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
  45. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_handle_events.js +8 -0
  46. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_keep_static_attrs_only_in_templates.js +8 -0
  47. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_turn_dynamic_attrs.js +11 -0
  48. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_native_component.js +7 -0
  49. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_react_component.js +7 -0
  50. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_fragment.js +44 -0
  51. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_render_fn.js +8 -0
  52. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_and_expr.js +14 -0
  53. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_conditional_expr.js +15 -0
  54. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/entry.rs/should_support_multi_compile_mode.js +10 -0
  55. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_handle_events.js +183 -0
  56. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_turn_dynamic_attrs.js +186 -0
  57. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_render_react_component.js +76 -0
  58. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_fragment.js +341 -0
  59. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_render_fn.js +186 -0
  60. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_and_expr.js +211 -0
  61. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_complex_condition.js +244 -0
  62. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_and_unkonw_component.js +139 -0
  63. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_expr.js +344 -0
  64. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_compile_child_node.js +141 -0
  65. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_component_not_in_config.js +91 -0
  66. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_multi_compile_mode.js +209 -0
  67. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_single_compile_mode.js +66 -0
  68. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +76 -0
  69. 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 +89 -0
  70. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_function_expr.js +86 -0
  71. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +8 -0
  72. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_expr.js +6 -0
  73. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_function_expr.js +20 -0
  74. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_support_nested_loop.js +15 -0
  75. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/shake.rs/should_static_jsx_being_shaked.js +20 -0
  76. package/swc/plugin-define-config/.cargo/config +5 -0
  77. package/swc/plugin-define-config/Cargo.lock +582 -506
  78. package/swc/plugin-define-config/Cargo.toml +2 -11
  79. package/swc/plugin-define-config/src/lib.rs +81 -128
  80. package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
  81. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_app.js +2 -0
  82. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_page.js +2 -0
  83. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_exports.js +11 -0
  84. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_app.js +3 -0
  85. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_page.js +3 -0
@@ -0,0 +1,61 @@
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
+ }
@@ -0,0 +1 @@
1
+ pub mod components;
@@ -1,7 +1,8 @@
1
1
  use swc_core::{
2
2
  ecma::{
3
3
  atoms::Atom,
4
- ast::*
4
+ ast::*,
5
+ utils::quote_str,
5
6
  },
6
7
  common::{
7
8
  iter::IdentifyLast,
@@ -11,8 +12,11 @@ use swc_core::{
11
12
  };
12
13
  use std::collections::HashMap;
13
14
 
14
- use self::constants::*;
15
+ use self::{constants::*, harmony::components::get_text_component_str};
16
+ use crate::PluginConfig;
17
+ use crate::transform_harmony::TransformVisitor;
15
18
 
19
+ pub mod harmony;
16
20
  pub mod constants;
17
21
 
18
22
  pub fn named_iter (str: String) -> impl FnMut() -> String {
@@ -25,7 +29,7 @@ pub fn named_iter (str: String) -> impl FnMut() -> String {
25
29
 
26
30
  pub fn jsx_text_to_string (atom: &Atom) -> String {
27
31
  let content = atom.replace("\t", " ");
28
-
32
+
29
33
  let res = content
30
34
  .lines()
31
35
  .enumerate()
@@ -55,11 +59,7 @@ pub fn jsx_text_to_string (atom: &Atom) -> String {
55
59
  res
56
60
  }
57
61
 
58
- pub fn is_empty_jsx_text_line (atom: &Atom) -> bool {
59
- let str = jsx_text_to_string(atom);
60
- str.is_empty()
61
- }
62
-
62
+ // 将驼峰写法转换为 kebab-case,即 aBcD -> a-bc-d
63
63
  pub fn to_kebab_case (val: &str) -> String {
64
64
  let mut res = String::new();
65
65
  val
@@ -96,11 +96,12 @@ pub fn convert_jsx_attr_key (jsx_key: &str, adapter: &HashMap<String, String>) -
96
96
  to_kebab_case(jsx_key)
97
97
  }
98
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
+
99
103
  pub fn identify_jsx_event_key (val: &str) -> Option<String> {
100
- if
101
- val.starts_with("on") &&
102
- val.chars().nth(2).is_some_and(|x| x.is_uppercase())
103
- {
104
+ if check_is_event_attr(val) {
104
105
  let event_name = val.get(2..).unwrap().to_lowercase();
105
106
  let event_name = if event_name == "click" {
106
107
  "tap"
@@ -113,6 +114,16 @@ pub fn identify_jsx_event_key (val: &str) -> Option<String> {
113
114
  }
114
115
  }
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
+
116
127
  pub fn is_static_jsx (el: &Box<JSXElement>) -> bool {
117
128
  if el.opening.attrs.len() > 0 {
118
129
  return false
@@ -170,12 +181,62 @@ pub fn create_jsx_lit_attr (name: &str, lit: Lit) -> JSXAttrOrSpread {
170
181
  })
171
182
  }
172
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
+
173
234
  /**
174
235
  * identify: `xx.map(function () {})` or `xx.map(() => {})`
175
236
  */
176
237
  pub fn is_call_expr_of_loop (callee_expr: &mut Box<Expr>, args: &mut Vec<ExprOrSpread>) -> bool {
177
238
  if let Expr::Member(MemberExpr { prop: MemberProp::Ident(Ident { sym, ..}), .. }) = &mut **callee_expr {
178
- if &**sym == "map" {
239
+ if sym == "map" {
179
240
  if let Some(ExprOrSpread { expr, .. }) = args.get_mut(0) {
180
241
  return expr.is_arrow() || expr.is_fn_expr()
181
242
  }
@@ -184,6 +245,21 @@ pub fn is_call_expr_of_loop (callee_expr: &mut Box<Expr>, args: &mut Vec<ExprOrS
184
245
  return false
185
246
  }
186
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
+
187
263
  pub fn extract_jsx_loop <'a> (callee_expr: &mut Box<Expr>, args: &'a mut Vec<ExprOrSpread>) -> Option<&'a mut Box<JSXElement>> {
188
264
  if is_call_expr_of_loop(callee_expr, args) {
189
265
  if let Some(ExprOrSpread { expr, .. }) = args.get_mut(0) {
@@ -194,7 +270,7 @@ pub fn extract_jsx_loop <'a> (callee_expr: &mut Box<Expr>, args: &'a mut Vec<Exp
194
270
  if return_value.is_jsx_element() {
195
271
  let el = return_value.as_mut_jsx_element().unwrap();
196
272
  el.opening.attrs.push(create_jsx_bool_attr(COMPILE_FOR));
197
- el.opening.attrs.push(create_jsx_lit_attr(COMPILE_FOR_KEY, Lit::Str(Str { span, value: "sid".into(), raw: None})));
273
+ el.opening.attrs.push(create_jsx_lit_attr(COMPILE_FOR_KEY, Lit::Str(quote_str!("sid"))));
198
274
  return Some(el)
199
275
  }
200
276
  None
@@ -226,6 +302,41 @@ pub fn extract_jsx_loop <'a> (callee_expr: &mut Box<Expr>, args: &'a mut Vec<Exp
226
302
  None
227
303
  }
228
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
+
229
340
  #[test]
230
341
  fn test_jsx_text () {
231
342
  assert_eq!(" span ", jsx_text_to_string(&" span ".into()));
@@ -233,4 +344,4 @@ fn test_jsx_text () {
233
344
  assert_eq!("a b", jsx_text_to_string(&" \n \n a b \n ".into()));
234
345
  assert_eq!("", jsx_text_to_string(&"\n\n\n\n\n\n \n\n ".into()));
235
346
  assert_eq!("", jsx_text_to_string(&"".into()));
236
- }
347
+ }
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,44 @@
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
+ }
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,183 @@
1
+ const TARO_TEMPLATES_f0t0 = `import { createNode } from '../render'
2
+ import { FlexManager } from '../utils/FlexManager'
3
+ import { TOUCH_EVENT_MAP } from '../utils/constant/event'
4
+ import { getNodeThresholds, getNormalAttributes, getFontAttributes } from '../utils/helper'
5
+ import { TaroIgnoreElement, eventHandler, getComponentEventCallback, AREA_CHANGE_EVENT_NAME, VISIBLE_CHANGE_EVENT_NAME } from '../../runtime'
6
+ import { DynamicCenter } from '../utils/DynamicCenter'
7
+
8
+ import type { TaroViewElement } from '../element'
9
+ import type { TaroElement, TaroAny, TaroStyleType, TaroTextStyleType } from '../../runtime'
10
+
11
+ @Extend(Flex)
12
+ function attrs (style: TaroStyleType) {
13
+ .id(style.id)
14
+ .key(style.id)
15
+ .padding(style.padding)
16
+ .margin(style.margin)
17
+ .width(style.width)
18
+ .height(style.height)
19
+ .constraintSize(style.constraintSize)
20
+ .flexGrow(style.flexGrow)
21
+ .flexShrink(style.flexShrink)
22
+ .flexBasis(style.flexBasis)
23
+ .alignSelf(style.alignSelf)
24
+ .backgroundColor(style.backgroundColor)
25
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
26
+ .backgroundImageSize(style.backgroundImageSize)
27
+ .backgroundImagePosition(style.backgroundImagePosition)
28
+ .rotate(style.rotate)
29
+ .scale(style.scale)
30
+ .translate(style.translate)
31
+ .transform(style.transform)
32
+ .borderStyle(style.borderStyle)
33
+ .borderWidth(style.borderWidth)
34
+ .borderColor(style.borderColor)
35
+ .borderRadius(style.borderRadius)
36
+ .linearGradient(style.linearGradient)
37
+ .zIndex(style.zIndex)
38
+ .opacity(style.opacity)
39
+ .clip(style.clip)
40
+ }
41
+ @Extend(Image)
42
+ function attrsImage (style: TaroStyleType) {
43
+ .id(style.id)
44
+ .key(style.id)
45
+ .padding(style.padding)
46
+ .margin(style.margin)
47
+ .width(style.width)
48
+ .height(style.height)
49
+ .constraintSize(style.constraintSize)
50
+ .flexGrow(style.flexGrow)
51
+ .flexShrink(style.flexShrink)
52
+ .flexBasis(style.flexBasis)
53
+ .alignSelf(style.alignSelf)
54
+ .backgroundColor(style.backgroundColor)
55
+ .backgroundImage(style.backgroundImage, style.backgroundRepeat)
56
+ .backgroundImageSize(style.backgroundImageSize)
57
+ .backgroundImagePosition(style.backgroundImagePosition)
58
+ .rotate(style.rotate)
59
+ .scale(style.scale)
60
+ .translate(style.translate)
61
+ .transform(style.transform)
62
+ .borderStyle(style.borderStyle)
63
+ .borderWidth(style.borderWidth)
64
+ .borderColor(style.borderColor)
65
+ .borderRadius(style.borderRadius)
66
+ .linearGradient(style.linearGradient)
67
+ .zIndex(style.zIndex)
68
+ .opacity(style.opacity)
69
+ .clip(style.clip)
70
+ }
71
+
72
+ function getImageMode (mode: string): ImageFit {
73
+ switch (mode) {
74
+ case 'aspectFit': return ImageFit.Contain
75
+ case 'aspectFill': return ImageFit.Cover
76
+ case 'scaleToFill': return ImageFit.Fill
77
+ case 'widthFix': return ImageFit.Auto
78
+ case 'heightFix': return ImageFit.Auto
79
+ default: return ImageFit.Contain
80
+ }
81
+ }
82
+ @Component
83
+ export default struct TARO_TEMPLATES_f0t0 {
84
+ nodeInfoMap: TaroAny = {}
85
+ dynamicCenter: DynamicCenter = new DynamicCenter()
86
+ @ObjectLink node: TaroViewElement
87
+
88
+ aboutToAppear () {
89
+ this.dynamicCenter.bindComponentToNodeWithDFS(this.node, this)
90
+ }
91
+
92
+ @State node0: TaroElement = new TaroIgnoreElement()
93
+ @State node1: TaroElement = new TaroIgnoreElement()
94
+ @State node2: TaroElement = new TaroIgnoreElement()
95
+
96
+ build() {
97
+ Flex(FlexManager.flexOptions(this.node0 as TaroElement)) {
98
+ Flex(FlexManager.flexOptions(this.node0.childNodes[0] as TaroElement)) {}
99
+ .attrs(getNormalAttributes(this.node0.childNodes[0] as TaroElement))
100
+ .onVisibleAreaChange(getNodeThresholds(this.node0.childNodes[0] as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node0.childNodes[0] as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
101
+ .onAreaChange(getComponentEventCallback(this.node0.childNodes[0] as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
102
+ const eventResult: TaroAny = res.eventResult
103
+ this.nodeInfoMap[this.node0.childNodes[0]._nid].areaInfo = eventResult[1]
104
+ }))
105
+ .onClick(e => eventHandler(e, 'click', this.node0.childNodes[0] as TaroElement))
106
+ Flex(FlexManager.flexOptions(this.node0.childNodes[1] as TaroElement)) {}
107
+ .attrs(getNormalAttributes(this.node0.childNodes[1] as TaroElement))
108
+ .onVisibleAreaChange(getNodeThresholds(this.node0.childNodes[1] as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node0.childNodes[1] as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
109
+ .onAreaChange(getComponentEventCallback(this.node0.childNodes[1] as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
110
+ const eventResult: TaroAny = res.eventResult
111
+ this.nodeInfoMap[this.node0.childNodes[1]._nid].areaInfo = eventResult[1]
112
+ }))
113
+ .onClick(e => eventHandler(e, 'click', this.node0.childNodes[1] as TaroElement))
114
+ Flex(FlexManager.flexOptions(this.node1 as TaroElement)) {}
115
+ .attrs(getNormalAttributes(this.node1 as TaroElement))
116
+ .onVisibleAreaChange(getNodeThresholds(this.node1 as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node1 as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
117
+ .onAreaChange(getComponentEventCallback(this.node1 as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
118
+ const eventResult: TaroAny = res.eventResult
119
+ this.nodeInfoMap[this.node1._nid].areaInfo = eventResult[1]
120
+ }))
121
+ .onClick(e => eventHandler(e, 'click', this.node1 as TaroElement))
122
+ Flex(FlexManager.flexOptions(this.node2 as TaroElement)) {}
123
+ .attrs(getNormalAttributes(this.node2 as TaroElement))
124
+ .onVisibleAreaChange(getNodeThresholds(this.node2 as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node2 as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
125
+ .onAreaChange(getComponentEventCallback(this.node2 as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
126
+ const eventResult: TaroAny = res.eventResult
127
+ this.nodeInfoMap[this.node2._nid].areaInfo = eventResult[1]
128
+ }))
129
+ Image((this.node0.childNodes[4] as TaroElement).getAttribute('src'))
130
+ .objectFit(getImageMode((this.node0.childNodes[4] as TaroElement).getAttribute('mode')))
131
+ .attrsImage(getNormalAttributes(this.node0.childNodes[4] as TaroElement))
132
+ .onVisibleAreaChange(getNodeThresholds(this.node0.childNodes[4] as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node0.childNodes[4] as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
133
+ .onAreaChange(getComponentEventCallback(this.node0.childNodes[4] as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
134
+ const eventResult: TaroAny = res.eventResult
135
+ this.nodeInfoMap[this.node0.childNodes[4]._nid].areaInfo = eventResult[1]
136
+ }))
137
+ .onComplete(e => eventHandler(e, 'complete', this.node0.childNodes[4] as TaroElement))
138
+ Flex(FlexManager.flexOptions(this.node0.childNodes[5] as TaroElement)) {}
139
+ .attrs(getNormalAttributes(this.node0.childNodes[5] as TaroElement))
140
+ .onVisibleAreaChange(getNodeThresholds(this.node0.childNodes[5] as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node0.childNodes[5] as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
141
+ .onAreaChange(getComponentEventCallback(this.node0.childNodes[5] as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
142
+ const eventResult: TaroAny = res.eventResult
143
+ this.nodeInfoMap[this.node0.childNodes[5]._nid].areaInfo = eventResult[1]
144
+ }))
145
+ .onClick(e => eventHandler(e, 'click', this.node0.childNodes[5] as TaroElement))
146
+ .onTouch(e => eventHandler(e, TOUCH_EVENT_MAP.get(e.type), this.node0.childNodes[5] as TaroElement))
147
+ }
148
+ .attrs(getNormalAttributes(this.node0 as TaroElement))
149
+ .onVisibleAreaChange(getNodeThresholds(this.node0 as TaroElement) || [0.0, 1.0], getComponentEventCallback(this.node0 as TaroElement, VISIBLE_CHANGE_EVENT_NAME))
150
+ .onAreaChange(getComponentEventCallback(this.node0 as TaroElement, AREA_CHANGE_EVENT_NAME, res => {
151
+ const eventResult: TaroAny = res.eventResult
152
+ this.nodeInfoMap[this.node0._nid].areaInfo = eventResult[1]
153
+ }))
154
+ }
155
+ }
156
+ `;
157
+ function Index() {
158
+ return <View compileMode="f0t0" _dynamicID="node0">
159
+
160
+ <View onClick={()=>{
161
+ console.log("click done");
162
+ }}></View>
163
+
164
+ <View onClick={function clickFn() {
165
+ console.log("click done");
166
+ }}></View>
167
+
168
+ <View onClick={handleViewClick} _dynamicID="node1"></View>
169
+
170
+ <View onAnimationStart={()=>{}} id={myId} _dynamicID="node2"></View>
171
+
172
+ <Image onLoad={()=>{
173
+ console.log("load done");
174
+ }} id="myImg"/>
175
+
176
+ <View onClick={()=>{
177
+ console.log("click done");
178
+ }} onTouchStart={()=>{
179
+ console.log("touch start done");
180
+ }}/>
181
+
182
+ </View>;
183
+ }