Skip to content

Commit

Permalink
fix(transformer): 三元表达式其中有一个值为函数解析错误
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Oct 18, 2018
1 parent 8d32a34 commit fde2474
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 1 addition & 3 deletions packages/taro-transformer-wx/__tests__/control-flow.spec.ts
Expand Up @@ -372,16 +372,14 @@ describe('三元表达式', () => {
`)
})

console.log(code)

expect(template).toMatch(prettyPrint(`
<block>
<view>
<block>
<block wx:if=\"{{title}}\">
<text>yes</text>
</block>
<block wx:else>{{test}}</block>
<block wx:else>{{anonymousState__temp}}</block>
</block>
</view>
</block>
Expand Down
10 changes: 4 additions & 6 deletions packages/taro-transformer-wx/src/render.ts
Expand Up @@ -254,15 +254,13 @@ export class RenderParser {
)
setTemplate(name, jsxElementPath, this.templates)
}
} else if (
(t.isJSXElement(consequent) && t.isCallExpression(alternate))
// ||
// (t.isJSXElement(alternate) && t.isCallExpression(consequent))
) {
} else if (t.isJSXElement(consequent) && t.isCallExpression(alternate)) {
const id = generateAnonymousState(this.renderScope!, parentPath.get('alternate') as any, this.referencedIdentifiers, true)
// block.children = [t.jSXExpressionContainer(alternate)]
parentPath.get('alternate').replaceWith(id)
//
} else if (t.isJSXElement(alternate) && t.isCallExpression(consequent)) {
const id = generateAnonymousState(this.renderScope!, parentPath.get('consequent') as any, this.referencedIdentifiers, true)
parentPath.get('consequent').replaceWith(id)
} else {
block.children = [t.jSXExpressionContainer(consequent)]
newJSXIfAttr(block, test)
Expand Down

0 comments on commit fde2474

Please sign in to comment.