babel-plugin-transform-taroapi 3.5.0-alpha.13 → 3.5.0-alpha.16
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/dist/index.js +7 -7
- package/package.json +4 -5
- package/src/index.ts +7 -7
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const plugin = function (babel) {
|
|
4
4
|
const t = babel.types;
|
|
5
|
-
// 这些变量需要在每个
|
|
5
|
+
// 这些变量需要在每个 program 里重置
|
|
6
6
|
const invokedApis = new Map();
|
|
7
7
|
let taroName;
|
|
8
8
|
let needDefault;
|
|
9
|
-
let
|
|
9
|
+
let referTaro;
|
|
10
10
|
return {
|
|
11
11
|
name: 'babel-plugin-transform-taro-api',
|
|
12
12
|
visitor: {
|
|
@@ -30,10 +30,10 @@ const plugin = function (babel) {
|
|
|
30
30
|
needDefault = true;
|
|
31
31
|
const localName = node.local.name;
|
|
32
32
|
const binding = ast.scope.getBinding(localName);
|
|
33
|
-
const
|
|
34
|
-
|
|
33
|
+
const idn = t.identifier(taroName);
|
|
34
|
+
referTaro.push(idn);
|
|
35
35
|
binding && binding.referencePaths.forEach(reference => {
|
|
36
|
-
reference.replaceWith(t.memberExpression(
|
|
36
|
+
reference.replaceWith(t.memberExpression(idn, t.identifier(propertyName)));
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -80,7 +80,7 @@ const plugin = function (babel) {
|
|
|
80
80
|
Program: {
|
|
81
81
|
enter(ast) {
|
|
82
82
|
needDefault = false;
|
|
83
|
-
|
|
83
|
+
referTaro = [];
|
|
84
84
|
invokedApis.clear();
|
|
85
85
|
taroName = ast.scope.getBinding('Taro')
|
|
86
86
|
? ast.scope.generateUid('Taro')
|
|
@@ -89,7 +89,7 @@ const plugin = function (babel) {
|
|
|
89
89
|
exit(ast, state) {
|
|
90
90
|
// 防止重复引入
|
|
91
91
|
let isTaroApiImported = false;
|
|
92
|
-
|
|
92
|
+
referTaro.forEach(node => {
|
|
93
93
|
node.name = taroName;
|
|
94
94
|
});
|
|
95
95
|
ast.traverse({
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-transform-taroapi",
|
|
3
|
-
"version": "3.5.0-alpha.
|
|
3
|
+
"version": "3.5.0-alpha.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"scripts": {
|
|
6
7
|
"build": "tsc"
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
"gitHead": "1e201315913fbeb3a71f14c93a5e7a2fa490e4c4"
|
|
10
|
-
}
|
|
8
|
+
}
|
|
9
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,12 +3,12 @@ const plugin = function (babel: {
|
|
|
3
3
|
}) {
|
|
4
4
|
const t = babel.types
|
|
5
5
|
|
|
6
|
-
// 这些变量需要在每个
|
|
6
|
+
// 这些变量需要在每个 program 里重置
|
|
7
7
|
const invokedApis: Map<string, string> = new Map()
|
|
8
8
|
let taroName: string
|
|
9
9
|
let needDefault: boolean
|
|
10
10
|
|
|
11
|
-
let
|
|
11
|
+
let referTaro: any[]
|
|
12
12
|
|
|
13
13
|
return {
|
|
14
14
|
name: 'babel-plugin-transform-taro-api',
|
|
@@ -31,12 +31,12 @@ const plugin = function (babel: {
|
|
|
31
31
|
needDefault = true
|
|
32
32
|
const localName = node.local.name
|
|
33
33
|
const binding = ast.scope.getBinding(localName)
|
|
34
|
-
const
|
|
35
|
-
|
|
34
|
+
const idn = t.identifier(taroName)
|
|
35
|
+
referTaro.push(idn)
|
|
36
36
|
binding && binding.referencePaths.forEach(reference => {
|
|
37
37
|
reference.replaceWith(
|
|
38
38
|
t.memberExpression(
|
|
39
|
-
|
|
39
|
+
idn,
|
|
40
40
|
t.identifier(propertyName)
|
|
41
41
|
)
|
|
42
42
|
)
|
|
@@ -87,7 +87,7 @@ const plugin = function (babel: {
|
|
|
87
87
|
Program: {
|
|
88
88
|
enter (ast) {
|
|
89
89
|
needDefault = false
|
|
90
|
-
|
|
90
|
+
referTaro = []
|
|
91
91
|
invokedApis.clear()
|
|
92
92
|
|
|
93
93
|
taroName = ast.scope.getBinding('Taro')
|
|
@@ -97,7 +97,7 @@ const plugin = function (babel: {
|
|
|
97
97
|
exit (ast, state) {
|
|
98
98
|
// 防止重复引入
|
|
99
99
|
let isTaroApiImported = false
|
|
100
|
-
|
|
100
|
+
referTaro.forEach(node => {
|
|
101
101
|
node.name = taroName
|
|
102
102
|
})
|
|
103
103
|
|