Skip to content

Commit

Permalink
fix(transformer): 限定运行循环 ref 的条件,#2194
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Feb 19, 2019
1 parent 31b16b6 commit 3b146c8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<t.ClassDeclaration>
classPath.node.body.body.unshift(t.classProperty(t.identifier('$$hasLoopRef'), t.booleanLiteral(true)))
}
}

replaceIdWithTemplate = (handleRefId = false) => (path: NodePath<t.Node>) => {
if (!t.isJSXAttribute(path.parent)) {
path.traverse({
Expand Down Expand Up @@ -1132,6 +1139,7 @@ export class RenderParser {
this.setCustomEvent()
this.createData()
this.setProperies()
this.setLoopRefFlag()
}

checkDuplicateData () {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 3b146c8

Please sign in to comment.