Skip to content

Commit

Permalink
fix(transformer): 自定义组件 bind 会生成匿名 state
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Nov 14, 2018
1 parent 3cad1fb commit 4be9fd1
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,9 @@ class Transformer {
if (!attr) return
const key = attr.node.name
const value = attr.node.value
if (!t.isJSXIdentifier(key)) {
return
}
if (t.isJSXIdentifier(key) && key.name.startsWith('on') && t.isJSXExpressionContainer(value)) {
const expr = value.expression
if (t.isCallExpression(expr) && t.isMemberExpression(expr.callee) && t.isIdentifier(expr.callee.property, { name: 'bind' })) {
Expand All @@ -347,7 +350,7 @@ class Transformer {
if (!jsx) return
const jsxName = jsx.node.name
if (!t.isJSXIdentifier(jsxName)) return
if (DEFAULT_Component_SET.has(jsxName.name) || expression.isIdentifier() || expression.isMemberExpression() || expression.isLiteral() || expression.isLogicalExpression() || expression.isConditionalExpression()) return
if (DEFAULT_Component_SET.has(jsxName.name) || expression.isIdentifier() || expression.isMemberExpression() || expression.isLiteral() || expression.isLogicalExpression() || expression.isConditionalExpression() || key.name.startsWith('on') || expression.isCallExpression()) return
generateAnonymousState(scope, expression, self.jsxReferencedIdentifiers)
},
JSXElement (path) {
Expand Down

0 comments on commit 4be9fd1

Please sign in to comment.