Skip to content

Commit

Permalink
fix(taroize):支持wx:elif的mustache语法错误提示,close #4188 (#4235)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiyu8 authored and yuche committed Aug 26, 2019
1 parent f4c611c commit d473ddc
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions packages/taroize/src/wxml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,24 +556,29 @@ function handleConditions (conditions: Condition[]) {
const lastLength = conditions.length - 1
const lastCon = conditions[lastLength]
let lastAlternate: t.Expression = cloneDeep(lastCon.path.node)
if (lastCon.condition === WX_ELSE_IF) {
lastAlternate = t.logicalExpression(
'&&',
lastCon.tester.expression,
lastAlternate
)
}
const node = conditions
.slice(0, lastLength)
.reduceRight((acc: t.Expression, condition) => {
return t.conditionalExpression(
condition.tester.expression,
cloneDeep(condition.path.node),
acc
try {
if (lastCon.condition === WX_ELSE_IF) {
lastAlternate = t.logicalExpression(
'&&',
lastCon.tester.expression,
lastAlternate
)
}, lastAlternate)
conditions[0].path.replaceWith(t.jSXExpressionContainer(node))
conditions.slice(1).forEach(c => c.path.remove())
}
const node = conditions
.slice(0, lastLength)
.reduceRight((acc: t.Expression, condition) => {
return t.conditionalExpression(
condition.tester.expression,
cloneDeep(condition.path.node),
acc
)
}, lastAlternate)
conditions[0].path.replaceWith(t.jSXExpressionContainer(node))
conditions.slice(1).forEach(c => c.path.remove())
} catch(error) {
// tslint:disable-next-line
console.error('wx:elif 的值需要用双括号 `{{}}` 包裹它的值')
}
}
}

Expand Down

0 comments on commit d473ddc

Please sign in to comment.