Skip to content

Commit

Permalink
refactor(taroize) 删除无用文件,重构部分函数 (#4333)
Browse files Browse the repository at this point in the history
* taroize#reconstruction Taroize微重构

* taroize#reconstruction Taroize微重构,增加参数类型
  • Loading branch information
Qiyu8 authored and yuche committed Aug 29, 2019
1 parent 51a2415 commit d7945c2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 57 deletions.
26 changes: 0 additions & 26 deletions packages/taroize/src/lifecycle.ts

This file was deleted.

55 changes: 24 additions & 31 deletions packages/taroize/src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ const buildDecorator = (id: t.Identifier | t.ObjectExpression) => t.decorator(
t.callExpression(t.identifier('withWeapp'), [id])
)

function replaceIdentifier (callee: NodePath<t.Node>) {
if (callee.isIdentifier()) {
const name = callee.node.name
if (name === 'getApp' || name === 'getCurrentPages') {
callee.replaceWith(
t.memberExpression(t.identifier('Taro'), callee.node)
)
}
}
}

function replaceMemberExpression (callee: NodePath<t.Node>) {
if (callee.isMemberExpression()) {
const object = callee.get('object')
if (object.isIdentifier({ name: 'wx' })) {
object.replaceWith(t.identifier('Taro'))
}
}
}

export function parseScript (
script?: string,
returned?: t.Expression,
Expand Down Expand Up @@ -37,20 +57,8 @@ export function parseScript (
},
CallExpression (path) {
const callee = path.get('callee')
if (callee.isIdentifier()) {
const name = callee.node.name
if (name === 'getApp' || name === 'getCurrentPages') {
callee.replaceWith(
t.memberExpression(t.identifier('Taro'), callee.node)
)
}
}
if (callee.isMemberExpression()) {
const object = callee.get('object')
if (object.isIdentifier({ name: 'wx' })) {
object.replaceWith(t.identifier('Taro'))
}
}
replaceIdentifier(callee)
replaceMemberExpression(callee)
if (
callee.isIdentifier({ name: 'Page' }) ||
callee.isIdentifier({ name: 'Component' }) ||
Expand Down Expand Up @@ -114,23 +122,8 @@ function parsePage (
pagePath.traverse({
CallExpression (path) {
const callee = path.get('callee')
if (callee.isIdentifier()) {
const name = callee.node.name
if (name === 'getApp' || name === 'getCurrentPages') {
callee.replaceWith(
t.memberExpression(t.identifier('Taro'), callee.node)
)
}
}
if (callee.isMemberExpression()) {
const object = callee.get('object')
if (object.isIdentifier()) {
const objectName = object.node.name
if (objectName === 'wx') {
object.replaceWith(t.identifier('Taro'))
}
}
}
replaceIdentifier(callee)
replaceMemberExpression(callee)
}
})
if (refId) {
Expand Down

0 comments on commit d7945c2

Please sign in to comment.