babel-plugin-hylid-bridge 2.4.0-alpha.0 → 2.4.0-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/CHANGELOG.md +8 -0
- package/lib/index.js +14 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.4.0-alpha.1](https://code.alipay.com/ant-ife/hylid-bridge/compare/v2.4.0-alpha.0...v2.4.0-alpha.1) (2022-08-15)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 不修改全局的 my, 新建本地变量
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [2.4.0-alpha.0](https://code.alipay.com/ant-ife/hylid-bridge/compare/v2.1.0...v2.4.0-alpha.0) (2022-08-12)
|
|
7
15
|
|
|
8
16
|
|
package/lib/index.js
CHANGED
|
@@ -95,6 +95,8 @@ function splitTarget(target) {
|
|
|
95
95
|
throw new Error("Invalid bridge target: ".concat(target, "."));
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
var myLocalName = "".concat(identifierPrefix, "my__");
|
|
99
|
+
|
|
98
100
|
var _default = function _default(_, opts) {
|
|
99
101
|
var targets = getTargets(opts === null || opts === void 0 ? void 0 : opts.targets);
|
|
100
102
|
var userAppEnvPath = getUserAppEnvPath(opts === null || opts === void 0 ? void 0 : opts.appEnvPath);
|
|
@@ -111,7 +113,11 @@ var _default = function _default(_, opts) {
|
|
|
111
113
|
return;
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
var newNode = babelTypes.cloneNode(path.node, true, true);
|
|
117
|
+
newNode.object = babelTypes.identifier(myLocalName);
|
|
118
|
+
|
|
114
119
|
if (state.usedJSAPIList === 'all') {
|
|
120
|
+
path.replaceWith(newNode);
|
|
115
121
|
return;
|
|
116
122
|
}
|
|
117
123
|
|
|
@@ -137,6 +143,8 @@ var _default = function _default(_, opts) {
|
|
|
137
143
|
state.usedJSAPIList = 'all';
|
|
138
144
|
}
|
|
139
145
|
}
|
|
146
|
+
|
|
147
|
+
path.replaceWith(newNode);
|
|
140
148
|
},
|
|
141
149
|
Program: {
|
|
142
150
|
exit: function exit(path, state) {
|
|
@@ -179,14 +187,14 @@ var _default = function _default(_, opts) {
|
|
|
179
187
|
|
|
180
188
|
var target = targetList[0];
|
|
181
189
|
var targetSplit = splitTarget(target);
|
|
182
|
-
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat(_lodash.default.camelCase("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
190
|
+
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat(_lodash.default.camelCase("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_my__"))))]), buildElseIf(targetList.slice(1)));
|
|
183
191
|
};
|
|
184
192
|
|
|
185
|
-
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(
|
|
193
|
+
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))])); // Do not generate the `if statement` when there is just one target.
|
|
186
194
|
|
|
187
195
|
if (targets.length === 1) {
|
|
188
196
|
var targetSplit = splitTarget(targets[0]);
|
|
189
|
-
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
197
|
+
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_my__")))));
|
|
190
198
|
} else {
|
|
191
199
|
var elseIfNode = buildElseIf(targets);
|
|
192
200
|
elseIfNode && nodes.push(elseIfNode);
|
|
@@ -213,10 +221,10 @@ var _default = function _default(_, opts) {
|
|
|
213
221
|
var propertyList = normalizedJSAPIList.map(function (name) {
|
|
214
222
|
return babelTypes.objectProperty(babelTypes.identifier(name), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_").concat(name, "__")));
|
|
215
223
|
});
|
|
216
|
-
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat(_lodash.default.camelCase("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
224
|
+
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat(_lodash.default.camelCase("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList)))]), _buildElseIf(targetList.slice(1)));
|
|
217
225
|
};
|
|
218
226
|
|
|
219
|
-
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(
|
|
227
|
+
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))])); // Do not generate the `if statement` when there is just one target.
|
|
220
228
|
|
|
221
229
|
if (targets.length === 1) {
|
|
222
230
|
var _targetSplit = splitTarget(targets[0]);
|
|
@@ -224,7 +232,7 @@ var _default = function _default(_, opts) {
|
|
|
224
232
|
var propertyList = normalizedJSAPIList.map(function (name) {
|
|
225
233
|
return babelTypes.objectProperty(babelTypes.identifier(name), babelTypes.identifier("".concat(identifierPrefix).concat(_targetSplit[0], "_").concat(_targetSplit[1], "_").concat(name, "__")));
|
|
226
234
|
});
|
|
227
|
-
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
235
|
+
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList))));
|
|
228
236
|
} else {
|
|
229
237
|
var _elseIfNode = _buildElseIf(targets);
|
|
230
238
|
|