diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index cfa21ab9927b..56e03a3b0b09 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -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 => @@ -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) } } @@ -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) { diff --git a/packages/taro-transformer-wx/src/utils.ts b/packages/taro-transformer-wx/src/utils.ts index edc564917322..f7e4a321d56a 100644 --- a/packages/taro-transformer-wx/src/utils.ts +++ b/packages/taro-transformer-wx/src/utils.ts @@ -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('_$')) {