Skip to content

Commit

Permalink
fix(taroize): onLoad 的第一个参数可以传入 this.$router.params
Browse files Browse the repository at this point in the history
close #2792
  • Loading branch information
yuche committed Apr 19, 2019
1 parent 9c1cae6 commit a386d93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 10 additions & 1 deletion packages/taroize/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a386d93

Please sign in to comment.