@tarojs/helper 4.0.0-beta.0 → 4.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esbuild/index.js +2 -2
- package/dist/esbuild/index.js.map +1 -1
- package/dist/utils.js +3 -6
- package/dist/utils.js.map +1 -1
- package/package.json +4 -3
- package/swc/.gitkeep +0 -0
- package/swc/swc_plugin_compile_mode.wasm +0 -0
- package/swc/swc_plugin_define_config.wasm +0 -0
- package/swc/plugin-compile-mode/.cargo/config +0 -5
- package/swc/plugin-compile-mode/.editorconfig +0 -6
- package/swc/plugin-compile-mode/.vscode/settings.json +0 -3
- package/swc/plugin-compile-mode/Cargo.lock +0 -2021
- package/swc/plugin-compile-mode/Cargo.toml +0 -22
- package/swc/plugin-compile-mode/package.json +0 -15
- package/swc/plugin-compile-mode/src/lib.rs +0 -71
- package/swc/plugin-compile-mode/src/tests/attributes.rs +0 -54
- package/swc/plugin-compile-mode/src/tests/children.rs +0 -86
- package/swc/plugin-compile-mode/src/tests/condition.rs +0 -50
- package/swc/plugin-compile-mode/src/tests/entry.rs +0 -20
- package/swc/plugin-compile-mode/src/tests/harmony/attributes.rs +0 -45
- package/swc/plugin-compile-mode/src/tests/harmony/children.rs +0 -74
- package/swc/plugin-compile-mode/src/tests/harmony/condition.rs +0 -79
- package/swc/plugin-compile-mode/src/tests/harmony/entry.rs +0 -67
- package/swc/plugin-compile-mode/src/tests/harmony/looping.rs +0 -62
- package/swc/plugin-compile-mode/src/tests/harmony/mod.rs +0 -45
- package/swc/plugin-compile-mode/src/tests/looping.rs +0 -84
- package/swc/plugin-compile-mode/src/tests/mod.rs +0 -100
- package/swc/plugin-compile-mode/src/tests/shake.rs +0 -27
- package/swc/plugin-compile-mode/src/transform.rs +0 -474
- package/swc/plugin-compile-mode/src/transform_harmony.rs +0 -526
- package/swc/plugin-compile-mode/src/utils/constants.rs +0 -152
- package/swc/plugin-compile-mode/src/utils/harmony/components.rs +0 -61
- package/swc/plugin-compile-mode/src/utils/harmony/mod.rs +0 -1
- package/swc/plugin-compile-mode/src/utils/mod.rs +0 -347
- package/swc/plugin-compile-mode/target/wasm32-wasi/release/swc_plugin_compile_mode.wasm +0 -0
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_handle_events.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_keep_static_attrs_only_in_templates.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/attributes.rs/should_turn_dynamic_attrs.js +0 -11
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_native_component.js +0 -7
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_render_react_component.js +0 -7
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_fragment.js +0 -44
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/children.rs/should_support_render_fn.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_and_expr.js +0 -14
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/condition.rs/should_support_conditional_expr.js +0 -15
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/entry.rs/should_support_multi_compile_mode.js +0 -10
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_handle_events.js +0 -183
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/attributes.rs/should_turn_dynamic_attrs.js +0 -186
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_render_react_component.js +0 -76
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_fragment.js +0 -341
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/children.rs/should_support_render_fn.js +0 -186
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_and_expr.js +0 -211
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_complex_condition.js +0 -244
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_and_unkonw_component.js +0 -139
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/condition.rs/should_support_conditional_expr.js +0 -344
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_compile_child_node.js +0 -141
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_component_not_in_config.js +0 -91
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_multi_compile_mode.js +0 -209
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/entry.rs/should_support_single_compile_mode.js +0 -66
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +0 -76
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_arrow_function_with_blockstmt_and_set_parent_dynamic_id.js +0 -89
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/harmony/looping.rs/should_loop_with_function_expr.js +0 -86
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_blockstmt.js +0 -8
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_arrow_function_with_expr.js +0 -6
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_loop_with_function_expr.js +0 -20
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/looping.rs/should_support_nested_loop.js +0 -15
- package/swc/plugin-compile-mode/tests/__swc_snapshots__/src/tests/shake.rs/should_static_jsx_being_shaked.js +0 -20
- package/swc/plugin-define-config/.cargo/config +0 -5
- package/swc/plugin-define-config/Cargo.lock +0 -2110
- package/swc/plugin-define-config/Cargo.toml +0 -18
- package/swc/plugin-define-config/src/lib.rs +0 -141
- package/swc/plugin-define-config/target/wasm32-wasi/release/swc_plugin_define_config.wasm +0 -0
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_app.js +0 -2
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_decl_default_page.js +0 -2
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/module_exports.js +0 -11
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_app.js +0 -3
- package/swc/plugin-define-config/tests/__swc_snapshots__/src/lib.rs/var_decl_page.js +0 -3
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
[package]
|
|
2
|
-
name = "swc_plugin_compile_mode"
|
|
3
|
-
version = "0.1.0"
|
|
4
|
-
edition = "2021"
|
|
5
|
-
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib"]
|
|
8
|
-
|
|
9
|
-
[profile.release]
|
|
10
|
-
lto = false # https://github.com/swc-project/swc/issues/7479
|
|
11
|
-
|
|
12
|
-
[dependencies]
|
|
13
|
-
serde = { version = "1.0", features = ["derive"] }
|
|
14
|
-
serde_json = "1.0.105"
|
|
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"] }
|
|
19
|
-
|
|
20
|
-
# .cargo/config defines few alias to build plugin.
|
|
21
|
-
# cargo build-wasi generates wasm-wasi32 binary
|
|
22
|
-
# cargo build-wasm32 generates wasm32-unknown-unknown binary.
|
|
@@ -1,15 +0,0 @@
|
|
|
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,71 +0,0 @@
|
|
|
1
|
-
use swc_core::{
|
|
2
|
-
ecma::{
|
|
3
|
-
ast::Program,
|
|
4
|
-
visit::{as_folder, FoldWith, VisitMut},
|
|
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
|
-
mod transform_harmony;
|
|
18
|
-
#[cfg(test)]
|
|
19
|
-
mod tests;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
#[derive(Serialize, Deserialize, Debug)]
|
|
23
|
-
pub struct PluginConfig {
|
|
24
|
-
pub tmpl_prefix: String,
|
|
25
|
-
#[serde(default)]
|
|
26
|
-
pub is_harmony: bool,
|
|
27
|
-
#[serde(default)]
|
|
28
|
-
pub components: HashMap<String, HashMap<String, String>>,
|
|
29
|
-
#[serde(default)]
|
|
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>,
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/// An example plugin function with macro support.
|
|
40
|
-
/// `plugin_transform` macro interop pointers into deserialized structs, as well
|
|
41
|
-
/// as returning ptr back to host.
|
|
42
|
-
///
|
|
43
|
-
/// It is possible to opt out from macro by writing transform fn manually
|
|
44
|
-
/// if plugin need to handle low-level ptr directly via
|
|
45
|
-
/// `__transform_plugin_process_impl(
|
|
46
|
-
/// ast_ptr: *const u8, ast_ptr_len: i32,
|
|
47
|
-
/// unresolved_mark: u32, should_enable_comments_proxy: i32) ->
|
|
48
|
-
/// i32 /* 0 for success, fail otherwise.
|
|
49
|
-
/// Note this is only for internal pointer interop result,
|
|
50
|
-
/// not actual transform result */`
|
|
51
|
-
///
|
|
52
|
-
/// This requires manual handling of serialization / deserialization from ptrs.
|
|
53
|
-
/// Refer swc_plugin_macro to see how does it work internally.
|
|
54
|
-
#[plugin_transform]
|
|
55
|
-
pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
|
|
56
|
-
let config = serde_json::from_str::<PluginConfig>(
|
|
57
|
-
&metadata
|
|
58
|
-
.get_transform_plugin_config()
|
|
59
|
-
.unwrap()
|
|
60
|
-
)
|
|
61
|
-
.unwrap();
|
|
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
|
-
|
|
70
|
-
program.fold_with(&mut as_folder(visitor))
|
|
71
|
-
}
|
|
@@ -1,54 +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 key="image" ref={myRefCb} />
|
|
13
|
-
</View>
|
|
14
|
-
)
|
|
15
|
-
}
|
|
16
|
-
"#
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
test!(
|
|
20
|
-
get_syntax_config(),
|
|
21
|
-
|_| tr(),
|
|
22
|
-
should_turn_dynamic_attrs,
|
|
23
|
-
r#"
|
|
24
|
-
function Index () {
|
|
25
|
-
return (
|
|
26
|
-
<View compileMode>
|
|
27
|
-
<View class={myClass}>
|
|
28
|
-
<View style={myStyle} customProp={myCustomProp}></View>
|
|
29
|
-
<View hoverStayTime={myTime}>
|
|
30
|
-
<View hoverClass={myHoverClass}></View>
|
|
31
|
-
</View>
|
|
32
|
-
</View>
|
|
33
|
-
</View>
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
"#
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
test!(
|
|
40
|
-
get_syntax_config(),
|
|
41
|
-
|_| tr(),
|
|
42
|
-
should_handle_events,
|
|
43
|
-
r#"
|
|
44
|
-
function Index () {
|
|
45
|
-
return (
|
|
46
|
-
<View compileMode>
|
|
47
|
-
<View onClick={handleViewClick}></View>
|
|
48
|
-
<View onAnimationStart={() => {}} id={myId}></View>
|
|
49
|
-
<Image onLoad={() => {}} id="myImg" />
|
|
50
|
-
</View>
|
|
51
|
-
)
|
|
52
|
-
}
|
|
53
|
-
"#
|
|
54
|
-
);
|
|
@@ -1,86 +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_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
|
-
);
|
|
@@ -1,50 +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
|
-
{condition1 && <View onClick={() => condition2 && doSth()} />}
|
|
19
|
-
<View hoverClass={myClass}></View>
|
|
20
|
-
<View>{condition1 && ident}</View>
|
|
21
|
-
<View>{condition1 && obj.property}</View>
|
|
22
|
-
<View>{condition1 && fn()}</View>
|
|
23
|
-
</View>
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
"#
|
|
27
|
-
);
|
|
28
|
-
test!(
|
|
29
|
-
get_syntax_config(),
|
|
30
|
-
|_| tr(),
|
|
31
|
-
should_support_conditional_expr,
|
|
32
|
-
r#"
|
|
33
|
-
function Index () {
|
|
34
|
-
return (
|
|
35
|
-
<View compileMode>
|
|
36
|
-
{condition ? <View hoverClass={myClass}>{content}</View> : <Text selectable>hello</Text>}
|
|
37
|
-
{condition1 ? condition2 ? <View>{a}</View> : <Text>{b}</Text> : <View>{c}</View>}
|
|
38
|
-
{condition1 ? <View>{a}</View> : condition2 ? <View>{b}</View> : <Text>{c}</Text>}
|
|
39
|
-
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
|
|
40
|
-
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
|
|
41
|
-
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
|
|
42
|
-
{condition1 ? "someText" : 789}
|
|
43
|
-
{condition1 ? <View className={condition2 ? '' : ''} /> : <View/>}
|
|
44
|
-
{condition1 ? <View>{condition2 ? <View/> : <View/>}</View> : <View/>}
|
|
45
|
-
<View hoverClass={myClass}></View>
|
|
46
|
-
</View>
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
"#
|
|
50
|
-
);
|
|
@@ -1,20 +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
|
-
);
|
|
@@ -1,45 +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_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
|
-
);
|
|
@@ -1,74 +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_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
|
-
);
|
|
@@ -1,79 +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
|
-
);
|
|
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
|
-
);
|
|
@@ -1,67 +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_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
|
-
);
|
|
@@ -1,62 +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
|
-
);
|
|
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
|
-
);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
pub use super::get_syntax_config;
|
|
2
|
-
use swc_core::ecma::visit::{as_folder, Fold, VisitMut};
|
|
3
|
-
use crate::{
|
|
4
|
-
PluginConfig,
|
|
5
|
-
transform_harmony::*,
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
mod entry;
|
|
9
|
-
mod attributes;
|
|
10
|
-
mod condition;
|
|
11
|
-
mod looping;
|
|
12
|
-
mod children;
|
|
13
|
-
|
|
14
|
-
pub fn tr () -> impl Fold + VisitMut {
|
|
15
|
-
let config = serde_json::from_str::<PluginConfig>(
|
|
16
|
-
r#"
|
|
17
|
-
{
|
|
18
|
-
"is_harmony": true,
|
|
19
|
-
"tmpl_prefix": "f0",
|
|
20
|
-
"support_events": [
|
|
21
|
-
"onLoad",
|
|
22
|
-
"onClick",
|
|
23
|
-
"onTouchEnd",
|
|
24
|
-
"onTouchMove",
|
|
25
|
-
"onTouchStart",
|
|
26
|
-
"onTouchCancel"
|
|
27
|
-
],
|
|
28
|
-
"support_components": [
|
|
29
|
-
"view",
|
|
30
|
-
"text",
|
|
31
|
-
"image"
|
|
32
|
-
],
|
|
33
|
-
"event_adapter": {
|
|
34
|
-
"onTouchEnd": "onTouch",
|
|
35
|
-
"onTouchMove": "onTouch",
|
|
36
|
-
"onTouchStart": "onTouch",
|
|
37
|
-
"onTouchCancel": "onTouch",
|
|
38
|
-
"onLoad": "onComplete"
|
|
39
|
-
}
|
|
40
|
-
}"#
|
|
41
|
-
)
|
|
42
|
-
.unwrap();
|
|
43
|
-
let visitor = TransformVisitor::new(config);
|
|
44
|
-
as_folder(visitor)
|
|
45
|
-
}
|