Skip to content

Commit 2b6aebe

Browse files
author
mayintao3
committed
Merge branch 'main' into feat/harmony
2 parents 188e5e2 + 8501202 commit 2b6aebe

File tree

372 files changed

+31265
-17321
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+31265
-17321
lines changed

.cargo/config.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ rustflags = ["-C", "target-feature=+crt-static"]
2020
# Alias to build actual SWC plugin binary for the specified target.
2121
build-wasi = "build --target wasm32-wasi"
2222
build-wasm32 = "build --target wasm32-unknown-unknown"
23-
build-swc-plugins = "build-wasi --release -p swc_plugin_compile_mode -p swc_plugin_define_config"
24-
test-swc-plugins = "test -p swc_plugin_compile_mode -p swc_plugin_define_config"
23+
build-swc-plugins = "build-wasi --release -p swc_plugin_compile_mode -p swc_plugin_define_config -p swc_plugin_compile_mode_pre_process"
24+
test-swc-plugins = "test -p swc_plugin_compile_mode -p swc_plugin_define_config -p swc_plugin_compile_mode_pre_process"

.github/workflows/nodejs.yml

-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ jobs:
113113
run: pnpm test
114114
env:
115115
CI: true
116-
- name: Upload coverage reports to Codecov
117-
uses: codecov/codecov-action@v3
118-
env:
119-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
120-
121116
# 以下 coverage 流程通过 artifact 拆分文件作为单独 job 上传时间损耗过长,因此在在 node test 后直接继续执行
122117
- name: Upload [taro-cli] coverage to Codecov
123118
uses: codecov/codecov-action@v4

.husky/commit-msg

100644100755
File mode changed.

.husky/pre-commit

100644100755
File mode changed.

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"./crates/taro_init/Cargo.toml",
1919
"./crates/native_binding/Cargo.toml",
2020
"./crates/swc_plugin_compile_mode/Cargo.toml",
21-
"./crates/swc_plugin_define_config/Cargo.toml"
21+
"./crates/swc_plugin_define_config/Cargo.toml",
22+
"./crates/swc_plugin_compile_mode_pre_process/Cargo.toml"
2223
],
2324
"rust-analyzer.showUnlinkedFileNotification": false
2425
}

Cargo.lock

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/native_binding/binding.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface CreateOptions {
2323
version?: string
2424
date?: string
2525
typescript?: boolean
26+
buildEs5?: boolean
2627
template: string
2728
pageName?: string
2829
compiler?: CompilerType
@@ -105,6 +106,7 @@ export interface Project {
105106
npm: NpmType
106107
description?: string
107108
typescript?: boolean
109+
buildEs5?: boolean
108110
template: string
109111
css: CSSType
110112
autoInstall?: boolean

crates/native_binding/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tarojs/binding",
3-
"version": "4.0.0-beta.139",
3+
"version": "4.0.8",
44
"description": "Node binding for taro",
55
"main": "binding.js",
66
"typings": "binding.d.ts",

crates/native_binding/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub async fn create_project(
1818
conf.npm,
1919
conf.description,
2020
conf.typescript,
21+
conf.build_es5,
2122
conf.template,
2223
conf.css,
2324
conf.framework,

crates/swc_plugin_compile_mode/.editorconfig

-6
This file was deleted.
+52-50
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
1+
use serde::Deserialize;
2+
use std::collections::HashMap;
13
use swc_core::{
2-
ecma::{
3-
ast::Program,
4-
visit::{as_folder, FoldWith, VisitMut},
5-
},
6-
plugin::{
7-
plugin_transform,
8-
proxies::TransformPluginProgramMetadata
9-
}
4+
ecma::{
5+
ast::Program,
6+
visit::{as_folder, FoldWith, VisitMut},
7+
},
8+
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
109
};
11-
use serde::{Deserialize};
12-
use std::collections::HashMap;
1310

14-
mod utils;
15-
mod transform;
16-
mod transform_harmony;
1711
#[cfg(test)]
1812
mod tests;
13+
mod transform;
14+
mod transform_harmony;
15+
mod utils;
1916

2017
struct SerdeDefault;
2118
impl SerdeDefault {
22-
fn platform_default () -> String {
23-
String::from("WEAPP")
24-
}
19+
fn platform_default() -> String {
20+
String::from("WEAPP")
21+
}
22+
fn is_use_xs_default() -> bool {
23+
true
24+
}
25+
fn template_tag_default() -> String {
26+
String::from("")
27+
}
2528
}
2629

27-
#[derive(Deserialize, Debug)]
30+
#[derive(Deserialize, Debug)]
2831
pub struct ComponentReplace {
29-
pub current_init: String,
30-
pub dependency_define: String,
32+
pub current_init: String,
33+
pub dependency_define: String,
3134
}
3235
#[derive(Deserialize, Debug)]
3336
pub struct PluginConfig {
34-
pub tmpl_prefix: String,
35-
#[serde(default = "SerdeDefault::platform_default")]
36-
pub platform: String,
37-
#[serde(default)]
38-
pub is_harmony: bool,
39-
#[serde(default)]
40-
pub components: HashMap<String, HashMap<String, String>>,
41-
#[serde(default)]
42-
pub adapter: HashMap<String, String>,
43-
#[serde(default)]
44-
pub support_events: Vec<String>,
45-
#[serde(default)]
46-
pub support_components: Vec<String>,
47-
#[serde(default)]
48-
pub event_adapter: HashMap<String, String>,
49-
#[serde(default)]
50-
pub component_replace: HashMap<String, ComponentReplace>,
51-
37+
pub tmpl_prefix: String,
38+
#[serde(default = "SerdeDefault::platform_default")]
39+
pub platform: String,
40+
#[serde(default)]
41+
pub is_harmony: bool,
42+
#[serde(default)]
43+
pub components: HashMap<String, HashMap<String, String>>,
44+
#[serde(default)]
45+
pub adapter: HashMap<String, String>,
46+
#[serde(default)]
47+
pub support_events: Vec<String>,
48+
#[serde(default)]
49+
pub support_components: Vec<String>,
50+
#[serde(default)]
51+
pub event_adapter: HashMap<String, String>,
52+
#[serde(default)]
53+
pub component_replace: HashMap<String, ComponentReplace>,
54+
#[serde(default = "SerdeDefault::is_use_xs_default")]
55+
pub is_use_xs: bool,
56+
#[serde(default = "SerdeDefault::template_tag_default")]
57+
pub template_tag: String,
5258
}
5359

5460
/// An example plugin function with macro support.
@@ -68,19 +74,15 @@ pub struct PluginConfig {
6874
/// Refer swc_plugin_macro to see how does it work internally.
6975
#[plugin_transform]
7076
pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
71-
let config = serde_json::from_str::<PluginConfig>(
72-
&metadata
73-
.get_transform_plugin_config()
74-
.unwrap()
75-
)
76-
.unwrap();
77+
let config =
78+
serde_json::from_str::<PluginConfig>(&metadata.get_transform_plugin_config().unwrap()).unwrap();
7779

78-
// 如果 config 中的 is_harmony 字段为 true 则走 harmony_transform, 否则则走 transform
79-
let visitor: Box<dyn VisitMut> = if config.is_harmony {
80-
Box::new(transform_harmony::TransformVisitor::new(config))
81-
} else {
82-
Box::new(transform::TransformVisitor::new(config))
83-
};
80+
// 如果 config 中的 is_harmony 字段为 true 则走 harmony_transform, 否则则走 transform
81+
let visitor: Box<dyn VisitMut> = if config.is_harmony {
82+
Box::new(transform_harmony::TransformVisitor::new(config))
83+
} else {
84+
Box::new(transform::TransformVisitor::new(config))
85+
};
8486

85-
program.fold_with(&mut as_folder(visitor))
87+
program.fold_with(&mut as_folder(visitor))
8688
}

crates/swc_plugin_compile_mode/src/tests/attributes.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use super::{get_syntax_config, tr};
12
use swc_core::ecma::transforms::testing::test;
2-
use super::{tr, get_syntax_config};
33

44
test!(
5-
get_syntax_config(),
6-
|_| tr(),
7-
should_keep_static_attrs_only_in_templates,
8-
r#"
5+
get_syntax_config(),
6+
|_| tr(),
7+
should_keep_static_attrs_only_in_templates,
8+
r#"
99
function Index () {
1010
return (
1111
<View compileMode>
@@ -17,10 +17,10 @@ test!(
1717
);
1818

1919
test!(
20-
get_syntax_config(),
21-
|_| tr(),
22-
should_turn_dynamic_attrs,
23-
r#"
20+
get_syntax_config(),
21+
|_| tr(),
22+
should_turn_dynamic_attrs,
23+
r#"
2424
function Index () {
2525
return (
2626
<View compileMode>
@@ -37,16 +37,17 @@ test!(
3737
);
3838

3939
test!(
40-
get_syntax_config(),
41-
|_| tr(),
42-
should_handle_events,
43-
r#"
40+
get_syntax_config(),
41+
|_| tr(),
42+
should_handle_events,
43+
r#"
4444
function Index () {
4545
return (
4646
<View compileMode>
4747
<View onClick={handleViewClick}></View>
4848
<View onAnimationStart={() => {}} id={myId}></View>
4949
<Image onLoad={() => {}} id="myImg" />
50+
<View nativeView="view" onScroll={() => {}} onScrollUpdateWorklet="onScrollUpdate" onGestureWorklet="onGesture" shouldResponseOnMoveWorklet="shouldResponseOnMoveCallBack"></View>
5051
</View>
5152
)
5253
}

crates/swc_plugin_compile_mode/src/tests/children.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use super::{get_syntax_config, tr};
12
use swc_core::ecma::transforms::testing::test;
2-
use super::{tr, get_syntax_config};
33

44
test!(
5-
get_syntax_config(),
6-
|_| tr(),
7-
should_support_render_fn,
8-
r#"
5+
get_syntax_config(),
6+
|_| tr(),
7+
should_support_render_fn,
8+
r#"
99
function Index () {
1010
return (
1111
<View compileMode>
@@ -19,10 +19,10 @@ test!(
1919
);
2020

2121
test!(
22-
get_syntax_config(),
23-
|_| tr(),
24-
should_support_fragment,
25-
r#"
22+
get_syntax_config(),
23+
|_| tr(),
24+
should_support_fragment,
25+
r#"
2626
function Index () {
2727
return (
2828
<View compileMode>
@@ -54,10 +54,10 @@ test!(
5454
);
5555

5656
test!(
57-
get_syntax_config(),
58-
|_| tr(),
59-
should_support_context_api,
60-
r#"
57+
get_syntax_config(),
58+
|_| tr(),
59+
should_support_context_api,
60+
r#"
6161
function Index () {
6262
return (
6363
<View compileMode>
@@ -77,10 +77,10 @@ test!(
7777
);
7878

7979
test!(
80-
get_syntax_config(),
81-
|_| tr(),
82-
should_render_react_component,
83-
r#"
80+
get_syntax_config(),
81+
|_| tr(),
82+
should_render_react_component,
83+
r#"
8484
function Index () {
8585
return (
8686
<View compileMode>
@@ -94,10 +94,10 @@ test!(
9494
);
9595

9696
test!(
97-
get_syntax_config(),
98-
|_| tr(),
99-
should_render_native_component,
100-
r#"
97+
get_syntax_config(),
98+
|_| tr(),
99+
should_render_native_component,
100+
r#"
101101
function Index () {
102102
return (
103103
<View compileMode>

0 commit comments

Comments
 (0)