Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 添加 useXsForTemplate 试用性字段以及半编译预处理功能 #16598

Merged
merged 33 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
62c23b9
feat: init
ZEJIA-LIU Sep 2, 2024
3c08c90
feat: 完成模块拆分与基本工作流
ZEJIA-LIU Sep 3, 2024
ec46d05
feat: 完成组件收集
ZEJIA-LIU Sep 10, 2024
4b3423c
feat: 完成收集环节和转化环节的串联
ZEJIA-LIU Sep 12, 2024
1c48427
feat: 完成react组件中render组件的搜集
ZEJIA-LIU Sep 13, 2024
db36eca
feat: 拓扑算法输出依赖顺序
ZEJIA-LIU Sep 14, 2024
0bffcc0
chore(release): publish 4.0.6-alpha.0 --tag=alpha
ZEJIA-LIU Sep 23, 2024
361d064
Merge branch 'feat/4.0.6' into feat/compile_mode_pre_process
ZEJIA-LIU Sep 23, 2024
c8b6520
feat: 暂时保存
ZEJIA-LIU Sep 23, 2024
43276a5
feat: 补齐绝大部份测试用例
ZEJIA-LIU Sep 23, 2024
96fabe3
lint: 使用rustfmt 统一代码风格
ZEJIA-LIU Sep 24, 2024
2bfeac8
style: 优化目录结构
ZEJIA-LIU Sep 24, 2024
672dd3d
feat: 完善测试用例
ZEJIA-LIU Sep 24, 2024
54f1a1b
ci: 添加新的swc插件编译命令
ZEJIA-LIU Sep 24, 2024
e435c31
feat: 接入半编译预处理 swc 插件
ZEJIA-LIU Sep 24, 2024
b4ebb8a
Merge branch 'main' into feat/compile_mode_pre_process
ZEJIA-LIU Sep 24, 2024
a1e3801
chore(debug): 增加快捷调试脚本&解决husky不工作问题
Jul 25, 2024
3f2a6f6
perf(setData): 优先使用微任务执行setData
Jul 25, 2024
fc242df
perf(wxs): 增加模版渲染时是否使用wxs配置(不使用wxs性能可提升10%以上)
Aug 27, 2024
8b4ee9f
perf(event): 增加clickview模版,减少冗余事件绑定
Sep 2, 2024
8ec53d9
perf(template): 移除模版中用于循环体的block标签,降低节点嵌套和模版大小
Sep 3, 2024
eae48a9
Merge branch 'perf/setData' into feat/4.0.7
Sep 25, 2024
249cd19
chore(release): publish 4.0.7-alpha.1 --tag=alpha
Sep 25, 2024
50ddb97
test: 更新snapshots
Sep 25, 2024
114540b
perf(setData): 修复不使用wxs时custom-wrapper组件l属性为null导致的warning问题
Sep 25, 2024
5f371a0
feat: 半编译支持没有xs的情况
ZEJIA-LIU Oct 10, 2024
dc52ad4
lint: fix
ZEJIA-LIU Oct 10, 2024
ffe1bb5
feat: 更新半编译swc
ZEJIA-LIU Oct 10, 2024
5e3b781
chore(release): publish 4.0.7-alpha.2 --tag=alpha
ZEJIA-LIU Oct 10, 2024
756c0d1
Merge branch 'main' into feat/4.0.7
ZEJIA-LIU Oct 22, 2024
c7a352b
chore: 解决合并冲突
ZEJIA-LIU Oct 22, 2024
f00b14a
chore: 解决合并冲突
ZEJIA-LIU Oct 22, 2024
6e7a0ca
feat: 设置半编译预处理config
ZEJIA-LIU Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ rustflags = ["-C", "target-feature=+crt-static"]
# Alias to build actual SWC plugin binary for the specified target.
build-wasi = "build --target wasm32-wasi"
build-wasm32 = "build --target wasm32-unknown-unknown"
build-swc-plugins = "build-wasi --release -p swc_plugin_compile_mode -p swc_plugin_define_config"
test-swc-plugins = "test -p swc_plugin_compile_mode -p swc_plugin_define_config"
build-swc-plugins = "build-wasi --release -p swc_plugin_compile_mode -p swc_plugin_define_config -p swc_plugin_compile_mode_pre_process"
test-swc-plugins = "test -p swc_plugin_compile_mode -p swc_plugin_define_config -p swc_plugin_compile_mode_pre_process"
Empty file modified .husky/commit-msg
100644 → 100755
Empty file.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"./crates/taro_init/Cargo.toml",
"./crates/native_binding/Cargo.toml",
"./crates/swc_plugin_compile_mode/Cargo.toml",
"./crates/swc_plugin_define_config/Cargo.toml"
"./crates/swc_plugin_define_config/Cargo.toml",
"./crates/swc_plugin_compile_mode_pre_process/Cargo.toml"
],
"rust-analyzer.showUnlinkedFileNotification": false
}
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/native_binding/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/binding",
"version": "4.0.6",
"version": "4.0.7-alpha.2",
"description": "Node binding for taro",
"main": "binding.js",
"typings": "binding.d.ts",
Expand Down
6 changes: 0 additions & 6 deletions crates/swc_plugin_compile_mode/.editorconfig

This file was deleted.

102 changes: 52 additions & 50 deletions crates/swc_plugin_compile_mode/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,60 @@
use serde::Deserialize;
use std::collections::HashMap;
use swc_core::{
ecma::{
ast::Program,
visit::{as_folder, FoldWith, VisitMut},
},
plugin::{
plugin_transform,
proxies::TransformPluginProgramMetadata
}
ecma::{
ast::Program,
visit::{as_folder, FoldWith, VisitMut},
},
plugin::{plugin_transform, proxies::TransformPluginProgramMetadata},
};
use serde::{Deserialize};
use std::collections::HashMap;

mod utils;
mod transform;
mod transform_harmony;
#[cfg(test)]
mod tests;
mod transform;
mod transform_harmony;
mod utils;

struct SerdeDefault;
impl SerdeDefault {
fn platform_default () -> String {
String::from("WEAPP")
}
fn platform_default() -> String {
String::from("WEAPP")
}
fn is_use_xs_default() -> bool {
true
}
fn template_tag_default() -> String {
String::from("")
}
}

#[derive(Deserialize, Debug)]
#[derive(Deserialize, Debug)]
pub struct ComponentReplace {
pub current_init: String,
pub dependency_define: String,
pub current_init: String,
pub dependency_define: String,
}
#[derive(Deserialize, Debug)]
pub struct PluginConfig {
pub tmpl_prefix: String,
#[serde(default = "SerdeDefault::platform_default")]
pub platform: String,
#[serde(default)]
pub is_harmony: bool,
#[serde(default)]
pub components: HashMap<String, HashMap<String, String>>,
#[serde(default)]
pub adapter: HashMap<String, String>,
#[serde(default)]
pub support_events: Vec<String>,
#[serde(default)]
pub support_components: Vec<String>,
#[serde(default)]
pub event_adapter: HashMap<String, String>,
#[serde(default)]
pub component_replace: HashMap<String, ComponentReplace>,

pub tmpl_prefix: String,
#[serde(default = "SerdeDefault::platform_default")]
pub platform: String,
#[serde(default)]
pub is_harmony: bool,
#[serde(default)]
pub components: HashMap<String, HashMap<String, String>>,
#[serde(default)]
pub adapter: HashMap<String, String>,
#[serde(default)]
pub support_events: Vec<String>,
#[serde(default)]
pub support_components: Vec<String>,
#[serde(default)]
pub event_adapter: HashMap<String, String>,
#[serde(default)]
pub component_replace: HashMap<String, ComponentReplace>,
#[serde(default = "SerdeDefault::is_use_xs_default")]
pub is_use_xs: bool,
#[serde(default = "SerdeDefault::template_tag_default")]
pub template_tag: String,
}

/// An example plugin function with macro support.
Expand All @@ -68,19 +74,15 @@ pub struct PluginConfig {
/// Refer swc_plugin_macro to see how does it work internally.
#[plugin_transform]
pub fn process_transform(program: Program, metadata: TransformPluginProgramMetadata) -> Program {
let config = serde_json::from_str::<PluginConfig>(
&metadata
.get_transform_plugin_config()
.unwrap()
)
.unwrap();
let config =
serde_json::from_str::<PluginConfig>(&metadata.get_transform_plugin_config().unwrap()).unwrap();

// 如果 config 中的 is_harmony 字段为 true 则走 harmony_transform, 否则则走 transform
let visitor: Box<dyn VisitMut> = if config.is_harmony {
Box::new(transform_harmony::TransformVisitor::new(config))
} else {
Box::new(transform::TransformVisitor::new(config))
};
// 如果 config 中的 is_harmony 字段为 true 则走 harmony_transform, 否则则走 transform
let visitor: Box<dyn VisitMut> = if config.is_harmony {
Box::new(transform_harmony::TransformVisitor::new(config))
} else {
Box::new(transform::TransformVisitor::new(config))
};

program.fold_with(&mut as_folder(visitor))
program.fold_with(&mut as_folder(visitor))
}
26 changes: 13 additions & 13 deletions crates/swc_plugin_compile_mode/src/tests/attributes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{get_syntax_config, tr};
use swc_core::ecma::transforms::testing::test;
use super::{tr, get_syntax_config};

test!(
get_syntax_config(),
|_| tr(),
should_keep_static_attrs_only_in_templates,
r#"
get_syntax_config(),
|_| tr(),
should_keep_static_attrs_only_in_templates,
r#"
function Index () {
return (
<View compileMode>
Expand All @@ -17,10 +17,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_turn_dynamic_attrs,
r#"
get_syntax_config(),
|_| tr(),
should_turn_dynamic_attrs,
r#"
function Index () {
return (
<View compileMode>
Expand All @@ -37,10 +37,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_handle_events,
r#"
get_syntax_config(),
|_| tr(),
should_handle_events,
r#"
function Index () {
return (
<View compileMode>
Expand Down
42 changes: 21 additions & 21 deletions crates/swc_plugin_compile_mode/src/tests/children.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{get_syntax_config, tr};
use swc_core::ecma::transforms::testing::test;
use super::{tr, get_syntax_config};

test!(
get_syntax_config(),
|_| tr(),
should_support_render_fn,
r#"
get_syntax_config(),
|_| tr(),
should_support_render_fn,
r#"
function Index () {
return (
<View compileMode>
Expand All @@ -19,10 +19,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_support_fragment,
r#"
get_syntax_config(),
|_| tr(),
should_support_fragment,
r#"
function Index () {
return (
<View compileMode>
Expand Down Expand Up @@ -54,10 +54,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_support_context_api,
r#"
get_syntax_config(),
|_| tr(),
should_support_context_api,
r#"
function Index () {
return (
<View compileMode>
Expand All @@ -77,10 +77,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_render_react_component,
r#"
get_syntax_config(),
|_| tr(),
should_render_react_component,
r#"
function Index () {
return (
<View compileMode>
Expand All @@ -94,10 +94,10 @@ test!(
);

test!(
get_syntax_config(),
|_| tr(),
should_render_native_component,
r#"
get_syntax_config(),
|_| tr(),
should_render_native_component,
r#"
function Index () {
return (
<View compileMode>
Expand Down
68 changes: 42 additions & 26 deletions crates/swc_plugin_compile_mode/src/tests/condition.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{get_syntax_config, tr};
use swc_core::ecma::transforms::testing::test;
use super::{tr, get_syntax_config};

test!(
get_syntax_config(),
|_| tr(),
should_support_and_expr,
r#"
get_syntax_config(),
|_| tr(),
should_support_and_expr,
r#"
function Index () {
return (
<View compileMode>
Expand Down Expand Up @@ -34,26 +34,42 @@ test!(
}
"#
);

test!(
get_syntax_config(),
|_| tr(),
should_support_conditional_expr,
r#"
function Index () {
return (
<View compileMode>
{condition ? <View hoverClass={myClass}>{content}</View> : <Text selectable>hello</Text>}
{condition1 ? condition2 ? <View>{a}</View> : <Text>{b}</Text> : <View>{c}</View>}
{condition1 ? <View>{a}</View> : condition2 ? <View>{b}</View> : <Text>{c}</Text>}
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
{condition1 ? "someText" : 789}
{condition1 ? <View className={condition2 ? '' : ''} /> : <View/>}
{condition1 ? <View>{condition2 ? <View/> : <View/>}</View> : <View/>}
<View hoverClass={myClass}></View>
</View>
)
}
"#
get_syntax_config(),
|_| tr(),
should_support_conditional_expr,
r#"
function Index () {
return (
<View compileMode>
{condition ? <View hoverClass={myClass}>{content}</View> : <Text selectable>hello</Text>}
{condition1 ? condition2 ? <View>{a}</View> : <Text>{b}</Text> : <View>{c}</View>}
{condition1 ? <View>{a}</View> : condition2 ? <View>{b}</View> : <Text>{c}</Text>}
{condition1 ? <View>{a}</View> : (condition2 ? <View>{b}</View> : <Text>{c}</Text>)}
{condition1 ? condition2 && <View>{a}</View> : <View>{b}</View>}
{condition1 ? <View>{a}</View> : condition2 && <View>{b}</View>}
{condition1 ? "someText" : 789}
{condition1 ? <View className={condition2 ? '' : ''} /> : <View/>}
{condition1 ? <View>{condition2 ? <View/> : <View/>}</View> : <View/>}
<View hoverClass={myClass}></View>
</View>
)
}
"#
);

test!(
get_syntax_config(),
|_| tr(),
should_support_jsx_container_expr,
r#"
function Index () {
return (
<View compileMode>
{<View hoverClass={myClass}></View>}
</View>
)
}
"#
);
10 changes: 5 additions & 5 deletions crates/swc_plugin_compile_mode/src/tests/entry.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use super::{get_syntax_config, tr};
use swc_core::ecma::transforms::testing::test;
use super::{tr, get_syntax_config};

test!(
get_syntax_config(),
|_| tr(),
should_support_multi_compile_mode,
r#"
get_syntax_config(),
|_| tr(),
should_support_multi_compile_mode,
r#"
function Index () {
return (
<View>
Expand Down
Loading
Loading