@dolphinweex/weex-harmony-transform 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/index.js +3 -0
- package/package.json +26 -0
- package/weexTransform.js +98 -0
package/README.md
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dolphinweex/weex-harmony-transform",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "weex harmony adapter",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"weexTransform.js"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@babel/traverse": "^7.25.3",
|
|
13
|
+
"fs-extra": "10.0.1",
|
|
14
|
+
"istanbul-lib-coverage": "3.2.0",
|
|
15
|
+
"istanbul-lib-report": "3.0.0",
|
|
16
|
+
"istanbul-reports": "3.1.5",
|
|
17
|
+
"nyc": "15.1.0",
|
|
18
|
+
"source-map": "0.7.4"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": ""
|
|
23
|
+
},
|
|
24
|
+
"keyword": [],
|
|
25
|
+
"devDependencies": {}
|
|
26
|
+
}
|
package/weexTransform.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
const weexExtModules = [
|
|
2
|
+
'weexModule',
|
|
3
|
+
'globalEvent',
|
|
4
|
+
'clipboard',
|
|
5
|
+
'navigator',
|
|
6
|
+
'deviceInfo',
|
|
7
|
+
'websocket',
|
|
8
|
+
'picker',
|
|
9
|
+
'webview',
|
|
10
|
+
'stream',
|
|
11
|
+
'bridgeModule',
|
|
12
|
+
'lottieModule',
|
|
13
|
+
'singleBlueToothModule',
|
|
14
|
+
'nfcModule',
|
|
15
|
+
'storage',
|
|
16
|
+
'routerModule'
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function isNeedWeexExtProxy(module) {
|
|
21
|
+
return (weexExtModules.indexOf(module) === -1) ? false : true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = function({ types: t }) {
|
|
25
|
+
return {
|
|
26
|
+
name: "weexTransform",
|
|
27
|
+
visitor: {
|
|
28
|
+
StringLiteral(path, state) {
|
|
29
|
+
},
|
|
30
|
+
CallExpression(astPath) {
|
|
31
|
+
const node = astPath.node
|
|
32
|
+
const calleePath = astPath.get('callee')
|
|
33
|
+
const callee = calleePath.node
|
|
34
|
+
if (callee.type === 'MemberExpression') {
|
|
35
|
+
const args = astPath.node.arguments
|
|
36
|
+
if (
|
|
37
|
+
args.length === 1 &&
|
|
38
|
+
t.isStringLiteral(args[0]) &&
|
|
39
|
+
isNeedWeexExtProxy(args[0].value) &&
|
|
40
|
+
t.isIdentifier(callee.object) &&
|
|
41
|
+
callee.object.name === 'weex'
|
|
42
|
+
) {
|
|
43
|
+
if (process.env.ISHARMONY === 'true') {
|
|
44
|
+
console.log('Transform harmony process.env.ISHARMONY:' + process.env.ISHARMONY);
|
|
45
|
+
// callee.object = t.identifier('weexExt')
|
|
46
|
+
|
|
47
|
+
const parentPath = astPath.parentPath?.parentPath
|
|
48
|
+
const parentNode = parentPath?.node
|
|
49
|
+
if (parentNode && t.isVariableDeclaration(parentNode)) {
|
|
50
|
+
const key = args[0].value
|
|
51
|
+
const value = parentNode.declarations[0].id.name
|
|
52
|
+
const properties = [
|
|
53
|
+
t.objectProperty(
|
|
54
|
+
t.identifier(key),
|
|
55
|
+
t.identifier(value),
|
|
56
|
+
false,
|
|
57
|
+
false
|
|
58
|
+
)
|
|
59
|
+
]
|
|
60
|
+
const objectPattern = t.objectPattern(properties)
|
|
61
|
+
|
|
62
|
+
const requireExpression = t.CallExpression(
|
|
63
|
+
t.identifier('require'),
|
|
64
|
+
[t.stringLiteral('@ohos/weex-harmony-transform')]
|
|
65
|
+
)
|
|
66
|
+
const replaceNode = t.variableDeclaration('const', [
|
|
67
|
+
t.variableDeclarator(objectPattern, requireExpression)
|
|
68
|
+
])
|
|
69
|
+
|
|
70
|
+
parentPath.replaceWith(replaceNode)
|
|
71
|
+
} else {
|
|
72
|
+
if (parentNode && t.isCallExpression(parentNode)) {
|
|
73
|
+
const callee = parentNode.callee
|
|
74
|
+
const object = callee.object
|
|
75
|
+
const requireModuleName = object.arguments[0].value
|
|
76
|
+
|
|
77
|
+
const requireExpression = t.callExpression(
|
|
78
|
+
t.identifier('require'),
|
|
79
|
+
[t.stringLiteral('@ohos/weex-harmony-transform')]
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
const memberExpression = t.memberExpression(
|
|
83
|
+
requireExpression,
|
|
84
|
+
t.identifier(requireModuleName)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
parentNode.callee.object = memberExpression
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
console.log('Transform not harmony process.env.ISHARMONY:' + process.env.ISHARMONY);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
};
|