From a386d93a95f45a9a07567425e8ebe2c4d11ea2c4 Mon Sep 17 00:00:00 2001 From: yuche Date: Fri, 19 Apr 2019 18:28:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(taroize):=20onLoad=20=E7=9A=84=E7=AC=AC?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E5=8F=82=E6=95=B0=E5=8F=AF=E4=BB=A5=E4=BC=A0?= =?UTF-8?q?=E5=85=A5=20this.$router.params=20close=20#2792?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-transformer-wx/src/render.ts | 2 +- packages/taroize/src/script.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/taro-transformer-wx/src/render.ts b/packages/taro-transformer-wx/src/render.ts index b1b734f855c1..becc69c06981 100644 --- a/packages/taro-transformer-wx/src/render.ts +++ b/packages/taro-transformer-wx/src/render.ts @@ -1981,7 +1981,7 @@ export class RenderParser { .filter(i => isVarName(i)) .filter(i => i !== MAP_CALL_ITERATOR && !this.reserveStateWords.has(i)) .filter(i => !i.startsWith('$$')) - .filter(i => !i.startsWith('_$')) + .filter(i => !i.startsWith('_$indexKey')) .filter(i => !this.loopRefIdentifiers.has(i)) let properties = propertyKeys.map(i => t.objectProperty(t.identifier(i), t.identifier(i))) if (this.customComponentData.length > 0) { diff --git a/packages/taroize/src/script.ts b/packages/taroize/src/script.ts index 4fc03db0ce06..250b8937229e 100644 --- a/packages/taroize/src/script.ts +++ b/packages/taroize/src/script.ts @@ -185,7 +185,7 @@ function parsePage ( classBody = properties.map(prop => { const key = prop.get('key') const value = prop.get('value') - const params = prop.isObjectMethod() + let params = prop.isObjectMethod() ? prop.node.params : value.isFunctionExpression() || value.isArrowFunctionExpression() ? value.node.params @@ -303,6 +303,15 @@ function parsePage ( } if (PageLifecycle.has(name)) { const lifecycle = PageLifecycle.get(name)! + if (name === 'onLoad' && t.isIdentifier(params[0])) { + params = [t.assignmentPattern(params[0] as t.Identifier, t.logicalExpression('||', t.memberExpression( + t.memberExpression( + t.thisExpression(), + t.identifier('$router') + ), + t.identifier('params') + ), t.objectExpression([])))] + } if (prop.isObjectMethod()) { const body = prop.get('body') return t.classMethod('method', t.identifier(lifecycle), params, body.node)