From 3b146c8c59a3d3dc6aadb0321fa5e00dbab4199c Mon Sep 17 00:00:00 2001 From: yuche Date: Tue, 19 Feb 2019 14:09:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(transformer):=20=E9=99=90=E5=AE=9A=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E5=BE=AA=E7=8E=AF=20ref=20=E7=9A=84=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C#2194?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index 9ad1c00816c1..63734e0ff7a1 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -328,6 +328,13 @@ export class RenderParser { Adapter.type !== Adapters.alipay && classPath.node.body.body.unshift(classProp) } + setLoopRefFlag () { + if (this.loopRefs.size) { + const classPath = this.renderPath.findParent(isClassDcl) as NodePath + classPath.node.body.body.unshift(t.classProperty(t.identifier('$$hasLoopRef'), t.booleanLiteral(true))) + } + } + replaceIdWithTemplate = (handleRefId = false) => (path: NodePath) => { if (!t.isJSXAttribute(path.parent)) { path.traverse({ @@ -1132,6 +1139,7 @@ export class RenderParser { this.setCustomEvent() this.createData() this.setProperies() + this.setLoopRefFlag() } checkDuplicateData () { @@ -1214,7 +1222,7 @@ export class RenderParser { } const callGetElementById = t.callExpression(t.identifier(GEL_ELEMENT_BY_ID), args) const refDecl = buildConstVariableDeclaration(refDeclName, - process.env.NODE_ENV === 'test' ? callGetElementById : t.logicalExpression('&&', t.identifier('__scope'), callGetElementById) + process.env.NODE_ENV === 'test' ? callGetElementById : t.logicalExpression('&&', t.identifier('__scope'), t.logicalExpression('&&', t.identifier('__runloopRef'), callGetElementById)) ) const callRef = t.callExpression(ref.fn, [t.identifier(refDeclName)]) const callRefFunc = t.expressionStatement( @@ -1657,6 +1665,7 @@ export class RenderParser { this.renderPath.node.body.body.unshift( template(`this.__state = arguments[0] || this.state || {};`)(), template(`this.__props = arguments[1] || this.props || {};`)(), + template(`const __runloopRef = arguments[3];`)(), this.usedThisProperties.size ? t.variableDeclaration( 'const',