Skip to content

Commit

Permalink
fix(transformer): 不以 render 开头的 JSX 函数没有重命名
Browse files Browse the repository at this point in the history
close #4036
  • Loading branch information
yuche committed Aug 1, 2019
1 parent 071ce65 commit 2fc083b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/taro-transformer-wx/src/class-method-renamer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as t from 'babel-types'
import { isDerivedFromThis } from './utils'

function buildMethodName (n: string) {
return `render${n}`
return `render${n.charAt(0).toUpperCase() + n.slice(1)}`
}

export const buildVistor = () => {
Expand All @@ -18,15 +18,20 @@ export const buildVistor = () => {
let methodName = ''
const classMethod = path.findParent(p => p.isClassMethod())
if (classMethod && classMethod.isClassMethod() && t.isIdentifier(classMethod.node.key)) {
methodName = classMethod.node.key.name
if (methodName.startsWith('render')) {
return
}
methodName = classMethod.node.key.name
classMethod.node.key = t.identifier(buildMethodName(methodName))
}

const classProp = path.findParent(p => p.isClassProperty())
if (classProp && classProp.isClassProperty()) {
methodName = classProp.node.key.name
if (methodName.startsWith('render')) {
return
}
classProp.node.key = t.identifier(buildMethodName(methodName))
}

if (methodName.length > 0 && !methodName.startsWith('render')) {
Expand Down

0 comments on commit 2fc083b

Please sign in to comment.