Skip to content

Commit

Permalink
feat(transformer): 循环中可以直接 return JSX 引用,close #3504
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Jun 24, 2019
1 parent beb21f0 commit 38a38ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ export class RenderParser {
}
if (t.isIdentifier(parentNode.left)) {
const assignmentName = parentNode.left.name
const renderScope = isIfStemInLoop ? jsxElementPath.findParent(p => isArrayMapCallExpression(p)).get('arguments')[0].get('body').scope : this.renderScope
const bindingNode = renderScope.getOwnBinding(assignmentName).path.node
const renderScope: Scope = isIfStemInLoop ? jsxElementPath.findParent(p => isArrayMapCallExpression(p)).get('arguments')[0].get('body').scope : this.renderScope
const bindingNode = renderScope.getOwnBinding(assignmentName)!.path.node
// tslint:disable-next-line
const parallelIfStems = this.findParallelIfStem(ifStatement)
const parentIfStatement = ifStatement.findParent(p =>
Expand Down Expand Up @@ -897,6 +897,7 @@ export class RenderParser {
// setTemplate(name, path, templates)
assignmentName && this.templates.set(assignmentName, block)
if (isIfStemInLoop) {
this.replaceIdWithTemplate()(renderScope.path)
this.returnedPaths.push(parentPath)
}
}
Expand Down Expand Up @@ -2058,7 +2059,7 @@ export class RenderParser {
// this.referencedIdentifiers.add(t.identifier(stateName))
if (Adapters.quickapp === Adapter.type) {
let itemName = indexId!.name
let indexName = indexId!.name
let indexName = itemId!.name
if (itemName || indexName) {
let forExpr: string
if (itemName && !indexName) {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export function generateAnonymousState (
if (isArrowFunctionInJSX) {
return
}
if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE) && !id.name.startsWith('_$')) {
if (t.isIdentifier(id) && !id.name.startsWith(LOOP_STATE) && !id.name.startsWith('_$') && init != null) {
const newId = scope.generateDeclaredUidIdentifier('$' + id.name)
refIds.forEach((refId) => {
if (refId.name === variableName && !variableName.startsWith('_$')) {
Expand Down

0 comments on commit 38a38ce

Please sign in to comment.