Skip to content

Commit

Permalink
feat: 完善测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
ZEJIA-LIU committed Sep 24, 2024
1 parent 2bfeac8 commit 672dd3d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 38 deletions.
59 changes: 33 additions & 26 deletions crates/swc_plugin_compile_mode/src/tests/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,42 @@ test!(
}
"#
);

test!(
get_syntax_config(),
|_| tr(),
should_support_conditional_expr,
r#"
function Index () {
const [list, setList] = useState([
1,
2,
3,
4,
5
]);
return <View compileMode>
<View>
{
<View>
{
list.map((item) => {
return <View>
<Text>hello world{item}</Text>
</View>
})
}
<Text>hello world</Text>
</View>
}
</View>
</View>;
}
"#
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>
)
}
"#
);
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(i.cn[0].p1,\'none\')}}" wx:if="{{i.cn[0].compileIf}}">{{i.cn[0].cn[0].v}}</view><text selectable="true" wx:else>hello</text><block wx:if="{{i.cn[1].compileIf}}"><view wx:if="{{i.cn[1].cn[0].compileIf}}">{{i.cn[1].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[1].cn[0].cn[0].v}}</text></block><view wx:else>{{i.cn[1].cn[0].v}}</view><view wx:if="{{i.cn[2].compileIf}}">{{i.cn[2].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[2].cn[0].compileIf}}">{{i.cn[2].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[2].cn[0].cn[0].v}}</text></block><view wx:if="{{i.cn[3].compileIf}}">{{i.cn[3].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[3].cn[0].compileIf}}">{{i.cn[3].cn[0].cn[0].v}}</view><text wx:else>{{i.cn[3].cn[0].cn[0].v}}</text></block><block wx:if="{{i.cn[4].compileIf}}"><view wx:if="{{i.cn[4].cn[0].compileIf}}">{{i.cn[4].cn[0].cn[0].v}}</view></block><view wx:else>{{i.cn[4].cn[0].v}}</view><view wx:if="{{i.cn[5].compileIf}}">{{i.cn[5].cn[0].v}}</view><block wx:else><view wx:if="{{i.cn[5].cn[0].compileIf}}">{{i.cn[5].cn[0].cn[0].v}}</view></block><block wx:if="{{i.cn[6].compileIf}}">{{i.cn[6].cn[0].v}}</block><block wx:else>{{i.cn[6].cn[0].v}}</block><view class="{{i.cn[7].cl}}" wx:if="{{i.cn[7].compileIf}}"></view><view wx:else></view><view wx:if="{{i.cn[8].compileIf}}"><view wx:if="{{i.cn[8].cn[0].compileIf}}"></view><view wx:else></view></view><view wx:else></view><view hover-class="{{xs.b(i.cn[9].p1,\'none\')}}"></view></view></template>';
function Index() {
return <View compileMode="f0t0">
{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <Text></Text>}
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <Text>{b}</Text>}</block> : <View>{c}</View>}
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}
{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <View/>}</block> : <View>{b}</View>}
{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <View/>}</block>}
{condition1 ? <block compileIf={condition1}>{"someText"}</block> : <block>{789}</block>}
{condition1 ? <View className={condition2 ? '' : ''} compileIf={condition1}/> : <View/>}
{condition1 ? <View compileIf={condition1}>{condition2 ? <View compileIf={condition2}/> : <View/>}</View> : <View/>}
<View hoverClass={myClass}></View>
</View>;

{condition ? <View hoverClass={myClass} compileIf={condition}>{content}</View> : <Text></Text>}

{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <Text>{b}</Text>}</block> : <View>{c}</View>}

{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}

{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <Text>{c}</Text>}</block>}

{condition1 ? <block compileIf={condition1}>{condition2 ? <View compileIf={condition2}>{a}</View> : <View/>}</block> : <View>{b}</View>}

{condition1 ? <View compileIf={condition1}>{a}</View> : <block>{condition2 ? <View compileIf={condition2}>{b}</View> : <View/>}</block>}

{condition1 ? <block compileIf={condition1}>{"someText"}</block> : <block>{789}</block>}

{condition1 ? <View className={condition2 ? '' : ''} compileIf={condition1}/> : <View/>}

{condition1 ? <View compileIf={condition1}>{condition2 ? <View compileIf={condition2}/> : <View/>}</View> : <View/>}

<View hoverClass={myClass}></View>

</View>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const TARO_TEMPLATES_f0t0 = '<template name="tmpl_0_f0t0"><view><view hover-class="{{xs.b(i.cn[0].p1,\'none\')}}"></view></view></template>';
function Index() {
return <View compileMode="f0t0">

{<View hoverClass={myClass}></View>}

</View>;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default function Index() {
function renderB() {
function renderA() {
return <View> ComponentA </View>;
}
return <View compileMode>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default function Index() {
const list = [
1,
2,
3
];
function renderA(listA) {
return <View> {listA.map((item, index)=>{
return <View key={index}> {item} </View>;
})} </View>;
}
return <View compileMode>

{renderA(list.map((item)=>item + 1))}

</View>;
}

0 comments on commit 672dd3d

Please sign in to comment.