Skip to content

Commit d15403b

Browse files
authored
Merge branch 'main' into main
2 parents 2a9b48a + d936b77 commit d15403b

File tree

203 files changed

+31305
-27454
lines changed

Some content is hidden

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

203 files changed

+31305
-27454
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/build-rust-binding.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: Setup pnpm
4949
uses: pnpm/[email protected]
5050
with:
51-
version: 8
51+
version: 9
5252
- name: Setup Node.js ${{ matrix.node-version }}
5353
uses: actions/setup-node@v4
5454
if: ${{ !matrix.settings.docker }}

.github/workflows/nodejs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
- name: Setup pnpm
6565
uses: pnpm/[email protected]
6666
with:
67-
version: 8
67+
version: 9
6868
- name: Setup Node.js ${{ matrix.node-version }}
6969
uses: actions/setup-node@v4
7070
with:

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Setup pnpm
8989
uses: pnpm/[email protected]
9090
with:
91-
version: 8
91+
version: 9
9292
- name: Setup Node 18
9393
uses: actions/setup-node@v4
9494
with:

.github/workflows/sync-components-types.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: install
3737
uses: pnpm/[email protected]
3838
with:
39-
version: 8
39+
version: 9
4040
run_install: |
4141
- recursive: true
4242
args: [--frozen-lockfile, --strict-peer-dependencies]

.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/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.6",
3+
"version": "4.0.7",
44
"description": "Node binding for taro",
55
"main": "binding.js",
66
"typings": "binding.d.ts",

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

+13-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,10 +37,10 @@ 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>

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)