Skip to content

Commit 8c7da05

Browse files
authored
Merge pull request #5 from mpx-ecology/feat/supportWxCondition
feat: support wx condition directive
2 parents 55154a0 + e70fb3d commit 8c7da05

File tree

3 files changed

+268
-118
lines changed

3 files changed

+268
-118
lines changed

inspect-extension/components/composition/wxIf.mpx

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
<template>
2-
<view class="list">
3-
<view wx:if="{{ shouldShow > 100}}">
4-
Case1: {{ shouldShow }}
2+
<view>
3+
<!-- Case1: Type Narrowing 类型收窄 -->
4+
<view wx:if="{{ typeof msg === 'string'}}">
5+
msg should be string: {{ msg }}
56
</view>
6-
<view wx:elif="{{ shouldShow > 10}}">
7-
Case2: {{ shouldShow }}
7+
<view wx:elif="{{ typeof msg === 'number' }}">
8+
msg should be number: {{ msg }}
89
</view>
910
<view wx:else>
10-
Case3: {{ shouldShow }}
11+
msg should be undefined: {{ msg }}
1112
</view>
13+
14+
<!-- Case2: Type Narrowing for undefined -->
15+
<view wx:if="{{ status }}">
16+
{{ status.message }}
17+
</view>
18+
19+
<!-- Case3: Type Narrowing -->
20+
<view wx:if="{{ typeof foo === 'string' }}">
21+
{{ foo }}
22+
</view>
23+
24+
<!-- Case4: 表达式带空格 -->
25+
<view wx:if=" {{ status?.message && msg }}"></view>
1226
</view>
1327
</template>
1428

1529
<script setup lang="ts">
1630
import { ref } from "@mpxjs/core"
17-
const shouldShow = ref(0)
31+
32+
let msg = ref<string | number>()
33+
let status: { message: string } | undefined;
34+
let foo: any
1835

1936
defineExpose({
20-
shouldShow,
37+
msg,
38+
status,
39+
foo
2140
})
2241
</script>
23-
24-
<style lang="stylus">
25-
.list
26-
background-color red
27-
</style>

packages/language-core/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,4 +215,8 @@ declare module '@vue/compiler-dom' {
215215
defaultValue?: boolean
216216
defaultIndex?: boolean
217217
}
218+
219+
export interface IfBranchNode {
220+
mpxCondition?: 'if' | 'elif' | 'else'
221+
}
218222
}

0 commit comments

Comments
 (0)