Skip to content

Commit

Permalink
fix(compilerMode): 修复编译模式没有正确处理动态 id 属性的问题 (#15583)
Browse files Browse the repository at this point in the history
* fix(compilerMode): 修复编译模式没有正确处理动态 id 属性的问题

* fix: ci

---------

Co-authored-by: ZEJIA LIU <[email protected]>
  • Loading branch information
Chen-jj and ZEJIA-LIU committed Apr 25, 2024
1 parent a685aa1 commit 61beec8
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion crates/swc_plugin_compile_mode/src/tests/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test!(
<View class={myClass}>
<View style={myStyle} customProp={myCustomProp}></View>
<View hoverStayTime={myTime}>
<View hoverClass={myHoverClass}></View>
<View hoverClass={myHoverClass} id={myId}></View>
</View>
</View>
</View>
Expand Down
4 changes: 3 additions & 1 deletion crates/swc_plugin_compile_mode/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,9 @@ impl TransformVisitor {
}

// 小程序组件标准属性 -> 取 @tarojs/shared 传递过来的属性值;非标准属性 -> 取属性名
let value: &str = attrs_map.get(&miniapp_attr_name).unwrap_or(&jsx_attr_name);
let value: &str = attrs_map.get(&miniapp_attr_name)
.map(|res| res.as_str())
.unwrap_or(if miniapp_attr_name == "id" { "uid" } else { &jsx_attr_name });
// 按当前节点在节点树中的位置换算路径
node_path.push('.');
let value = if value.contains(TMPL_DATA_ROOT) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view bindtap="eh" data-sid="{{i.cn[0].sid}}" id="{{i.cn[0].sid}}"></view><view bindanimationstart="eh" data-sid="{{i.cn[1].sid}}" id="{{i.cn[1].id}}"></view><image bindload="eh" data-sid="{{i.cn[2].sid}}" id="myImg"></image></view></template>';
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view bindtap="eh" data-sid="{{i.cn[0].sid}}" id="{{i.cn[0].sid}}"></view><view bindanimationstart="eh" data-sid="{{i.cn[1].sid}}" id="{{i.cn[1].uid}}"></view><image bindload="eh" data-sid="{{i.cn[2].sid}}" id="myImg"></image></view></template>';
function Index() {
return <View compileMode="f0t0">
<View onClick={handleViewClick}></View>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view class="{{i.cn[0].cl}}"><view custom-prop="{{i.cn[0].cn[0].customProp}}" style="{{i.cn[0].cn[0].st}}"></view><view hover-stay-time="{{xs.b(i.cn[0].cn[1].p3,400)}}"><view hover-class="{{xs.b(i.cn[0].cn[1].cn[0].p1,\'none\')}}"></view></view></view></view></template>';
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view class="{{i.cn[0].cl}}"><view custom-prop="{{i.cn[0].cn[0].customProp}}" style="{{i.cn[0].cn[0].st}}"></view><view hover-stay-time="{{xs.b(i.cn[0].cn[1].p3,400)}}"><view hover-class="{{xs.b(i.cn[0].cn[1].cn[0].p1,\'none\')}}" id="{{i.cn[0].cn[1].cn[0].uid}}"></view></view></view></view></template>';
function Index() {
return <View compileMode="f0t0">
<View class={myClass}>
<View style={myStyle} customProp={myCustomProp}></View>
<View hoverStayTime={myTime}>
<View hoverClass={myHoverClass}></View>
<View hoverClass={myHoverClass} id={myId}></View>
</View>
</View>
</View>;
Expand Down
Binary file modified packages/taro-helper/swc-backup/swc_plugin_compile_mode.wasm
Binary file not shown.
Binary file modified packages/taro-helper/swc-backup/swc_plugin_define_config.wasm
Binary file not shown.

0 comments on commit 61beec8

Please sign in to comment.