Skip to content

Commit

Permalink
fix(transformer): 多层循环的 callee 如果是循环体内的变量不用变为成员表达式, #912
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Oct 23, 2018
1 parent 9e66495 commit 0656199
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,14 @@ export class RenderParser {
if (replacements.has(parent) || (this.renderScope.hasOwnBinding(name) && this.loopCalleeId.has(path.node))) {
return
}

if (stateToBeAssign.has(name) && path.isReferencedIdentifier()) {
if (t.isMemberExpression(parent) && t.isIdentifier(parent.property, { name: 'map' })) {
const grandParentPath = path.parentPath.parentPath
if (grandParentPath.isCallExpression() && this.loopComponents.has(grandParentPath)) {
return
}
}
const replacement = t.memberExpression(
t.identifier(item.name),
path.node
Expand Down Expand Up @@ -1105,7 +1112,7 @@ export class RenderParser {
}
})
} else {
throw codeFrameError(object.loc, '请简化该表达式为标识符或成员表达式')
throw codeFrameError(object.loc, '多层循环中循环的数组只能是一个变量或成员表达式')
}
}
}
Expand Down Expand Up @@ -1331,18 +1338,20 @@ export class RenderParser {
this.renderPath.node.body.body.unshift(
template(`this.__state = arguments[0] || this.state || {};`)(),
template(`this.__props = arguments[1] || this.props || {};`)(),
this.usedThisProperties.size ? t.variableDeclaration(
'const',
[
t.variableDeclarator(
t.objectPattern(Array.from(this.usedThisProperties).map(p => t.objectProperty(
t.identifier(p),
t.identifier(p)
) as any)),
t.thisExpression()
)
]
) : t.emptyStatement()
this.usedThisProperties.size
? t.variableDeclaration(
'const',
[
t.variableDeclarator(
t.objectPattern(Array.from(this.usedThisProperties).map(p => t.objectProperty(
t.identifier(p),
t.identifier(p)
) as any)),
t.thisExpression()
)
]
)
: t.emptyStatement()
)

if (t.isIdentifier(this.renderPath.node.key)) {
Expand Down

0 comments on commit 0656199

Please sign in to comment.