Skip to content

Commit

Permalink
fix(transformer): 当用户没有指名循环的 index 时自动增加一个一个匿名的 index 作为变量名覆盖。fix #2258
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Feb 25, 2019
1 parent 495f7f5 commit 704a655
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,16 @@ export class RenderParser {
t.stringLiteral(index.name)
)
this.loopScopes.add(index.name)
} else if (index === undefined) {
if (process.env.NODE_ENV !== 'test') {
setJSXAttr(
jsxElementPath.node,
Adapter.forIndex,
t.stringLiteral(this.renderScope.generateUid('anonIdx'))
)
}
} else {
throw codeFrameError(index, '包含 JSX 的 map 循环第二个参数只能是一个普通标识符')
}
this.loopComponents.set(callExpr, jsxElementPath)
// caller.replaceWith(jsxElementPath.node)
Expand Down

0 comments on commit 704a655

Please sign in to comment.