Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(convert): 修复 taro convert 后 react 项目报错的问题 #7465

Merged
merged 5 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/taro-cli/src/rn/transformJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export function parseJSCode ({ code, filePath, isEntryFile, projectConfig }) {
},
CallExpression (astPath) {
const node = astPath.node
const callee = node.callee as t.Identifier
const callee = node.callee as any
const calleeName = callee.name
const parentPath = astPath.parentPath

Expand Down
8,939 changes: 2,094 additions & 6,845 deletions packages/taro-cli/yarn.lock

Large diffs are not rendered by default.

1,642 changes: 871 additions & 771 deletions packages/taro-helper/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ require(\\"./taro\\");
},
8: function(module, exports, __webpack_require__) {
module.exports = {
cbody: \\"index.module__cbody___3Vfl2\\",
ctext: \\"index.module__ctext___Dq1RJ\\"
cbody: \\"index-module__cbody___3Vfl2\\",
ctext: \\"index-module__ctext___Dq1RJ\\"
};
}
}, [ [ 17, 0, 1, 3, 2 ] ] ]);
Expand All @@ -532,7 +532,7 @@ require(\\"./taro\\");
<template is=\\"taro_tmpl\\" data=\\"{{root:root}}\\" />

/** filePath: dist/pages/index/index.wxss **/
.index\\\\.module__cbody___3Vfl2{height:300rpx;background-color:#e8e8ed}.index\\\\.module__ctext___Dq1RJ{display:inline-block;width:100%;color:#ff0}.index__cwrapper___oXrpd{font-size:36rpx}.chomepage{background:gray}
.index-module__cbody___3Vfl2{height:300rpx;background-color:#e8e8ed}.index-module__ctext___Dq1RJ{display:inline-block;width:100%;color:#ff0}.index__cwrapper___oXrpd{font-size:36rpx}.chomepage{background:gray}

/** filePath: dist/runtime.js **/
(function(modules) {
Expand Down Expand Up @@ -1281,8 +1281,8 @@ require(\\"./taro\\");
},
8: function(module, exports, __webpack_require__) {
module.exports = {
cbody: \\"index.module__cbody___3Vfl2\\",
ctext: \\"index.module__ctext___Dq1RJ\\"
cbody: \\"index-module__cbody___3Vfl2\\",
ctext: \\"index-module__ctext___Dq1RJ\\"
};
}
}, [ [ 17, 0, 1, 3, 2 ] ] ]);
Expand All @@ -1295,7 +1295,7 @@ require(\\"./taro\\");
<template is=\\"taro_tmpl\\" data=\\"{{root:root}}\\" />

/** filePath: dist/pages/index/index.wxss **/
.index\\\\.module__cbody___3Vfl2{height:300rpx;background-color:#e8e8ed}.index\\\\.module__ctext___Dq1RJ{display:inline-block;width:100%;color:#ff0}.cwrapper{font-size:36rpx}.chomepage{background:gray}
.index-module__cbody___3Vfl2{height:300rpx;background-color:#e8e8ed}.index-module__ctext___Dq1RJ{display:inline-block;width:100%;color:#ff0}.cwrapper{font-size:36rpx}.chomepage{background:gray}

/** filePath: dist/runtime.js **/
(function(modules) {
Expand Down
9,123 changes: 1,778 additions & 7,345 deletions packages/taro-mini-runner/yarn.lock

Large diffs are not rendered by default.

2,389 changes: 27 additions & 2,362 deletions packages/taro-service/yarn.lock

Large diffs are not rendered by default.

1,991 changes: 26 additions & 1,965 deletions packages/taro-webpack-runner/yarn.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion packages/taro-with-weapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"author": "yuche",
"license": "MIT",
"dependencies": {
"@tarojs/taro": "1.3.22",
"@tarojs/taro": "3.0.8",
"@tarojs/runtime": "3.0.8",
"lodash": "^4.17.11"
}
}
84 changes: 84 additions & 0 deletions packages/taro-with-weapp/src/clone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const json = JSON

export const clone = (obj) => json.parse(stringify(obj))

function stringify (obj, opts) {
if (!opts) opts = {}
if (typeof opts === 'function') opts = { cmp: opts }
let space = opts.space || ''
if (typeof space === 'number') space = Array(space + 1).join(' ')
const cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false
const replacer = opts.replacer || function (key, value) { return value }

const cmp = opts.cmp && (function (f) {
return function (node) {
return function (a, b) {
const aobj = { key: a, value: node[a] }
const bobj = { key: b, value: node[b] }
return f(aobj, bobj)
}
}
})(opts.cmp)

const seen = []
return (function stringify (parent, key, node, level) {
const indent = space ? ('\n' + new Array(level + 1).join(space)) : ''
const colonSeparator = space ? ': ' : ':'

if (node && node.toJSON && typeof node.toJSON === 'function') {
node = node.toJSON()
}

node = replacer.call(parent, key, node)

if (node === undefined) {
return
}
if (typeof node !== 'object' || node === null) {
return json.stringify(node)
}
if (isArray(node)) {
const out = []
for (let i = 0; i < node.length; i++) {
const item = stringify(node, i, node[i], level + 1) || json.stringify(null)
out.push(indent + space + item)
}
return '[' + out.join(',') + indent + ']'
} else {
if (seen.indexOf(node) !== -1) {
if (cycles) return json.stringify('__cycle__')
throw new TypeError('Converting circular structure to JSON')
} else seen.push(node)

const keys = objectKeys(node).sort(cmp && cmp(node))
const out = []
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const value = stringify(node, key, node[key], level + 1)

if (!value) continue

const keyValue = json.stringify(key) +
colonSeparator +
value

out.push(indent + space + keyValue)
}
seen.splice(seen.indexOf(node), 1)
return '{' + out.join(',') + indent + '}'
}
})({ '': obj }, '', obj, 0)
};

const isArray = Array.isArray || function (x) {
return {}.toString.call(x) === '[object Array]'
}

const objectKeys = Object.keys || function (obj) {
const has = Object.prototype.hasOwnProperty || function () { return true }
const keys = []
for (const key in obj) {
if (has.call(obj, key)) keys.push(key)
}
return keys
}
102 changes: 102 additions & 0 deletions packages/taro-with-weapp/src/diff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*eslint-disable*/
const ARRAYTYPE = '[object Array]'
const OBJECTTYPE = '[object Object]'
const FUNCTIONTYPE = '[object Function]'

export function diff (current, pre) {
const result = {}
syncKeys(current, pre)
_diff(current, pre, '', result)
return result
}

function syncKeys (current, pre) {
if (current === pre) return
const rootCurrentType = type(current)
const rootPreType = type(pre)
if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) {
// if(Object.keys(current).length >= Object.keys(pre).length){
for (let key in pre) {
const currentValue = current[key]
if (currentValue === undefined) {
current[key] = null
} else {
syncKeys(currentValue, pre[key])
}
}
// }
} else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) {
if (current.length >= pre.length) {
pre.forEach((item, index) => {
syncKeys(current[index], item)
})
}
}
}

function _diff (current, pre, path, result) {
if (current === pre) return
const rootCurrentType = type(current)
const rootPreType = type(pre)
if (rootCurrentType == OBJECTTYPE) {
if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(pre).length) {
setResult(result, path, current)
} else {
for (let key in current) {
const currentValue = current[key]
const preValue = pre[key]
const currentType = type(currentValue)
const preType = type(preValue)
if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) {
if (currentValue != pre[key]) {
setResult(result, (path == '' ? '' : path + '.') + key, currentValue)
}
} else if (currentType == ARRAYTYPE) {
if (preType != ARRAYTYPE) {
setResult(result, (path == '' ? '' : path + '.') + key, currentValue)
} else {
if (currentValue.length < preValue.length) {
setResult(result, (path == '' ? '' : path + '.') + key, currentValue)
} else {
currentValue.forEach((item, index) => {
_diff(item, preValue[index], (path == '' ? '' : path + '.') + key + '[' + index + ']', result)
})
}
}
} else if (currentType == OBJECTTYPE) {
if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) {
setResult(result, (path == '' ? '' : path + '.') + key, currentValue)
} else {
for (let subKey in currentValue) {
_diff(currentValue[subKey], preValue[subKey], (path == '' ? '' : path + '.') + key + '.' + subKey, result)
}
}
}
}
}
} else if (rootCurrentType == ARRAYTYPE) {
if (rootPreType != ARRAYTYPE) {
setResult(result, path, current)
} else {
if (current.length < pre.length) {
setResult(result, path, current)
} else {
current.forEach((item, index) => {
_diff(item, pre[index], path + '[' + index + ']', result)
})
}
}
} else {
setResult(result, path, current)
}
}

function setResult (result, k, v) {
if (type(v) != FUNCTIONTYPE) {
result[k] = v
}
}

function type (obj) {
return Object.prototype.toString.call(obj)
}
Loading