Skip to content

Commit e56ba47

Browse files
committed
fix: 修复输出rn wx:elif 静态为true 时构建报错
1 parent 33fbd0b commit e56ba47

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

packages/webpack-plugin/lib/template-compiler/compiler.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,6 @@ function postProcessIfReact (el) {
22472247
delete el.elseif
22482248
el._if = true
22492249
addIfCondition(ifNode, {
2250-
exp: el.elseif.exp,
22512250
block: el
22522251
})
22532252
removeNode(el, true)

packages/webpack-plugin/test/platform/common/wx-if.spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,34 @@ describe('template if should transform correct', function () {
7070
'createElement(getComponent("mpx-text"), null,"1"))')
7171
})
7272

73+
it('should keep node when condition is false', function () {
74+
const input = '<view><text wx:if="{{false}}">1</text></view>'
75+
const wxOutput = compileTemplateToWx(input)
76+
expect(wxOutput).toBe('<view></view>')
77+
78+
const iosOutput = compileTemplateToIos(input)
79+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null)')
80+
})
81+
82+
it('should keep node when wx:elif condition is true', function () {
83+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{true}}">2</text></view>'
84+
const wxOutput = compileTemplateToWx(input)
85+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text><text wx:else>2</text></view>')
86+
87+
const iosOutput = compileTemplateToIos(input)
88+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?' +
89+
'createElement(getComponent("mpx-text"), null,"1"):createElement(getComponent("mpx-text"), null,"2"))')
90+
})
91+
92+
it('should remove node when wx:elif condition is false', function () {
93+
const input = '<view><text wx:if="{{condition}}">1</text><text wx:elif="{{false}}">2</text></view>'
94+
const wxOutput = compileTemplateToWx(input)
95+
expect(wxOutput).toBe('<view><text wx:if="{{condition}}">1</text></view>')
96+
97+
const iosOutput = compileTemplateToIos(input)
98+
expect(iosOutput).toBe('createElement(getComponent("mpx-view"), null,(condition)?createElement(getComponent("mpx-text"), null,"1"):null)')
99+
})
100+
73101
it('should handle __mpx_mode__ in condition', function () {
74102
const input = `
75103
<view>

0 commit comments

Comments
 (0)