From f62bb85d0e680757ca0b86f3790c7fc86e51847a Mon Sep 17 00:00:00 2001 From: yuche Date: Fri, 1 Mar 2019 14:01:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(taroize):=20class=20properies=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8=20arguments?= =?UTF-8?q?=EF=BC=8Cclose=20#2295?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taroize/src/script.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/taroize/src/script.ts b/packages/taroize/src/script.ts index cb4203763fdf..c62991b9704f 100644 --- a/packages/taroize/src/script.ts +++ b/packages/taroize/src/script.ts @@ -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()