Skip to content

Commit

Permalink
Merge branch 'main' into fix/15114
Browse files Browse the repository at this point in the history
  • Loading branch information
ZakaryCode authored Jan 20, 2024
2 parents 72e4a72 + bcf77a0 commit 0c60a8e
Show file tree
Hide file tree
Showing 109 changed files with 368 additions and 172 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/sync-components-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ jobs:
cp -r .taro-docs/packages/taro-components/types/* packages/taro-components/types
rm -rf .taro-docs
# Bootstrap project
- name: Cache pnpm modules
uses: actions/cache@v3
with:
path: node_modules
path: ~/.pnpm-store
key: ${{ runner.os }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-
Expand All @@ -40,9 +41,16 @@ jobs:
- recursive: true
args: [--frozen-lockfile, --strict-peer-dependencies]
- args: [--filter @tarojs/components, -D, miniapp-types@latest]
# Note: 当前同步脚本使用 ts-node 与 node20 存在兼容问题,修复后解除版本限制
- name: Setup Node 16
uses: actions/setup-node@v4
with:
node-version: 16
cache: 'pnpm'
registry-url: 'https://registry.npmjs.org' # Don't touch!

- name: build
run: pnpm build
run: pnpm --filter=@tarojs/components... build

- name: execute sync script
run: |
Expand Down
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": "3.6.22",
"version": "3.6.23",
"description": "Node binding for taro",
"main": "binding.js",
"typings": "binding.d.ts",
Expand Down
13 changes: 10 additions & 3 deletions crates/swc_plugin_compile_mode/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ use swc_core::{
proxies::TransformPluginProgramMetadata
}
};
use serde::{Serialize, Deserialize};
use serde::{Deserialize};
use std::collections::HashMap;
use core::fmt::Debug;

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

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

#[derive(Serialize, Deserialize, Debug)]
#[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)]
Expand Down
73 changes: 73 additions & 0 deletions crates/swc_plugin_compile_mode/src/tests/alipay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
use swc_core::ecma::{
parser,
visit::{as_folder, Fold},
};
use crate::{
PluginConfig,
transform::*,
};

fn tr () -> impl Fold {
let config = serde_json::from_str::<PluginConfig>(
r#"
{
"tmpl_prefix": "f0",
"platform": "ALIPAY",
"components": {
"view": {
"hover-class": "xs.b(i.p3,'none')",
"hover-stop-propagation": "xs.b(i.p6,!1)",
"hover-start-time": "xs.b(i.p4,50)",
"hover-stay-time": "xs.b(i.p5,400)",
"onTouchStart": "eh",
"onTouchMove": "eh",
"onTouchEnd": "eh",
"onTouchCancel": "eh",
"onLongTap": "eh",
"animation": "i.p0",
"onAnimationStart": "eh",
"onAnimationIteration": "eh",
"onAnimationEnd": "eh",
"onTransitionEnd": "eh",
"disable-scroll": "xs.b(i.p1,false)",
"hidden": "xs.b(i.p2,false)",
"onAppear": "eh",
"onDisappear": "eh",
"onFirstAppear": "eh",
"style": "i.st",
"class": "i.cl",
"onTap": "eh"
}
},
"adapter": {
"if": "a:if",
"else": "a:else",
"elseif": "a:elif",
"for": "a:for",
"forItem": "a:for-item",
"forIndex": "a:for-index",
"key": "a:key",
"xs": "sjs",
"type": "alipay"
}
}"#
)
.unwrap();
let visitor = TransformVisitor::new(config);
as_folder(visitor)
}

test!(
get_syntax_config(),
|_| tr(),
should_event_name_in_camelcase,
r#"
function Index () {
return (
<View compileMode>
<View onClick={cb} onAnimationStart={cb}></View>
</View>
)
}
"#
);
2 changes: 1 addition & 1 deletion crates/swc_plugin_compile_mode/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl TransformVisitor {
}

let miniapp_attr_name = utils::convert_jsx_attr_key(&jsx_attr_name, &self.config.adapter);
let event_name = utils::identify_jsx_event_key(&jsx_attr_name);
let event_name = utils::identify_jsx_event_key(&jsx_attr_name, &self.config.platform);
let is_event = event_name.is_some();
match &jsx_attr.value {
Some(jsx_attr_value) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_plugin_compile_mode/src/transform_harmony.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl TransformVisitor {
if let JSXAttrName::Ident(..) = &jsx_attr.name {
if let JSXAttrName::Ident(Ident { sym: name, .. }) = &jsx_attr.name {
let jsx_attr_name = name.to_string();
let event_name = utils::identify_jsx_event_key(&jsx_attr_name);
let event_name = utils::identify_jsx_event_key(&jsx_attr_name, &self.config.platform);
let is_event = event_name.is_some();
let is_condition = jsx_attr_name == COMPILE_IF;

Expand Down
16 changes: 14 additions & 2 deletions crates/swc_plugin_compile_mode/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,27 @@ pub fn check_is_event_attr (val: &str) -> bool {
val.starts_with("on") && val.chars().nth(2).is_some_and(|x| x.is_uppercase())
}

pub fn identify_jsx_event_key (val: &str) -> Option<String> {
pub fn identify_jsx_event_key (val: &str, platform: &str) -> Option<String> {
if check_is_event_attr(val) {
let event_name = val.get(2..).unwrap().to_lowercase();
let event_name = if event_name == "click" {
"tap"
} else {
&event_name
};
Some(format!("bind{}", event_name))
let event_binding_name = match platform {
"ALIPAY" => {
if event_name == "tap" {
String::from("onTap")
} else {
String::from(val)
}
},
_ => {
format!("bind{}", event_name)
}
};
Some(event_binding_name)
} else {
return None;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view onClick="eh" onAnimationStart="eh"></view></view></template>';
function Index() {
return <View>
<View onClick={cb} onAnimationStart={cb}></View>
</View>;
}
2 changes: 1 addition & 1 deletion npm/darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-arm64",
"description": "Native binding for taro",
"version": "3.6.22",
"version": "3.6.23",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-darwin-x64",
"description": "Native binding for taro",
"version": "3.6.22",
"version": "3.6.23",
"os": [
"darwin"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/linux-x64-gnu/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-linux-x64-gnu",
"description": "Native binding for taro",
"version": "3.6.22",
"version": "3.6.23",
"os": [
"linux"
],
Expand Down
2 changes: 1 addition & 1 deletion npm/win32-x64-msvc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@tarojs/binding-win32-x64-msvc",
"description": "Native binding for taro",
"version": "3.6.22",
"version": "3.6.23",
"os": [
"win32"
],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taro",
"version": "3.6.22",
"version": "3.6.23",
"description": "开放式跨端跨框架开发解决方案",
"homepage": "https://github.com/NervJS/taro#readme",
"author": "O2Team",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-react-jsx-to-rn-stylesheet",
"version": "3.6.22",
"version": "3.6.23",
"description": "Transform stylesheet selector to style in JSX Elements.",
"license": "MIT",
"main": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-transform-taroapi/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-plugin-transform-taroapi",
"version": "3.6.22",
"version": "3.6.23",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-taro",
"version": "3.6.22",
"version": "3.6.23",
"description": "Taro babel preset",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/create-app",
"version": "3.6.22",
"version": "3.6.23",
"description": "create taro app with one command",
"author": "VincentW <Vincent.Mr.W@gmail.com>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/create-app#readme",
Expand Down
2 changes: 1 addition & 1 deletion packages/css-to-react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "taro-css-to-react-native",
"description": "Convert CSS text to a React Native stylesheet object",
"version": "3.6.22",
"version": "3.6.23",
"main": "dist/index.js",
"license": "MIT",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config-taro/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-taro",
"version": "3.6.22",
"version": "3.6.23",
"description": "Taro specific linting rules for ESLint",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-html-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-html-transform",
"version": "3.6.22",
"version": "3.6.23",
"description": "transform html tag name selector",
"main": "index.js",
"author": "drchan",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-plugin-constparse/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-plugin-constparse",
"version": "3.6.22",
"version": "3.6.23",
"description": "parse constants defined in config",
"main": "index.js",
"author": "Simba",
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-pxtransform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-pxtransform",
"version": "3.6.22",
"version": "3.6.23",
"description": "PostCSS plugin px 转小程序 rpx及h5 rem 单位",
"main": "index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/postcss-unit-transform/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postcss-taro-unit-transform",
"version": "3.6.22",
"version": "3.6.23",
"description": "小程序单位转换",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/shared",
"version": "3.6.22",
"version": "3.6.23",
"description": "Taro utils internal use.",
"author": "yuche <i@yuche.me>",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/shared#readme",
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class BaseTemplate {
protected modifyTemplateResult?: (res: string, nodeName: string, level: number, children: string) => string
protected modifyThirdPartyLoopBody?: (child: string, nodeName: string) => string
public supportXS = false
public isXMLSupportRecursiveReference = true
public Adapter = weixinAdapter
/** 组件列表 */
public internalComponents = internalComponents
Expand Down Expand Up @@ -490,7 +491,7 @@ export class BaseTemplate {
return `{${value}}`
}

protected buildXsTemplate () {
public buildXsTemplate (_filePath?: string) {
return ''
}

Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-config-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stylelint-config-taro-rn",
"version": "3.6.22",
"version": "3.6.23",
"description": "Shareable stylelint config for React Native CSS modules",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/stylelint-taro-rn/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "stylelint-taro-rn",
"description": "A collection of React Native specific rules for stylelint",
"version": "3.6.22",
"version": "3.6.23",
"main": "dist/index.js",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-alipay/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tarojs/plugin-platform-alipay",
"version": "3.6.22",
"version": "3.6.23",
"description": "支付宝小程序平台插件",
"author": "Chen-jj",
"homepage": "https://github.com/nervjs/taro/tree/master/packages/taro-alipay#readme",
Expand Down
5 changes: 3 additions & 2 deletions packages/taro-alipay/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { RecursiveTemplate } from '@tarojs/shared/dist/template'
export class Template extends RecursiveTemplate {
exportExpr = 'export default'
supportXS = true
isXMLSupportRecursiveReference = false
Adapter = {
if: 'a:if',
else: 'a:else',
Expand All @@ -18,8 +19,8 @@ export class Template extends RecursiveTemplate {

transferComponents: Record<string, Record<string, string>> = {}

buildXsTemplate () {
return '<import-sjs name="xs" from="./utils.sjs" />'
buildXsTemplate (filePath = './utils') {
return `<import-sjs name="xs" from="${filePath}.sjs" />`
}

replacePropName (name, value, compName, componentAlias) {
Expand Down
Loading

0 comments on commit 0c60a8e

Please sign in to comment.