@tarojs/helper 3.8.0-canary.0 → 4.0.0-alpha.2
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/LICENSE +14 -0
- package/README.md +25 -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 +7 -5
- 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 +83 -33
- package/dist/utils.js.map +1 -1
- package/package.json +24 -18
- 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.lock +0 -2086
- package/swc/plugin-compile-mode/Cargo.toml +0 -20
- package/swc/plugin-compile-mode/src/lib.rs +0 -52
- package/swc/plugin-compile-mode/src/tests/attributes.rs +0 -85
- package/swc/plugin-compile-mode/src/tests/condition.rs +0 -71
- package/swc/plugin-compile-mode/src/tests/entry.rs +0 -32
- package/swc/plugin-compile-mode/src/tests/looping.rs +0 -134
- package/swc/plugin-compile-mode/src/tests/mod.rs +0 -98
- package/swc/plugin-compile-mode/src/tests/shake.rs +0 -41
- package/swc/plugin-compile-mode/src/transform.rs +0 -466
- package/swc/plugin-compile-mode/src/utils/constants.rs +0 -11
- package/swc/plugin-compile-mode/src/utils/mod.rs +0 -236
- package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
- package/swc/plugin-define-config/Cargo.lock +0 -2034
- package/swc/plugin-define-config/Cargo.toml +0 -27
- package/swc/plugin-define-config/src/lib.rs +0 -188
- package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "example_plugin"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib"]
|
|
8
|
-
|
|
9
|
-
[profile.release]
|
|
10
|
-
lto = true
|
|
11
|
-
|
|
12
|
-
[dependencies]
|
|
13
|
-
serde = { version = "1.0", features = ["derive"] }
|
|
14
|
-
serde_json = "1.0.105"
|
|
15
|
-
swc_atoms = "0.5.8"
|
|
16
|
-
swc_core = { version = "0.79.*", features = ["ecma_plugin_transform", "__parser", "ecma_codegen"] }
|
|
17
|
-
|
|
18
|
-
# .cargo/config defines few alias to build plugin.
|
|
19
|
-
# cargo build-wasi generates wasm-wasi32 binary
|
|
20
|
-
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
use swc_core::{
|
|
2
|
-
ecma::{
|
|
3
|
-
ast::Program,
|
|
4
|
-
visit::{as_folder, FoldWith},
|
|
5
|
-
},
|
|
6
|
-
plugin::{
|
|
7
|
-
plugin_transform,
|
|
8
|
-
proxies::TransformPluginProgramMetadata
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
use serde::{Serialize, Deserialize};
|
|
12
|
-
use std::collections::HashMap;
|
|
13
|
-
use core::fmt::Debug;
|
|
14
|
-
|
|
15
|
-
mod utils;
|
|
16
|
-
mod transform;
|
|
17
|
-
#[cfg(test)]
|
|
18
|
-
mod tests;
|
|
19
|
-
|
|
20
|
-
#[derive(Serialize, Deserialize, Debug)]
|
|
21
|
-
pub struct PluginConfig {
|
|
22
|
-
pub tmpl_prefix: String,
|
|
23
|
-
pub components: HashMap<String, HashMap<String, String>>,
|
|
24
|
-
pub adapter: HashMap<String, String>,
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// An example plugin function with macro support.
|
|
28
|
-
/// `plugin_transform` macro interop pointers into deserialized structs, as well
|
|
29
|
-
/// as returning ptr back to host.
|
|
30
|
-
///
|
|
31
|
-
/// It is possible to opt out from macro by writing transform fn manually
|
|
32
|
-
/// if plugin need to handle low-level ptr directly via
|
|
33
|
-
/// `__transform_plugin_process_impl(
|
|
34
|
-
/// ast_ptr: *const u8, ast_ptr_len: i32,
|
|
35
|
-
/// unresolved_mark: u32, should_enable_comments_proxy: i32) ->
|
|
36
|
-
/// i32 /* 0 for success, fail otherwise.
|
|
37
|
-
/// Note this is only for internal pointer interop result,
|
|
38
|
-
/// not actual transform result */`
|
|
39
|
-
///
|
|
40
|
-
/// This requires manual handling of serialization / deserialization from ptrs.
|
|
41
|
-
/// Refer swc_plugin_macro to see how does it work internally.
|
|
42
|
-
#[plugin_transform]
|
|
43
|
-
pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
|
|
44
|
-
let config = serde_json::from_str::<PluginConfig>(
|
|
45
|
-
&metadata
|
|
46
|
-
.get_transform_plugin_config()
|
|
47
|
-
.unwrap()
|
|
48
|
-
)
|
|
49
|
-
.unwrap();
|
|
50
|
-
let visitor = transform::TransformVisitor::new(config);
|
|
51
|
-
program.fold_with(&mut as_folder(visitor))
|
|
52
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
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_keep_static_attrs_only_in_templates,
|
|
8
|
-
r#"
|
|
9
|
-
function Index () {
|
|
10
|
-
return (
|
|
11
|
-
<View compileMode>
|
|
12
|
-
<Image className="my_img" src="https://taro.com/x.png" lazyLoad />
|
|
13
|
-
</View>
|
|
14
|
-
)
|
|
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
|
-
"#
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
test!(
|
|
28
|
-
get_syntax_config(),
|
|
29
|
-
|_| tr(),
|
|
30
|
-
should_turn_dynamic_attrs,
|
|
31
|
-
r#"
|
|
32
|
-
function Index () {
|
|
33
|
-
return (
|
|
34
|
-
<View compileMode>
|
|
35
|
-
<View class={myClass}>
|
|
36
|
-
<View style={myStyle} customProp={myCustomProp}></View>
|
|
37
|
-
<View hoverStayTime={myTime}>
|
|
38
|
-
<View hoverClass={myHoverClass}></View>
|
|
39
|
-
</View>
|
|
40
|
-
</View>
|
|
41
|
-
</View>
|
|
42
|
-
)
|
|
43
|
-
}
|
|
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
|
-
"#
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
test!(
|
|
61
|
-
get_syntax_config(),
|
|
62
|
-
|_| tr(),
|
|
63
|
-
should_handle_events,
|
|
64
|
-
r#"
|
|
65
|
-
function Index () {
|
|
66
|
-
return (
|
|
67
|
-
<View compileMode>
|
|
68
|
-
<View onClick={handleViewClick}></View>
|
|
69
|
-
<View onAnimationStart={() => {}} id={myId}></View>
|
|
70
|
-
<Image onLoad={() => {}} id="myImg" />
|
|
71
|
-
</View>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
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
|
-
"#
|
|
85
|
-
);
|
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
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
|
-
"#
|
|
35
|
-
);
|
|
36
|
-
test!(
|
|
37
|
-
get_syntax_config(),
|
|
38
|
-
|_| tr(),
|
|
39
|
-
should_support_conditional_expr,
|
|
40
|
-
r#"
|
|
41
|
-
function Index () {
|
|
42
|
-
return (
|
|
43
|
-
<View compileMode>
|
|
44
|
-
{condition ? <View hoverClass={myClass}>{content}</View> : <Text selectable>hello</Text>}
|
|
45
|
-
{condition1 ? condition2 ? <View>{a}</View> : <Text>{b}</Text> : <View>{c}</View>}
|
|
46
|
-
{condition1 ? <View>{a}</View> : condition2 ? <View>{b}</View> : <Text>{c}</Text>}
|
|
47
|
-
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
|
|
48
|
-
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
|
|
49
|
-
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
|
|
50
|
-
{condition1 ? "someText" : 789 }
|
|
51
|
-
<View hoverClass={myClass}></View>
|
|
52
|
-
</View>
|
|
53
|
-
)
|
|
54
|
-
}
|
|
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
|
-
"#
|
|
71
|
-
);
|
|
@@ -1,32 +0,0 @@
|
|
|
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_multi_compile_mode,
|
|
8
|
-
r#"
|
|
9
|
-
function Index () {
|
|
10
|
-
return (
|
|
11
|
-
<View>
|
|
12
|
-
<Image src={mySrc} compileMode />
|
|
13
|
-
<View compileMode>
|
|
14
|
-
<Text>{myText}</Text>
|
|
15
|
-
</View>
|
|
16
|
-
</View>
|
|
17
|
-
)
|
|
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
|
-
"#
|
|
32
|
-
);
|
|
@@ -1,134 +0,0 @@
|
|
|
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
|
-
r#"
|
|
27
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(item.p1,\'none\')}}" wx:for="{{i.cn}}" wx:key="sid"><text>index:</text><text>{{item.cn[0].cn[0].v}}</text><text>item:</text><text>{{item.cn[1].cn[0].v}}</text></view></view></template>';
|
|
28
|
-
function Index () {
|
|
29
|
-
return <View compileMode="f0t0">
|
|
30
|
-
{list.map(function(item, index) {
|
|
31
|
-
return <View hoverClass={myClass}>
|
|
32
|
-
|
|
33
|
-
<Text>{index}</Text>
|
|
34
|
-
|
|
35
|
-
<Text>{item}</Text>
|
|
36
|
-
</View>
|
|
37
|
-
})}
|
|
38
|
-
</View>
|
|
39
|
-
}
|
|
40
|
-
"#
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
test!(
|
|
44
|
-
get_syntax_config(),
|
|
45
|
-
|_| tr(),
|
|
46
|
-
should_loop_with_arrow_function_with_blockstmt,
|
|
47
|
-
r#"
|
|
48
|
-
function Index () {
|
|
49
|
-
return (
|
|
50
|
-
<View compileMode>
|
|
51
|
-
{list.map(item => {
|
|
52
|
-
return <View>{item}</View>
|
|
53
|
-
})}
|
|
54
|
-
</View>
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
"#,
|
|
58
|
-
r#"
|
|
59
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view wx:for="{{i.cn}}" wx:key="sid">{{item.cn[0].v}}</view></view></template>';
|
|
60
|
-
function Index () {
|
|
61
|
-
return <View compileMode="f0t0">
|
|
62
|
-
{list.map(item => {
|
|
63
|
-
return <View>{item}</View>
|
|
64
|
-
})}
|
|
65
|
-
</View>
|
|
66
|
-
}
|
|
67
|
-
"#
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
test!(
|
|
71
|
-
get_syntax_config(),
|
|
72
|
-
|_| tr(),
|
|
73
|
-
should_loop_with_arrow_function_with_expr,
|
|
74
|
-
r#"
|
|
75
|
-
function Index () {
|
|
76
|
-
return (
|
|
77
|
-
<View compileMode>
|
|
78
|
-
{list.map(item => <View>{item}</View>)}
|
|
79
|
-
</View>
|
|
80
|
-
)
|
|
81
|
-
}
|
|
82
|
-
"#,
|
|
83
|
-
r#"
|
|
84
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view wx:for="{{i.cn}}" wx:key="sid">{{item.cn[0].v}}</view></view></template>';
|
|
85
|
-
function Index () {
|
|
86
|
-
return <View compileMode="f0t0">
|
|
87
|
-
{list.map(item => <View>{item}</View>)}
|
|
88
|
-
</View>
|
|
89
|
-
}
|
|
90
|
-
"#
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
test!(
|
|
94
|
-
get_syntax_config(),
|
|
95
|
-
|_| tr(),
|
|
96
|
-
should_support_nested_loop,
|
|
97
|
-
r#"
|
|
98
|
-
function Index () {
|
|
99
|
-
return (
|
|
100
|
-
<View compileMode>
|
|
101
|
-
{list.map(function(item, index) {
|
|
102
|
-
return (
|
|
103
|
-
<View hoverClass={myClass} key={index}>
|
|
104
|
-
<View>title: {item}</View>
|
|
105
|
-
<View>
|
|
106
|
-
{sublist.map(function(c) {
|
|
107
|
-
return <Text selectable={isSelectable}>content: {c}</Text>
|
|
108
|
-
})}
|
|
109
|
-
</View>
|
|
110
|
-
</View>
|
|
111
|
-
)
|
|
112
|
-
})}
|
|
113
|
-
</View>
|
|
114
|
-
)
|
|
115
|
-
}
|
|
116
|
-
"#,
|
|
117
|
-
r#"
|
|
118
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(item.p1,\'none\')}}" wx:for="{{i.cn}}" wx:key="sid"><view>title: {{item.cn[0].cn[0].v}}</view><view><text selectable="{{xs.b(item.p1,!1)}}" wx:for="{{item.cn[1].cn}}" wx:key="sid">content: {{item.cn[0].v}}</text></view></view></view></template>';
|
|
119
|
-
function Index () {
|
|
120
|
-
return <View compileMode="f0t0">
|
|
121
|
-
{list.map(function(item, index) {
|
|
122
|
-
return <View hoverClass={myClass} key={index}>
|
|
123
|
-
<View>{item}</View>
|
|
124
|
-
<View>
|
|
125
|
-
{sublist.map(function(c) {
|
|
126
|
-
return <Text selectable={isSelectable}>{c}</Text>
|
|
127
|
-
})}
|
|
128
|
-
</View>
|
|
129
|
-
</View>
|
|
130
|
-
})}
|
|
131
|
-
</View>
|
|
132
|
-
}
|
|
133
|
-
"#
|
|
134
|
-
);
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
mod entry;
|
|
2
|
-
mod attributes;
|
|
3
|
-
mod shake;
|
|
4
|
-
mod condition;
|
|
5
|
-
mod looping;
|
|
6
|
-
|
|
7
|
-
use swc_core::ecma::{
|
|
8
|
-
parser,
|
|
9
|
-
visit::{as_folder, Fold, VisitMut},
|
|
10
|
-
};
|
|
11
|
-
use crate::{
|
|
12
|
-
PluginConfig,
|
|
13
|
-
transform::*,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
pub fn tr () -> impl Fold + VisitMut {
|
|
17
|
-
let config = serde_json::from_str::<PluginConfig>(
|
|
18
|
-
r#"
|
|
19
|
-
{
|
|
20
|
-
"tmpl_prefix": "f0",
|
|
21
|
-
"components": {
|
|
22
|
-
"block": {},
|
|
23
|
-
"image": {
|
|
24
|
-
"src": "i.p3",
|
|
25
|
-
"mode": "xs.b(i.p1,'scaleToFill')",
|
|
26
|
-
"lazy-load": "xs.b(i.p0,!1)",
|
|
27
|
-
"binderror": "eh",
|
|
28
|
-
"bindload": "eh",
|
|
29
|
-
"bindtouchstart": "eh",
|
|
30
|
-
"bindtouchmove": "eh",
|
|
31
|
-
"bindtouchend": "eh",
|
|
32
|
-
"bindtouchcancel": "eh",
|
|
33
|
-
"bindlongpress": "eh",
|
|
34
|
-
"webp": "xs.b(i.p4,false)",
|
|
35
|
-
"show-menu-by-longpress": "xs.b(i.p2,false)",
|
|
36
|
-
"style": "i.st",
|
|
37
|
-
"class": "i.cl",
|
|
38
|
-
"bindtap": "eh"
|
|
39
|
-
},
|
|
40
|
-
"view": {
|
|
41
|
-
"hover-class": "xs.b(i.p1,'none')",
|
|
42
|
-
"hover-stop-propagation": "xs.b(i.p4,!1)",
|
|
43
|
-
"hover-start-time": "xs.b(i.p2,50)",
|
|
44
|
-
"hover-stay-time": "xs.b(i.p3,400)",
|
|
45
|
-
"bindtouchstart": "eh",
|
|
46
|
-
"bindtouchmove": "eh",
|
|
47
|
-
"bindtouchend": "eh",
|
|
48
|
-
"bindtouchcancel": "eh",
|
|
49
|
-
"bindlongpress": "eh",
|
|
50
|
-
"animation": "i.p0",
|
|
51
|
-
"bindanimationstart": "eh",
|
|
52
|
-
"bindanimationiteration": "eh",
|
|
53
|
-
"bindanimationend": "eh",
|
|
54
|
-
"bindtransitionend": "eh",
|
|
55
|
-
"style": "i.st",
|
|
56
|
-
"class": "i.cl",
|
|
57
|
-
"bindtap": "eh"
|
|
58
|
-
},
|
|
59
|
-
"text": {
|
|
60
|
-
"selectable": "xs.b(i.p1,!1)",
|
|
61
|
-
"space": "i.p2",
|
|
62
|
-
"decode": "xs.b(i.p0,!1)",
|
|
63
|
-
"user-select": "xs.b(i.p3,false)",
|
|
64
|
-
"style": "i.st",
|
|
65
|
-
"class": "i.cl",
|
|
66
|
-
"bindtap": "eh"
|
|
67
|
-
},
|
|
68
|
-
"movable-area": {
|
|
69
|
-
"scale-area": "xs.b(i.p0,!1)",
|
|
70
|
-
"style": "i.st",
|
|
71
|
-
"class": "i.cl",
|
|
72
|
-
"bindtap": "eh"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"adapter": {
|
|
76
|
-
"if": "wx:if",
|
|
77
|
-
"else": "wx:else",
|
|
78
|
-
"elseif": "wx:elif",
|
|
79
|
-
"for": "wx:for",
|
|
80
|
-
"forItem": "wx:for-item",
|
|
81
|
-
"forIndex": "wx:for-index",
|
|
82
|
-
"key": "wx:key",
|
|
83
|
-
"xs": "wxs",
|
|
84
|
-
"type": "weapp"
|
|
85
|
-
}
|
|
86
|
-
}"#
|
|
87
|
-
)
|
|
88
|
-
.unwrap();
|
|
89
|
-
let visitor = TransformVisitor::new(config);
|
|
90
|
-
as_folder(visitor)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
pub fn get_syntax_config () -> parser::Syntax {
|
|
94
|
-
parser::Syntax::Es(parser::EsConfig {
|
|
95
|
-
jsx: true,
|
|
96
|
-
..Default::default()
|
|
97
|
-
})
|
|
98
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
r#"
|
|
28
|
-
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><text>Hello World!</text><text>Hello{{i.cn[0].cn[0].v}}World{{i.cn[0].cn[1].v}}!</text><view><text></text></view><view hover-stop-propagation="true" style="color: red"><text>Hello World!</text></view><view style="{{i.cn[1].st}}"><text>Hello World!</text></view></view></template>';
|
|
29
|
-
function Index () {
|
|
30
|
-
return <View compileMode="f0t0">
|
|
31
|
-
|
|
32
|
-
<Text>{T1}{T2}</Text>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<View style={myStyle}>
|
|
36
|
-
|
|
37
|
-
</View>
|
|
38
|
-
</View>
|
|
39
|
-
}
|
|
40
|
-
"#
|
|
41
|
-
);
|