Skip to content

Commit

Permalink
fix(transformer): propsManager.set 不再设置对象字面量
Browse files Browse the repository at this point in the history
close #3721
  • Loading branch information
yuche committed Jul 16, 2019
1 parent 8492428 commit 40535ee
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ export class RenderParser {
path.parentPath.replaceWith(
template('ID = INIT;')({ ID: t.identifier(id.name), INIT: init })
)
} else if (id.name.startsWith('$props__')) {
path.skip()
} else {
const newId = this.renderScope.generateDeclaredUidIdentifier('$' + id.name)
const renamers = this.ifStemRenamers.get(blockStatement.scope)
Expand Down Expand Up @@ -983,10 +985,10 @@ export class RenderParser {

isEmptyBlock = ((block: t.JSXElement) => block.children.length === 0 && block.openingElement.attributes.length === 0)

private genPropsSettingExpression (properties: Array<t.ObjectProperty | t.SpreadProperty>, id: t.StringLiteral | t.Identifier): t.Expression {
private genPropsSettingExpression (properties: Array<t.ObjectProperty | t.SpreadProperty> | t.Identifier, id: t.StringLiteral | t.Identifier): t.Expression {
return t.callExpression(
t.memberExpression(t.identifier(PROPS_MANAGER), t.identifier('set')),
[t.objectExpression(properties), id]
[Array.isArray(properties) ? t.objectExpression(properties) : properties, id]
)
}

Expand Down Expand Up @@ -1044,7 +1046,8 @@ export class RenderParser {
if (this.isEmptyProps(openingElement.attributes)) {
return
}
const name = `$compid__${genCompid()}`
const compId = genCompid()
const name = `$compid__${compId}`
const variableName = t.identifier(name)
this.referencedIdentifiers.add(variableName)
const idExpr = buildConstVariableDeclaration(name,
Expand All @@ -1058,7 +1061,10 @@ export class RenderParser {
)
// createData 中设置 props
const properties = this.getPropsFromAttrs(openingElement)
const propsSettingExpr = this.genPropsSettingExpression(properties, variableName)
const propsId = `$props__${compId}`
const collectedProps = buildConstVariableDeclaration(propsId, t.objectExpression(properties))
jsxElementPath.getStatementParent().insertBefore(collectedProps)
const propsSettingExpr = this.genPropsSettingExpression(t.identifier(propsId), variableName)
this.genCompidExprs.add(idExpr)
const expr = setAncestorCondition(jsxElementPath, propsSettingExpr)
this.ancestorConditions.add(expr)
Expand Down

0 comments on commit 40535ee

Please sign in to comment.