Skip to content

Commit

Permalink
fix(transformer): 同一作用域有多个自定义组件无法正确生成 props
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jun 6, 2019
1 parent 99c2d84 commit 29225c6
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class RenderParser {
private incrementCalleeId = isTestEnv ? incrementId() : incrementCalleeId
private loopArrayId = isTestEnv ? incrementId() : incrementLoopArrayId
private classComputedState = new Set<string>()
private propsSettingExpressions = new Map<t.BlockStatement, () => t.ExpressionStatement>()
private propsSettingExpressions = new Map<t.BlockStatement, (() => t.ExpressionStatement)[]>()
private genCompidExprs = new Set<t.VariableDeclaration>()
private loopCallees = new Set<t.Node>()
private loopIfStemComponentMap = new Map<NodePath<t.CallExpression>, t.JSXElement>()
Expand Down Expand Up @@ -1032,7 +1032,9 @@ export class RenderParser {
blockStem = blockStatement.node
}
}
this.propsSettingExpressions.set(blockStem, () => t.expressionStatement(expr))
const funcs = this.propsSettingExpressions.get(blockStem)
const func = () => t.expressionStatement(expr)
this.propsSettingExpressions.set(blockStem, funcs ? [...funcs, func] : [func])

// xml 中打上组件 ID
setJSXAttr(jsxElementPath.node, 'compid', t.jSXExpressionContainer(variableName))
Expand Down Expand Up @@ -2262,8 +2264,8 @@ export class RenderParser {
})
)
)
this.propsSettingExpressions.forEach((expr, stem) => {
stem.body.push(expr())
this.propsSettingExpressions.forEach((exprs, stem) => {
stem.body.push(...exprs.map(e => e()))
})
this.renderPath.node.body.body.unshift(...Array.from(this.genCompidExprs))
if (this.isDefaultRender) {
Expand Down

0 comments on commit 29225c6

Please sign in to comment.