Skip to content

Commit

Permalink
fix(transformer): 单层 if 表达式被当成嵌套 if 表达式解析
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Mar 6, 2019
1 parent f40d395 commit d8a9cee
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { transformOptions, buildBabelTransformOptions } from './options'
import generate from 'babel-generator'
import { LoopRef } from './interface'
const template = require('babel-template')
const gen = generate

type ClassMethodsMap = Map<string, NodePath<t.ClassMethod | t.ClassProperty>>

Expand Down Expand Up @@ -737,9 +738,8 @@ export class RenderParser {
const newBlock = buildBlockElement()
newBlock.children = [block, jsxElementPath.node]
block = newBlock
} else if (parentIfStatement) {
let hasNestIfStatement = false
this.handleNestedIfStatement(block, jsxElementPath.node, parentIfStatement.node.test, hasNestIfStatement)
} else if (parentIfStatement && parentIfStatement.get('alternate') !== ifStatement) {
this.handleNestedIfStatement(block, jsxElementPath.node, parentIfStatement.node.test)
} else {
block.children.push(jsxElementPath.node)
}
Expand All @@ -761,7 +761,7 @@ export class RenderParser {
}
}

handleNestedIfStatement = (block: t.JSXElement, jsx: t.JSXElement, test: t.Expression, hasNestIfStatement: boolean) => {
handleNestedIfStatement = (block: t.JSXElement, jsx: t.JSXElement, test: t.Expression) => {
if (this.isEmptyBlock(block)) {
return
}
Expand All @@ -778,10 +778,9 @@ export class RenderParser {
(ifElseAttr && t.isJSXExpressionContainer(ifElseAttr.value, { expression: test }))
) {
child.children.push(jsx)
hasNestIfStatement = true
break
} else {
this.handleNestedIfStatement(child, jsx, test, hasNestIfStatement)
this.handleNestedIfStatement(child, jsx, test)
}
}
}
Expand Down

0 comments on commit d8a9cee

Please sign in to comment.