Skip to content

Commit

Permalink
fix(taroize): class properies 函数不能使用 arguments,close #2295
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Mar 1, 2019
1 parent 71b76b2 commit f62bb85
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/taroize/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,33 @@ function parsePage (
method.async = isAsync
return method
}
let hasArguments = false
prop.traverse({
Identifier (path) {
if (path.node.name === 'arguments') {
hasArguments = true
path.stop()
}
}
})

if (prop.isObjectMethod()) {
const body = prop.get('body')
if (hasArguments) {
return t.classMethod('method', t.identifier(name), params, body.node)
}
return t.classProperty(
t.identifier(name),
t.arrowFunctionExpression(params, body.node, isAsync)
)
}

if (hasArguments && (value.isFunctionExpression() || value.isArrowFunctionExpression())) {
const method = t.classMethod('method', t.identifier(name), params, value.node.body as any)
method.async = isAsync
return method
}

const classProp = t.classProperty(
t.identifier(name),
value.isFunctionExpression() || value.isArrowFunctionExpression()
Expand Down

0 comments on commit f62bb85

Please sign in to comment.