Skip to content

Commit

Permalink
fix(transformer): 循环中使用对象展开符报错,close #3547
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jun 26, 2019
1 parent b69232d commit 527ae89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ class Transformer {
}

if (id.name.endsWith(CONTEXT_PROVIDER)) {
const valueAttr = path.node.openingElement.attributes.find(a => a.name.name === 'value')
const valueAttr = path.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === 'value')
const contextName = id.name.slice(0, id.name.length - CONTEXT_PROVIDER.length)
if (valueAttr) {
if (t.isJSXElement(valueAttr.value)) {
Expand Down
14 changes: 7 additions & 7 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ export class RenderParser {
}
}
const block = buildBlockElement()
const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => a.name.name === Adapter.if)
const hasIfAttr = jsxElementPath.node.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const needWrapper = Adapters.swan === Adapter.type && hasIfAttr
if (needWrapper) {
block.children = [jsxElementPath.node]
Expand Down Expand Up @@ -872,7 +872,7 @@ export class RenderParser {
newJSXIfAttr(jsxElementPath.node, test, jsxElementPath)
}
}
const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test })) {
const newBlock = buildBlockElement()
newBlock.children = [block, jsxElementPath.node]
Expand All @@ -883,7 +883,7 @@ export class RenderParser {
let hasNest = false
this.handleNestedIfStatement(block, jsxElementPath.node, parentIfStatement.node.test, hasNest, isElse || !!ifStatement.findParent(p => p.node === parentIfStatement.node.alternate))
if (!hasNest && parentIfStatement.get('alternate') !== ifStatement) {
const ifAttr = block.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifAttr = block.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
if (ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: parentIfStatement.node.test })) {
const newBlock = buildBlockElement()
block.children.push(jsxElementPath.node)
Expand Down Expand Up @@ -922,8 +922,8 @@ export class RenderParser {
if (!t.isJSXElement(child)) {
continue
}
const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif)
const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif)
if (
(ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test }))
||
Expand All @@ -946,8 +946,8 @@ export class RenderParser {
if (!t.isJSXElement(child)) {
continue
}
const ifAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => a.name.name === Adapter.elseif)
const ifAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.if)
const ifElseAttr = child.openingElement.attributes.find(a => t.isJSXIdentifier(a.name) && a.name.name === Adapter.elseif)
if (
(ifAttr && t.isJSXExpressionContainer(ifAttr.value, { expression: test }))
||
Expand Down

0 comments on commit 527ae89

Please sign in to comment.