From a637ca55dc3ce38e668aaab7d5d4ebb752cb9b09 Mon Sep 17 00:00:00 2001 From: yuche Date: Mon, 18 Feb 2019 20:38:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(transformer):=20=E5=BD=93=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=92=8C=E5=BE=AA=E7=8E=AF=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E6=97=B6=E8=AD=A6=E5=91=8A=EF=BC=8C=E4=BD=86?= =?UTF-8?q?=E4=BB=8D=E7=84=B6=E6=8A=8A=E6=9C=AC=E5=9C=B0=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=20usedState=20=E5=92=8C=20pendingState,=20#2?= =?UTF-8?q?199?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index d80f05a0a35e..9ad1c00816c1 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1125,6 +1125,7 @@ export class RenderParser { this.handleLoopComponents() renderBody.traverse(this.visitors) this.setOutputTemplate() + this.checkDuplicateName() this.removeJSXStatement() this.setUsedState() this.setPendingState() @@ -1567,6 +1568,17 @@ export class RenderParser { ))) } + checkDuplicateName () { + this.loopScopes.forEach(s => { + if (this.renderPath.scope.hasBinding(s)) { + const err = codeFrameError(this.renderPath.scope.getBinding(s)!.path.node, '此变量声明与循环变量冲突,可能会造成问题。') + // tslint:disable-next-line + console.warn('Warning: ', err.message) + this.loopScopes.delete(s) + } + }) + } + setPendingState () { const propertyKeys = Array.from( new Set(Array.from(this.referencedIdentifiers)