babel-plugin-transform-taroapi 4.1.7-alpha.0 → 4.1.7-alpha.1
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 +4 -4
- package/package.json +1 -1
- package/src/index.ts +6 -6
package/dist/index.js
CHANGED
|
@@ -54,11 +54,11 @@ const plugin = function (babel) {
|
|
|
54
54
|
else if (t.isImportSpecifier(node)) {
|
|
55
55
|
const { imported } = node;
|
|
56
56
|
const propertyName = t.isIdentifier(imported) ? imported.name : imported.value;
|
|
57
|
-
if (this.apis.has(propertyName)) { // 记录api名字
|
|
57
|
+
if (this.apis.has(propertyName)) { // 记录 api 名字
|
|
58
58
|
ast.scope.rename(node.local.name);
|
|
59
59
|
invokedApis.set(propertyName, node.local.name);
|
|
60
60
|
}
|
|
61
|
-
else { // 如果是未实现的api 改成Taro.xxx
|
|
61
|
+
else { // 如果是未实现的 api 改成 Taro.xxx
|
|
62
62
|
needDefault = true;
|
|
63
63
|
const localName = node.local.name;
|
|
64
64
|
const binding = ast.scope.getBinding(localName);
|
|
@@ -72,7 +72,7 @@ const plugin = function (babel) {
|
|
|
72
72
|
});
|
|
73
73
|
},
|
|
74
74
|
MemberExpression(ast) {
|
|
75
|
-
/* 处理Taro.xxx */
|
|
75
|
+
/* 处理 Taro.xxx */
|
|
76
76
|
const isTaro = t.isIdentifier(ast.node.object, { name: taroName });
|
|
77
77
|
const property = ast.node.property;
|
|
78
78
|
let propertyName = null;
|
|
@@ -86,7 +86,7 @@ const plugin = function (babel) {
|
|
|
86
86
|
propertyName = property[propName];
|
|
87
87
|
if (!propertyName)
|
|
88
88
|
return;
|
|
89
|
-
// 同一api
|
|
89
|
+
// 同一 api 使用多次,读取变量名
|
|
90
90
|
if (this.apis.has(propertyName)) {
|
|
91
91
|
const parentNode = ast.parent;
|
|
92
92
|
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === ast.node;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -70,10 +70,10 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
|
|
|
70
70
|
} else if (t.isImportSpecifier(node)) {
|
|
71
71
|
const { imported } = node
|
|
72
72
|
const propertyName = t.isIdentifier(imported) ? imported.name : imported.value
|
|
73
|
-
if (this.apis.has(propertyName)) { // 记录api名字
|
|
73
|
+
if (this.apis.has(propertyName)) { // 记录 api 名字
|
|
74
74
|
ast.scope.rename(node.local.name)
|
|
75
75
|
invokedApis.set(propertyName, node.local.name)
|
|
76
|
-
} else { // 如果是未实现的api 改成Taro.xxx
|
|
76
|
+
} else { // 如果是未实现的 api 改成 Taro.xxx
|
|
77
77
|
needDefault = true
|
|
78
78
|
const localName = node.local.name
|
|
79
79
|
const binding = ast.scope.getBinding(localName)
|
|
@@ -84,7 +84,7 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
|
|
|
84
84
|
t.memberExpression(
|
|
85
85
|
idn,
|
|
86
86
|
t.identifier(propertyName)
|
|
87
|
-
)
|
|
87
|
+
) as any
|
|
88
88
|
)
|
|
89
89
|
})
|
|
90
90
|
}
|
|
@@ -92,7 +92,7 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
|
|
|
92
92
|
})
|
|
93
93
|
},
|
|
94
94
|
MemberExpression (ast: BabelCore.NodePath<any>) {
|
|
95
|
-
/* 处理Taro.xxx */
|
|
95
|
+
/* 处理 Taro.xxx */
|
|
96
96
|
const isTaro = t.isIdentifier(ast.node.object, { name: taroName })
|
|
97
97
|
const property = ast.node.property
|
|
98
98
|
let propertyName: string | null = null
|
|
@@ -108,7 +108,7 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
|
|
|
108
108
|
|
|
109
109
|
if (!propertyName) return
|
|
110
110
|
|
|
111
|
-
// 同一api
|
|
111
|
+
// 同一 api 使用多次,读取变量名
|
|
112
112
|
if (this.apis.has(propertyName)) {
|
|
113
113
|
const parentNode = ast.parent as BabelCore.types.AssignmentExpression
|
|
114
114
|
const isAssignment = t.isAssignmentExpression(parentNode) && parentNode.left === ast.node
|
|
@@ -123,7 +123,7 @@ const plugin = function (babel: typeof BabelCore): BabelCore.PluginObj<IState> {
|
|
|
123
123
|
/* 未绑定作用域 */
|
|
124
124
|
identifier = t.identifier(newPropertyName)
|
|
125
125
|
}
|
|
126
|
-
ast.replaceWith(identifier)
|
|
126
|
+
ast.replaceWith(identifier as any)
|
|
127
127
|
}
|
|
128
128
|
} else {
|
|
129
129
|
needDefault = true
|