@tarojs/helper 3.7.0-alpha.25 → 3.7.0-alpha.27

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 (80) hide show
  1. package/dist/constants.d.ts +3 -3
  2. package/dist/constants.js +3 -3
  3. package/dist/constants.js.map +1 -1
  4. package/dist/esbuild/index.js +1 -0
  5. package/dist/esbuild/index.js.map +1 -1
  6. package/dist/swcRegister.d.ts +0 -6
  7. package/dist/swcRegister.js +0 -15
  8. package/dist/swcRegister.js.map +1 -1
  9. package/dist/utils.d.ts +8 -2
  10. package/dist/utils.js +12 -3
  11. package/dist/utils.js.map +1 -1
  12. package/package.json +5 -5
  13. package/swc/plugin-compile-mode/.cargo/config +5 -0
  14. package/swc/plugin-compile-mode/.editorconfig +6 -0
  15. package/swc/plugin-compile-mode/.vscode/settings.json +3 -0
  16. package/swc/plugin-compile-mode/Cargo.lock +2021 -0
  17. package/swc/plugin-compile-mode/Cargo.toml +19 -0
  18. package/swc/plugin-compile-mode/package.json +15 -0
  19. package/swc/plugin-compile-mode/src/lib.rs +71 -0
  20. package/swc/plugin-compile-mode/src/tests/attributes.rs +54 -0
  21. package/swc/plugin-compile-mode/src/tests/children.rs +86 -0
  22. package/swc/plugin-compile-mode/src/tests/condition.rs +50 -0
  23. package/swc/plugin-compile-mode/src/tests/entry.rs +20 -0
  24. package/swc/plugin-compile-mode/src/tests/harmony/attributes.rs +45 -0
  25. package/swc/plugin-compile-mode/src/tests/harmony/children.rs +74 -0
  26. package/swc/plugin-compile-mode/src/tests/harmony/condition.rs +79 -0
  27. package/swc/plugin-compile-mode/src/tests/harmony/entry.rs +67 -0
  28. package/swc/plugin-compile-mode/src/tests/harmony/looping.rs +62 -0
  29. package/swc/plugin-compile-mode/src/tests/harmony/mod.rs +45 -0
  30. package/swc/plugin-compile-mode/src/tests/looping.rs +84 -0
  31. package/swc/plugin-compile-mode/src/tests/mod.rs +100 -0
  32. package/swc/plugin-compile-mode/src/tests/shake.rs +27 -0
  33. package/swc/plugin-compile-mode/src/transform.rs +480 -0
  34. package/swc/plugin-compile-mode/src/transform_harmony.rs +526 -0
  35. package/swc/plugin-compile-mode/src/utils/constants.rs +149 -0
  36. package/swc/plugin-compile-mode/src/utils/harmony/components.rs +61 -0
  37. package/swc/plugin-compile-mode/src/utils/harmony/mod.rs +1 -0
  38. package/swc/plugin-compile-mode/src/utils/mod.rs +346 -0
  39. package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
  40. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_handle_events.js +8 -0
  41. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_keep_static_attrs_only_in_templates.js +8 -0
  42. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_turn_dynamic_attrs.js +11 -0
  43. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_native_component.js +7 -0
  44. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_react_component.js +7 -0
  45. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_fragment.js +44 -0
  46. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_render_fn.js +8 -0
  47. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_and_expr.js +14 -0
  48. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_conditional_expr.js +15 -0
  49. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/entry.rs/should_support_multi_compile_mode.js +10 -0
  50. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_handle_events.js +181 -0
  51. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_turn_dynamic_attrs.js +184 -0
  52. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_render_react_component.js +75 -0
  53. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_fragment.js +339 -0
  54. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_render_fn.js +184 -0
  55. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_and_expr.js +209 -0
  56. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_complex_condition.js +242 -0
  57. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_and_unkonw_component.js +137 -0
  58. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_expr.js +342 -0
  59. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_compile_child_node.js +139 -0
  60. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_component_not_in_config.js +90 -0
  61. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_multi_compile_mode.js +206 -0
  62. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_single_compile_mode.js +65 -0
  63. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +75 -0
  64. 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 +88 -0
  65. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_function_expr.js +85 -0
  66. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +8 -0
  67. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_expr.js +6 -0
  68. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_function_expr.js +20 -0
  69. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_support_nested_loop.js +15 -0
  70. package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/shake.rs/should_static_jsx_being_shaked.js +20 -0
  71. package/swc/plugin-define-config/.cargo/config +5 -0
  72. package/swc/plugin-define-config/Cargo.lock +582 -506
  73. package/swc/plugin-define-config/Cargo.toml +2 -11
  74. package/swc/plugin-define-config/src/lib.rs +81 -128
  75. package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
  76. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_app.js +2 -0
  77. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_page.js +2 -0
  78. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_exports.js +11 -0
  79. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_app.js +3 -0
  80. package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_page.js +3 -0
@@ -0,0 +1,84 @@
1
+ use swc_core::ecma::transforms::testing::test;
2
+ use super::{tr, get_syntax_config};
3
+
4
+ test!(
5
+ get_syntax_config(),
6
+ |_| tr(),
7
+ should_loop_with_function_expr,
8
+ r#"
9
+ function Index () {
10
+ return (
11
+ <View compileMode>
12
+ {list.map(function(item, index) {
13
+ return (
14
+ <View hoverClass={myClass}>
15
+ <Text>index:</Text>
16
+ <Text>{index}</Text>
17
+ <Text>item:</Text>
18
+ <Text>{item}</Text>
19
+ </View>
20
+ )
21
+ })}
22
+ </View>
23
+ )
24
+ }
25
+ "#
26
+ );
27
+
28
+ test!(
29
+ get_syntax_config(),
30
+ |_| tr(),
31
+ should_loop_with_arrow_function_with_blockstmt,
32
+ r#"
33
+ function Index () {
34
+ return (
35
+ <View compileMode>
36
+ {list.map(item => {
37
+ return <View>{item}</View>
38
+ })}
39
+ </View>
40
+ )
41
+ }
42
+ "#
43
+ );
44
+
45
+ test!(
46
+ get_syntax_config(),
47
+ |_| tr(),
48
+ should_loop_with_arrow_function_with_expr,
49
+ r#"
50
+ function Index () {
51
+ return (
52
+ <View compileMode>
53
+ {list.map(item => <View>{item}</View>)}
54
+ </View>
55
+ )
56
+ }
57
+ "#
58
+ );
59
+
60
+ test!(
61
+ get_syntax_config(),
62
+ |_| tr(),
63
+ should_support_nested_loop,
64
+ r#"
65
+ function Index () {
66
+ return (
67
+ <View compileMode>
68
+ {list.map(function(item, index) {
69
+ return (
70
+ <View hoverClass={myClass} key={index}>
71
+ <View>title: {item}</View>
72
+ <View>
73
+ {sublist.map(function(c) {
74
+ return <Text selectable={isSelectable}>content: {c}</Text>
75
+ })}
76
+ </View>
77
+ </View>
78
+ )
79
+ })}
80
+ </View>
81
+ )
82
+ }
83
+ "#
84
+ );
@@ -0,0 +1,100 @@
1
+ use swc_core::ecma::{
2
+ parser,
3
+ visit::{as_folder, Fold, VisitMut},
4
+ };
5
+ use crate::{
6
+ PluginConfig,
7
+ transform::*,
8
+ };
9
+
10
+ mod entry;
11
+ mod attributes;
12
+ mod shake;
13
+ mod condition;
14
+ mod looping;
15
+ mod children;
16
+ mod harmony;
17
+
18
+ pub fn tr () -> impl Fold + VisitMut {
19
+ let config = serde_json::from_str::<PluginConfig>(
20
+ r#"
21
+ {
22
+ "tmpl_prefix": "f0",
23
+ "components": {
24
+ "block": {},
25
+ "image": {
26
+ "src": "i.p3",
27
+ "mode": "xs.b(i.p1,'scaleToFill')",
28
+ "lazy-load": "xs.b(i.p0,!1)",
29
+ "binderror": "eh",
30
+ "bindload": "eh",
31
+ "bindtouchstart": "eh",
32
+ "bindtouchmove": "eh",
33
+ "bindtouchend": "eh",
34
+ "bindtouchcancel": "eh",
35
+ "bindlongpress": "eh",
36
+ "webp": "xs.b(i.p4,false)",
37
+ "show-menu-by-longpress": "xs.b(i.p2,false)",
38
+ "style": "i.st",
39
+ "class": "i.cl",
40
+ "bindtap": "eh"
41
+ },
42
+ "view": {
43
+ "hover-class": "xs.b(i.p1,'none')",
44
+ "hover-stop-propagation": "xs.b(i.p4,!1)",
45
+ "hover-start-time": "xs.b(i.p2,50)",
46
+ "hover-stay-time": "xs.b(i.p3,400)",
47
+ "bindtouchstart": "eh",
48
+ "bindtouchmove": "eh",
49
+ "bindtouchend": "eh",
50
+ "bindtouchcancel": "eh",
51
+ "bindlongpress": "eh",
52
+ "animation": "i.p0",
53
+ "bindanimationstart": "eh",
54
+ "bindanimationiteration": "eh",
55
+ "bindanimationend": "eh",
56
+ "bindtransitionend": "eh",
57
+ "style": "i.st",
58
+ "class": "i.cl",
59
+ "bindtap": "eh"
60
+ },
61
+ "text": {
62
+ "selectable": "xs.b(i.p1,!1)",
63
+ "space": "i.p2",
64
+ "decode": "xs.b(i.p0,!1)",
65
+ "user-select": "xs.b(i.p3,false)",
66
+ "style": "i.st",
67
+ "class": "i.cl",
68
+ "bindtap": "eh"
69
+ },
70
+ "movable-area": {
71
+ "scale-area": "xs.b(i.p0,!1)",
72
+ "style": "i.st",
73
+ "class": "i.cl",
74
+ "bindtap": "eh"
75
+ }
76
+ },
77
+ "adapter": {
78
+ "if": "wx:if",
79
+ "else": "wx:else",
80
+ "elseif": "wx:elif",
81
+ "for": "wx:for",
82
+ "forItem": "wx:for-item",
83
+ "forIndex": "wx:for-index",
84
+ "key": "wx:key",
85
+ "xs": "wxs",
86
+ "type": "weapp"
87
+ }
88
+ }"#
89
+ )
90
+ .unwrap();
91
+ let visitor = TransformVisitor::new(config);
92
+ as_folder(visitor)
93
+ }
94
+
95
+ pub fn get_syntax_config () -> parser::Syntax {
96
+ parser::Syntax::Es(parser::EsConfig {
97
+ jsx: true,
98
+ ..Default::default()
99
+ })
100
+ }
@@ -0,0 +1,27 @@
1
+ use swc_core::ecma::transforms::testing::test;
2
+ use super::{tr, get_syntax_config};
3
+
4
+ test!(
5
+ get_syntax_config(),
6
+ |_| tr(),
7
+ should_static_jsx_being_shaked,
8
+ r#"
9
+ function Index () {
10
+ return (
11
+ <View compileMode>
12
+ <Text>Hello World!</Text>
13
+ <Text>Hello{T1}World{T2}!</Text>
14
+ <View>
15
+ <Text></Text>
16
+ </View>
17
+ <View style="color: red" hoverStopPropagation>
18
+ <Text>Hello World!</Text>
19
+ </View>
20
+ <View style={myStyle}>
21
+ <Text>Hello World!</Text>
22
+ </View>
23
+ </View>
24
+ )
25
+ }
26
+ "#
27
+ );