Skip to content

Commit

Permalink
fix: 更新 axml
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan committed Dec 18, 2023
1 parent 080bb5d commit e2ba803
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiled/alipay/src/Result/index.axml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
style="font-size: 64px" />
</view>
<image-icon
a:if="{{ image }}"
a:elif="{{ image }}"
className="ant-result-image"
image="{{ image }}" />
<block a:else />
Expand Down
2 changes: 1 addition & 1 deletion compiled/alipay/src/Tabs/index.axml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</view>
</view>
<view
a:if="{{ type === 'capsule' }}"
a:elif="{{ type === 'capsule' }}"
class="ant-tabs-bar-item ant-tabs-bar-capsule {{ tabClassName ? tabClassName : '' }} {{ mixin.value === index && !item.disabled ? 'ant-tabs-bar-active' : '' }} {{ item.disabled ? 'ant-tabs-bar-disabled' : '' }} {{ mixin.value === index && !item.disabled && tabActiveClassName ? tabActiveClassName : '' }}"
onTap="onChange"
data-index="{{ index }}">
Expand Down
2 changes: 1 addition & 1 deletion compiled/wechat/src/Result/index.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
style="font-size: 64px" />
</view>
<image-icon
wx:if="{{ image }}"
wx:elif="{{ image }}"
className="ant-result-image"
image="{{ image }}" />
<block wx:else />
Expand Down
4 changes: 4 additions & 0 deletions scripts/tsxml/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ITransformContext<T extends types.Node = types.Node> {
h(tagName: string, props: unknown, ...children: unknown[]): unknown;
if(): string;
else(): string;
elseif(): string;
for(): string;
forItem(): string;
forKey(): string;
Expand Down Expand Up @@ -156,6 +157,9 @@ export class TransformContext<T extends types.Node = types.Node>
else(): string {
return this.config.else;
}
elseif(): string {
return this.config.elseif;
}
forIndex(): string {
return this.config.forIndex;
}
Expand Down
1 change: 1 addition & 0 deletions scripts/tsxml/fixtures/if.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default ({ a, b }: TSXMLProps<Props>) => (
{!!a && <Text>a</Text>}
{!!a && b && <Text> a & b</Text>}
{a ? <Text>a</Text> : <Text>!a</Text>}
{a ? <Text>1</Text> : b ? <Text>2</Text> : <Text>3</Text>}
{<Text class={a ? '1' : '2'}></Text>}
<Text class={`1 ${a ? '1' + '2' : 2} 2`}></Text>
</View>
Expand Down
6 changes: 6 additions & 0 deletions scripts/tsxml/fixtures/snapshot/if.axml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<text a:if="{{ a }}">a</text>
<!-- display: inline -->
<text a:else>!a</text>
<!-- display: inline -->
<text a:if="{{ a }}">1</text>
<!-- display: inline -->
<text a:elif="{{ b }}">2</text>
<!-- display: inline -->
<text a:else>3</text>
<text class="{{ a ? '1' : '2' }}" />
<text class="1 {{ a ? '1' + '2' : 2 }} 2" />
</view>
6 changes: 6 additions & 0 deletions scripts/tsxml/fixtures/snapshot/if.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
<text wx:if="{{ a }}">a</text>
<!-- display: inline -->
<text wx:else>!a</text>
<!-- display: inline -->
<text wx:if="{{ a }}">1</text>
<!-- display: inline -->
<text wx:elif="{{ b }}">2</text>
<!-- display: inline -->
<text wx:else>3</text>
<text class="{{ a ? '1' : '2' }}" />
<text class="1 {{ a ? '1' + '2' : 2 }} 2" />
</view>
5 changes: 4 additions & 1 deletion scripts/tsxml/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ it('index', async () => {
await textTsXml('index');
});

it('测试解析为 axml', async () => {
it('if', async () => {
await textTsXml('if');
});

it('测试解析为 axml', async () => {
await textTsXml('sjs');
await textTsXml('style');
});
Expand Down
5 changes: 4 additions & 1 deletion scripts/tsxml/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,13 @@ export function transformJSXElement(ctx: ITransformContext) {
return ctx.toAxmlExpression();
}
case 'ConditionalExpression': {
const isElse = ctx.extraAttr?.[ctx.else()];
return [
transformJSXElement(
ctx.extends(ctx.node.consequent, {
[ctx.if()]: ctx.extends(ctx.node.test).toAxmlExpression(),
[isElse ? ctx.elseif() : ctx.if()]: ctx
.extends(ctx.node.test)
.toAxmlExpression(),
})
),
transformJSXElement(
Expand Down
3 changes: 3 additions & 0 deletions scripts/tsxml/platform.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const alipay: PlatformConfig = {
if: 'a:if',
for: 'a:for',
elseif: 'a:elif',
forItem: 'a:for-item',
forIndex: 'a:for-index',
forKey: 'a:key',
Expand All @@ -20,6 +21,7 @@ export const alipay: PlatformConfig = {
export const wechat: PlatformConfig = {
if: 'wx:if',
for: 'wx:for',
elseif: 'wx:elif',
else: 'wx:else',
forItem: 'wx:for-item',
forIndex: 'wx:for-index',
Expand Down Expand Up @@ -100,6 +102,7 @@ export interface PlatformConfig {
for: string;
if: string;
else: string;
elseif: string;
forItem: string;
forIndex: string;
forKey: string;
Expand Down
5 changes: 2 additions & 3 deletions src/Tabs/index.axml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default (
tabsBarClassName ? tabsBarClassName : ''
}`}
>
{type === 'basic' && (
{type === 'basic' ? (
<View
class={`ant-tabs-bar-item ant-tabs-bar-basic ${
tabClassName ? tabClassName : ''
Expand Down Expand Up @@ -81,8 +81,7 @@ export default (
{/* #endif */}
</View>
</View>
)}
{type === 'capsule' ? (
) : type === 'capsule' ? (
<View
class={`ant-tabs-bar-item ant-tabs-bar-capsule ${
tabClassName ? tabClassName : ''
Expand Down

0 comments on commit e2ba803

Please sign in to comment.