@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.
- package/README.md +22 -0
- package/dist/constants.d.ts +5 -3
- package/dist/constants.js +24 -22
- package/dist/constants.js.map +1 -1
- package/dist/dotenv.js.map +1 -1
- package/dist/esbuild/index.js +6 -4
- package/dist/esbuild/index.js.map +1 -1
- package/dist/npm.d.ts +2 -2
- package/dist/npm.js +6 -6
- package/dist/npm.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 +33 -1
- package/dist/utils.js +87 -34
- package/dist/utils.js.map +1 -1
- package/package.json +19 -15
- package/swc/plugin-compile-mode/.cargo/config +5 -0
- package/swc/plugin-compile-mode/.editorconfig +6 -0
- package/swc/plugin-compile-mode/.vscode/settings.json +3 -0
- package/swc/plugin-compile-mode/Cargo.lock +195 -260
- package/swc/plugin-compile-mode/Cargo.toml +6 -4
- package/swc/plugin-compile-mode/package.json +15 -0
- package/swc/plugin-compile-mode/src/lib.rs +21 -2
- package/swc/plugin-compile-mode/src/tests/attributes.rs +1 -32
- package/swc/plugin-compile-mode/src/tests/children.rs +86 -0
- package/swc/plugin-compile-mode/src/tests/condition.rs +8 -29
- package/swc/plugin-compile-mode/src/tests/entry.rs +1 -13
- package/swc/plugin-compile-mode/src/tests/harmony/attributes.rs +45 -0
- package/swc/plugin-compile-mode/src/tests/harmony/children.rs +74 -0
- package/swc/plugin-compile-mode/src/tests/harmony/condition.rs +79 -0
- package/swc/plugin-compile-mode/src/tests/harmony/entry.rs +67 -0
- package/swc/plugin-compile-mode/src/tests/harmony/looping.rs +62 -0
- package/swc/plugin-compile-mode/src/tests/harmony/mod.rs +45 -0
- package/swc/plugin-compile-mode/src/tests/looping.rs +1 -51
- package/swc/plugin-compile-mode/src/tests/mod.rs +11 -9
- package/swc/plugin-compile-mode/src/tests/shake.rs +1 -15
- package/swc/plugin-compile-mode/src/transform.rs +142 -134
- package/swc/plugin-compile-mode/src/transform_harmony.rs +526 -0
- package/swc/plugin-compile-mode/src/utils/constants.rs +141 -0
- package/swc/plugin-compile-mode/src/utils/harmony/components.rs +61 -0
- package/swc/plugin-compile-mode/src/utils/harmony/mod.rs +1 -0
- package/swc/plugin-compile-mode/src/utils/mod.rs +126 -15
- 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 +8 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_keep_static_attrs_only_in_templates.js +8 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_turn_dynamic_attrs.js +11 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_native_component.js +7 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_react_component.js +7 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_fragment.js +44 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_render_fn.js +8 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_and_expr.js +14 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_conditional_expr.js +15 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/entry.rs/should_support_multi_compile_mode.js +10 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_handle_events.js +183 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_turn_dynamic_attrs.js +186 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_render_react_component.js +76 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_fragment.js +341 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_render_fn.js +186 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_and_expr.js +211 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_complex_condition.js +244 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_and_unkonw_component.js +139 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_expr.js +344 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_compile_child_node.js +141 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_component_not_in_config.js +91 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_multi_compile_mode.js +209 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_single_compile_mode.js +66 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +76 -0
- 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
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_function_expr.js +86 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +8 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_expr.js +6 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_function_expr.js +20 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_support_nested_loop.js +15 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/shake.rs/should_static_jsx_being_shaked.js +20 -0
- package/swc/plugin-define-config/.cargo/config +5 -0
- package/swc/plugin-define-config/Cargo.lock +582 -506
- package/swc/plugin-define-config/Cargo.toml +2 -11
- package/swc/plugin-define-config/src/lib.rs +81 -128
- 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 +2 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_page.js +2 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_exports.js +11 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_app.js +3 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_page.js +3 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
2
|
+
name = "swc_plugin_compile_mode"
|
|
3
3
|
version = "0.1.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
|
|
@@ -7,13 +7,15 @@ edition = "2021"
|
|
|
7
7
|
crate-type = ["cdylib"]
|
|
8
8
|
|
|
9
9
|
[profile.release]
|
|
10
|
-
lto =
|
|
10
|
+
lto = false # https://github.com/swc-project/swc/issues/7479
|
|
11
11
|
|
|
12
12
|
[dependencies]
|
|
13
13
|
serde = { version = "1.0", features = ["derive"] }
|
|
14
14
|
serde_json = "1.0.105"
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
swc_core = { version = "0.86.*", features = ["ecma_plugin_transform", "ecma_utils"] }
|
|
16
|
+
|
|
17
|
+
[dev-dependencies]
|
|
18
|
+
swc_core = { version = "0.86.*", features = ["ecma_plugin_transform", "ecma_utils", "ecma_parser", "ecma_codegen"] }
|
|
17
19
|
|
|
18
20
|
# .cargo/config defines few alias to build plugin.
|
|
19
21
|
# cargo build-wasi generates wasm-wasi32 binary
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "swc-plugin-taro-compile-mode",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "",
|
|
6
|
+
"license": "ISC",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"swc-plugin"
|
|
9
|
+
],
|
|
10
|
+
"main": "target/wasm32-wasi/release/swc_plugin_compile_mode.wasm",
|
|
11
|
+
"files": [
|
|
12
|
+
"target"
|
|
13
|
+
],
|
|
14
|
+
"preferUnplugged": true
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
use swc_core::{
|
|
2
2
|
ecma::{
|
|
3
3
|
ast::Program,
|
|
4
|
-
visit::{as_folder, FoldWith},
|
|
4
|
+
visit::{as_folder, FoldWith, VisitMut},
|
|
5
5
|
},
|
|
6
6
|
plugin::{
|
|
7
7
|
plugin_transform,
|
|
@@ -14,14 +14,26 @@ use core::fmt::Debug;
|
|
|
14
14
|
|
|
15
15
|
mod utils;
|
|
16
16
|
mod transform;
|
|
17
|
+
mod transform_harmony;
|
|
17
18
|
#[cfg(test)]
|
|
18
19
|
mod tests;
|
|
19
20
|
|
|
21
|
+
|
|
20
22
|
#[derive(Serialize, Deserialize, Debug)]
|
|
21
23
|
pub struct PluginConfig {
|
|
22
24
|
pub tmpl_prefix: String,
|
|
25
|
+
#[serde(default)]
|
|
26
|
+
pub is_harmony: bool,
|
|
27
|
+
#[serde(default)]
|
|
23
28
|
pub components: HashMap<String, HashMap<String, String>>,
|
|
29
|
+
#[serde(default)]
|
|
24
30
|
pub adapter: HashMap<String, String>,
|
|
31
|
+
#[serde(default)]
|
|
32
|
+
pub support_events: Vec<String>,
|
|
33
|
+
#[serde(default)]
|
|
34
|
+
pub support_components: Vec<String>,
|
|
35
|
+
#[serde(default)]
|
|
36
|
+
pub event_adapter: HashMap<String, String>,
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
/// An example plugin function with macro support.
|
|
@@ -47,6 +59,13 @@ pub fn process_transform(program: Program, metadata: TransformPluginProgramMetad
|
|
|
47
59
|
.unwrap()
|
|
48
60
|
)
|
|
49
61
|
.unwrap();
|
|
50
|
-
|
|
62
|
+
|
|
63
|
+
// 如果 config 中的 is_harmony 字段为 true 则走 harmony_transform, 否则则走 transform
|
|
64
|
+
let visitor: Box<dyn VisitMut> = if config.is_harmony {
|
|
65
|
+
Box::new(transform_harmony::TransformVisitor::new(config))
|
|
66
|
+
} else {
|
|
67
|
+
Box::new(transform::TransformVisitor::new(config))
|
|
68
|
+
};
|
|
69
|
+
|
|
51
70
|
program.fold_with(&mut as_folder(visitor))
|
|
52
71
|
}
|
|
@@ -9,18 +9,10 @@ test!(
|
|
|
9
9
|
function Index () {
|
|
10
10
|
return (
|
|
11
11
|
<View compileMode>
|
|
12
|
-
<Image className="my_img" src="https://taro.com/x.png" lazyLoad />
|
|
12
|
+
<Image className="my_img" src="https://taro.com/x.png" lazyLoad key="image" ref={myRefCb} />
|
|
13
13
|
</View>
|
|
14
14
|
)
|
|
15
15
|
}
|
|
16
|
-
"#,
|
|
17
|
-
r#"
|
|
18
|
-
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>';
|
|
19
|
-
function Index () {
|
|
20
|
-
return <View compileMode="f0t0">
|
|
21
|
-
|
|
22
|
-
</View>
|
|
23
|
-
}
|
|
24
16
|
"#
|
|
25
17
|
);
|
|
26
18
|
|
|
@@ -41,19 +33,6 @@ test!(
|
|
|
41
33
|
</View>
|
|
42
34
|
)
|
|
43
35
|
}
|
|
44
|
-
"#,
|
|
45
|
-
r#"
|
|
46
|
-
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>';
|
|
47
|
-
function Index () {
|
|
48
|
-
return <View compileMode="f0t0">
|
|
49
|
-
<View class={myClass}>
|
|
50
|
-
<View style={myStyle} customProp={myCustomProp}></View>
|
|
51
|
-
<View hoverStayTime={myTime}>
|
|
52
|
-
<View hoverClass={myHoverClass}></View>
|
|
53
|
-
</View>
|
|
54
|
-
</View>
|
|
55
|
-
</View>
|
|
56
|
-
}
|
|
57
36
|
"#
|
|
58
37
|
);
|
|
59
38
|
|
|
@@ -71,15 +50,5 @@ test!(
|
|
|
71
50
|
</View>
|
|
72
51
|
)
|
|
73
52
|
}
|
|
74
|
-
"#,
|
|
75
|
-
r#"
|
|
76
|
-
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>';
|
|
77
|
-
function Index () {
|
|
78
|
-
return <View compileMode="f0t0">
|
|
79
|
-
<View onClick={handleViewClick}></View>
|
|
80
|
-
<View onAnimationStart={() => {}} id={myId}></View>
|
|
81
|
-
<Image onLoad={() => {}} />
|
|
82
|
-
</View>
|
|
83
|
-
}
|
|
84
53
|
"#
|
|
85
54
|
);
|
|
@@ -0,0 +1,86 @@
|
|
|
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_support_render_fn,
|
|
8
|
+
r#"
|
|
9
|
+
function Index () {
|
|
10
|
+
return (
|
|
11
|
+
<View compileMode>
|
|
12
|
+
<View>{renderHeader()}</View>
|
|
13
|
+
<View>{this.methods.renderFooter()}</View>
|
|
14
|
+
<View>{normalFunc()}</View>
|
|
15
|
+
</View>
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
"#
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
test!(
|
|
22
|
+
get_syntax_config(),
|
|
23
|
+
|_| tr(),
|
|
24
|
+
should_support_fragment,
|
|
25
|
+
r#"
|
|
26
|
+
function Index () {
|
|
27
|
+
return (
|
|
28
|
+
<View compileMode>
|
|
29
|
+
{content0}
|
|
30
|
+
<>
|
|
31
|
+
<View>{content1}</View>
|
|
32
|
+
<View>hello</View>
|
|
33
|
+
<View>
|
|
34
|
+
<>
|
|
35
|
+
<View>{content2}</View>
|
|
36
|
+
<View>hello!</View>
|
|
37
|
+
</>
|
|
38
|
+
</View>
|
|
39
|
+
<View>{content3}</View>
|
|
40
|
+
</>
|
|
41
|
+
<View>{content4}</View>
|
|
42
|
+
<>
|
|
43
|
+
<View>{content5}</View>
|
|
44
|
+
</>
|
|
45
|
+
<>
|
|
46
|
+
<View>hello!!</View>
|
|
47
|
+
</>
|
|
48
|
+
<View>hello!!!</View>
|
|
49
|
+
<View>{content6}</View>
|
|
50
|
+
</View>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
"#
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
test!(
|
|
57
|
+
get_syntax_config(),
|
|
58
|
+
|_| tr(),
|
|
59
|
+
should_render_react_component,
|
|
60
|
+
r#"
|
|
61
|
+
function Index () {
|
|
62
|
+
return (
|
|
63
|
+
<View compileMode>
|
|
64
|
+
<Foo />
|
|
65
|
+
<Foo title={myTitle} loading onClick={() => {}} />
|
|
66
|
+
</View>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
"#
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
test!(
|
|
73
|
+
get_syntax_config(),
|
|
74
|
+
|_| tr(),
|
|
75
|
+
should_render_native_component,
|
|
76
|
+
r#"
|
|
77
|
+
function Index () {
|
|
78
|
+
return (
|
|
79
|
+
<View compileMode>
|
|
80
|
+
<comp />
|
|
81
|
+
<comp type="primary" loading loading-text={loadingText} onMyevent={() => {}} />
|
|
82
|
+
</View>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
"#
|
|
86
|
+
);
|
|
@@ -15,22 +15,14 @@ test!(
|
|
|
15
15
|
)}
|
|
16
16
|
{condition1 && "condition2" && condition3 && <View hoverClass={myClass}>{content}</View>}
|
|
17
17
|
{condition1 && 'Hello'}
|
|
18
|
+
{condition1 && <View onClick={() => condition2 && doSth()} />}
|
|
18
19
|
<View hoverClass={myClass}></View>
|
|
20
|
+
<View>{condition1 && ident}</View>
|
|
21
|
+
<View>{condition1 && obj.property}</View>
|
|
22
|
+
<View>{condition1 && fn()}</View>
|
|
19
23
|
</View>
|
|
20
24
|
)
|
|
21
25
|
}
|
|
22
|
-
"#,
|
|
23
|
-
r#"
|
|
24
|
-
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 hover-class="{{xs.b(i.cn[4].p1,\'none\')}}"></view></view></template>';
|
|
25
|
-
function Index () {
|
|
26
|
-
return <View compileMode="f0t0">
|
|
27
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <View/>}
|
|
28
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <View/>}
|
|
29
|
-
{condition1 && "condition2" && condition3 ? <View hoverClass={myClass} compileIf={condition1 && "condition2" && condition3}>{content}</View> : <View/>}
|
|
30
|
-
{condition1 ? 'Hello' : "compileIgnore"}
|
|
31
|
-
<View hoverClass={myClass}></View>
|
|
32
|
-
</View>
|
|
33
|
-
}
|
|
34
26
|
"#
|
|
35
27
|
);
|
|
36
28
|
test!(
|
|
@@ -47,25 +39,12 @@ test!(
|
|
|
47
39
|
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
|
|
48
40
|
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
|
|
49
41
|
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
|
|
50
|
-
{condition1 ? "someText" : 789
|
|
42
|
+
{condition1 ? "someText" : 789}
|
|
43
|
+
{condition1 ? <View className={condition2 ? '' : ''} /> : <View/>}
|
|
44
|
+
{condition1 ? <View>{condition2 ? <View/> : <View/>}</View> : <View/>}
|
|
51
45
|
<View hoverClass={myClass}></View>
|
|
52
46
|
</View>
|
|
53
47
|
)
|
|
54
48
|
}
|
|
55
|
-
"#,
|
|
56
|
-
r#"
|
|
57
|
-
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 hover-class="{{xs.b(i.cn[7].p1,\'none\')}}"></view></view></template>';
|
|
58
|
-
function Index () {
|
|
59
|
-
return <View compileMode="f0t0">
|
|
60
|
-
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <Text></Text>}
|
|
61
|
-
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <Text>{b}</Text>}</block> : <View>{c}</View>}
|
|
62
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
|
|
63
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
|
|
64
|
-
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <View/>}</block> : <View>{b}</View>}
|
|
65
|
-
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <View/>}</block>}
|
|
66
|
-
{condition1 ? <block compileIf={condition1}>{"someText"}</block> : <block>{789}</block> }
|
|
67
|
-
<View hoverClass={myClass}></View>
|
|
68
|
-
</View>
|
|
69
|
-
}
|
|
70
49
|
"#
|
|
71
|
-
);
|
|
50
|
+
);
|
|
@@ -16,17 +16,5 @@ test!(
|
|
|
16
16
|
</View>
|
|
17
17
|
)
|
|
18
18
|
}
|
|
19
|
-
"#,
|
|
20
|
-
r#"
|
|
21
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><image src="{{i.p3}}"></image></template>';
|
|
22
|
-
const TARO_TEMPLATES_f0t1 = '<template name="tmpl_0_f0t1"><view><text>{{i.cn[0].cn[0].v}}</text></view></template>';
|
|
23
|
-
function Index () {
|
|
24
|
-
return <View>
|
|
25
|
-
<Image src={mySrc} compileMode="f0t0" />
|
|
26
|
-
<View compileMode="f0t1">
|
|
27
|
-
<Text>{myText}</Text>
|
|
28
|
-
</View>
|
|
29
|
-
</View>
|
|
30
|
-
}
|
|
31
19
|
"#
|
|
32
|
-
);
|
|
20
|
+
);
|
|
@@ -0,0 +1,45 @@
|
|
|
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_turn_dynamic_attrs,
|
|
8
|
+
r#"
|
|
9
|
+
function Index () {
|
|
10
|
+
return (
|
|
11
|
+
<View compileMode>
|
|
12
|
+
<View class={myClass}>
|
|
13
|
+
<View style={myStyle} customProp={myCustomProp}></View>
|
|
14
|
+
<View class="center" />
|
|
15
|
+
<View onTouch={myTime}>
|
|
16
|
+
<View hoverClass={myHoverClass}></View>
|
|
17
|
+
</View>
|
|
18
|
+
</View>
|
|
19
|
+
<Image alt="占位符" src="https://www.jd.com/test.jpg" />
|
|
20
|
+
<Image alt="占位符" src={src} />
|
|
21
|
+
</View>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
"#
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
test!(
|
|
28
|
+
get_syntax_config(),
|
|
29
|
+
|_| tr(),
|
|
30
|
+
should_handle_events,
|
|
31
|
+
r#"
|
|
32
|
+
function Index () {
|
|
33
|
+
return (
|
|
34
|
+
<View compileMode>
|
|
35
|
+
<View onClick={() => { console.log("click done") }}></View>
|
|
36
|
+
<View onClick={function clickFn () { console.log("click done") }}></View>
|
|
37
|
+
<View onClick={handleViewClick}></View>
|
|
38
|
+
<View onAnimationStart={() => {}} id={myId}></View>
|
|
39
|
+
<Image onLoad={() => { console.log("load done") }} id="myImg" />
|
|
40
|
+
<View onClick={() => { console.log("click done") }} onTouchStart={() => { console.log("touch start done") }} />
|
|
41
|
+
</View>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
"#
|
|
45
|
+
);
|
|
@@ -0,0 +1,74 @@
|
|
|
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_support_render_fn,
|
|
8
|
+
r#"
|
|
9
|
+
function Index () {
|
|
10
|
+
return (
|
|
11
|
+
<View compileMode>
|
|
12
|
+
<View>{renderHeader()}</View>
|
|
13
|
+
<View>
|
|
14
|
+
{renderHeader()}
|
|
15
|
+
{normalFunc()}
|
|
16
|
+
</View>
|
|
17
|
+
<View>{this.methods.renderFooter()}</View>
|
|
18
|
+
<View>{normalFunc()}</View>
|
|
19
|
+
</View>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
"#
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
test!(
|
|
26
|
+
get_syntax_config(),
|
|
27
|
+
|_| tr(),
|
|
28
|
+
should_support_fragment,
|
|
29
|
+
r#"
|
|
30
|
+
function Index () {
|
|
31
|
+
return (
|
|
32
|
+
<View compileMode>
|
|
33
|
+
{content0}
|
|
34
|
+
<>
|
|
35
|
+
<View>{content1}</View>
|
|
36
|
+
<View>hello</View>
|
|
37
|
+
<View>
|
|
38
|
+
<>
|
|
39
|
+
<View>{content2}</View>
|
|
40
|
+
<View>hello!</View>
|
|
41
|
+
</>
|
|
42
|
+
</View>
|
|
43
|
+
<View>{content3}</View>
|
|
44
|
+
</>
|
|
45
|
+
<View>{content4}</View>
|
|
46
|
+
<>
|
|
47
|
+
<View>{content5}</View>
|
|
48
|
+
</>
|
|
49
|
+
<>
|
|
50
|
+
<View>hello!!</View>
|
|
51
|
+
</>
|
|
52
|
+
<View>hello!!!</View>
|
|
53
|
+
<View>{content6}</View>
|
|
54
|
+
</View>
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
"#
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
test!(
|
|
61
|
+
get_syntax_config(),
|
|
62
|
+
|_| tr(),
|
|
63
|
+
should_render_react_component,
|
|
64
|
+
r#"
|
|
65
|
+
function Index () {
|
|
66
|
+
return (
|
|
67
|
+
<View compileMode>
|
|
68
|
+
<Foo />
|
|
69
|
+
<Foo title={myTitle} loading onClick={() => {}} />
|
|
70
|
+
</View>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
73
|
+
"#
|
|
74
|
+
);
|
|
@@ -0,0 +1,79 @@
|
|
|
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_support_and_expr,
|
|
8
|
+
r#"
|
|
9
|
+
function Index () {
|
|
10
|
+
return (
|
|
11
|
+
<View compileMode>
|
|
12
|
+
{condition && <View hoverClass={myClass}>{content}</View>}
|
|
13
|
+
{condition && (
|
|
14
|
+
<View hoverClass={myClass}>{content}</View>
|
|
15
|
+
)}
|
|
16
|
+
{condition1 && "condition2" && condition3 && <View hoverClass={myClass}>{content}</View>}
|
|
17
|
+
{condition1 && 'Hello'}
|
|
18
|
+
<View hoverClass={myClass}></View>
|
|
19
|
+
</View>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
"#
|
|
23
|
+
);
|
|
24
|
+
test!(
|
|
25
|
+
get_syntax_config(),
|
|
26
|
+
|_| tr(),
|
|
27
|
+
should_support_conditional_expr,
|
|
28
|
+
r#"
|
|
29
|
+
function Index () {
|
|
30
|
+
return (
|
|
31
|
+
<View compileMode>
|
|
32
|
+
{condition ? <View hoverClass={myClass}>{content}</View> : <Text selectable>hello</Text>}
|
|
33
|
+
{condition1 ? condition2 ? <View>{a}</View> : <Text>{b}</Text> : <View>{c}</View>}
|
|
34
|
+
{condition1 ? <View>{a}</View> : condition2 ? <View>{b}</View> : <Text>{c}</Text>}
|
|
35
|
+
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
|
|
36
|
+
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
|
|
37
|
+
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
|
|
38
|
+
{condition1 ? "someText" : 789 }
|
|
39
|
+
<View hoverClass={myClass}></View>
|
|
40
|
+
</View>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
"#
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
test!(
|
|
47
|
+
get_syntax_config(),
|
|
48
|
+
|_| tr(),
|
|
49
|
+
should_support_conditional_and_unkonw_component,
|
|
50
|
+
r#"
|
|
51
|
+
function Index () {
|
|
52
|
+
return (
|
|
53
|
+
<View compileMode>
|
|
54
|
+
{condition ? <View hoverClass='test'>hello</View> : <UnKnow selectable>hello</UnKnow>}
|
|
55
|
+
</View>
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
"#
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
test!(
|
|
62
|
+
get_syntax_config(),
|
|
63
|
+
|_| tr(),
|
|
64
|
+
should_support_complex_condition,
|
|
65
|
+
r#"
|
|
66
|
+
function Index () {
|
|
67
|
+
return (
|
|
68
|
+
<View compileMode>
|
|
69
|
+
{condition1 && <View onClick={() => condition2 && doSth()} />}
|
|
70
|
+
<View>{condition1 && ident}</View>
|
|
71
|
+
<View>{condition1 && obj.property}</View>
|
|
72
|
+
<View>{condition1 && fn()}</View>
|
|
73
|
+
{condition1 ? <View className={condition2 ? '' : ''} /> : <View/>}
|
|
74
|
+
{condition1 ? <View>{condition2 ? <View/> : <View/>}</View> : <View/>}
|
|
75
|
+
</View>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
"#
|
|
79
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
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_support_single_compile_mode,
|
|
8
|
+
r#"
|
|
9
|
+
function Index () {
|
|
10
|
+
return (
|
|
11
|
+
<View compileMode></View>
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
"#
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
test!(
|
|
18
|
+
get_syntax_config(),
|
|
19
|
+
|_| tr(),
|
|
20
|
+
should_support_component_not_in_config,
|
|
21
|
+
r#"
|
|
22
|
+
function Index () {
|
|
23
|
+
return (
|
|
24
|
+
<View compileMode>
|
|
25
|
+
<View><Slider /></View>
|
|
26
|
+
<View><Test1 /></View>
|
|
27
|
+
</View>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
"#
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
test!(
|
|
34
|
+
get_syntax_config(),
|
|
35
|
+
|_| tr(),
|
|
36
|
+
should_support_compile_child_node,
|
|
37
|
+
r#"
|
|
38
|
+
function Index () {
|
|
39
|
+
return (
|
|
40
|
+
<View compileMode>
|
|
41
|
+
<View />
|
|
42
|
+
<View>
|
|
43
|
+
<Image />
|
|
44
|
+
</View>
|
|
45
|
+
</View>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
"#
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
test!(
|
|
52
|
+
get_syntax_config(),
|
|
53
|
+
|_| tr(),
|
|
54
|
+
should_support_multi_compile_mode,
|
|
55
|
+
r#"
|
|
56
|
+
function Index () {
|
|
57
|
+
return (
|
|
58
|
+
<View>
|
|
59
|
+
<Image src={mySrc} compileMode />
|
|
60
|
+
<View compileMode>
|
|
61
|
+
<Text>{myText}</Text>
|
|
62
|
+
</View>
|
|
63
|
+
</View>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
"#
|
|
67
|
+
);
|
|
@@ -0,0 +1,62 @@
|
|
|
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_blockstmt_and_set_parent_dynamic_id,
|
|
49
|
+
r#"
|
|
50
|
+
function Index () {
|
|
51
|
+
return (
|
|
52
|
+
<View compileMode>
|
|
53
|
+
<View>
|
|
54
|
+
{list.map(item => {
|
|
55
|
+
return <View>{item}</View>
|
|
56
|
+
})}
|
|
57
|
+
</View>
|
|
58
|
+
</View>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
"#
|
|
62
|
+
);
|