babel-plugin-hylid-bridge 2.4.0-alpha.0 → 2.4.0-alpha.3
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 +24 -0
- package/lib/getLibraryDir.js +1 -1
- package/lib/index.js +18 -8
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.3](https://code.alipay.com/ant-ife/hylid-bridge/compare/v2.4.0-alpha.2...v2.4.0-alpha.3) (2022-08-17)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package babel-plugin-hylid-bridge
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [2.4.0-alpha.2](https://code.alipay.com/ant-ife/hylid-bridge/compare/v2.4.0-alpha.1...v2.4.0-alpha.2) (2022-08-16)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* 避免频繁打印日志* 适配 Remix 中会编译所有 node_modules 下模块的逻辑
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [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)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* 不修改全局的 my, 新建本地变量
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [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
31
|
|
|
8
32
|
|
package/lib/getLibraryDir.js
CHANGED
|
@@ -17,11 +17,11 @@ function getLibraryDir() {
|
|
|
17
17
|
libraryDir = process.env.HYLID_BRIDGE_PACKAGE_DIR || require.resolve('hylid-bridge/package.json', {
|
|
18
18
|
paths: [cwd]
|
|
19
19
|
}).replace('package.json', '');
|
|
20
|
+
(0, _utils.log)("Find the hylid-bridge package: ".concat(libraryDir));
|
|
20
21
|
} catch (e) {
|
|
21
22
|
(0, _utils.error)("Can not resolve the hylid-bridge package from the directory: ".concat(cwd, "."), e);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
(0, _utils.log)("Find the hylid-bridge package: ".concat(libraryDir));
|
|
26
26
|
return libraryDir;
|
|
27
27
|
}
|
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);
|
|
@@ -102,16 +104,22 @@ var _default = function _default(_, opts) {
|
|
|
102
104
|
name: 'babel-plugin-hylid-bridge',
|
|
103
105
|
visitor: {
|
|
104
106
|
MemberExpression: function MemberExpression(path, state) {
|
|
105
|
-
var _this
|
|
107
|
+
var _this$filename,
|
|
108
|
+
_this = this;
|
|
106
109
|
|
|
107
110
|
var objectName = path.node.object.name;
|
|
108
111
|
var propertyName = path.node.property.name;
|
|
109
112
|
|
|
110
|
-
if (
|
|
113
|
+
if ( // Remix 中会编译所有 node_modules 下的模块
|
|
114
|
+
(_this$filename = this.filename) !== null && _this$filename !== void 0 && _this$filename.includes("".concat(_path.default.sep, "node_modules").concat(_path.default.sep, "hylid-bridge").concat(_path.default.sep)) || !targets || !targets.length || objectName !== 'my' || path.scope.hasBinding('my')) {
|
|
111
115
|
return;
|
|
112
116
|
}
|
|
113
117
|
|
|
118
|
+
var newNode = babelTypes.cloneNode(path.node, true, true);
|
|
119
|
+
newNode.object = babelTypes.identifier(myLocalName);
|
|
120
|
+
|
|
114
121
|
if (state.usedJSAPIList === 'all') {
|
|
122
|
+
path.replaceWith(newNode);
|
|
115
123
|
return;
|
|
116
124
|
}
|
|
117
125
|
|
|
@@ -137,6 +145,8 @@ var _default = function _default(_, opts) {
|
|
|
137
145
|
state.usedJSAPIList = 'all';
|
|
138
146
|
}
|
|
139
147
|
}
|
|
148
|
+
|
|
149
|
+
path.replaceWith(newNode);
|
|
140
150
|
},
|
|
141
151
|
Program: {
|
|
142
152
|
exit: function exit(path, state) {
|
|
@@ -179,14 +189,14 @@ var _default = function _default(_, opts) {
|
|
|
179
189
|
|
|
180
190
|
var target = targetList[0];
|
|
181
191
|
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(
|
|
192
|
+
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
193
|
};
|
|
184
194
|
|
|
185
|
-
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(
|
|
195
|
+
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))])); // Do not generate the `if statement` when there is just one target.
|
|
186
196
|
|
|
187
197
|
if (targets.length === 1) {
|
|
188
198
|
var targetSplit = splitTarget(targets[0]);
|
|
189
|
-
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
199
|
+
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_my__")))));
|
|
190
200
|
} else {
|
|
191
201
|
var elseIfNode = buildElseIf(targets);
|
|
192
202
|
elseIfNode && nodes.push(elseIfNode);
|
|
@@ -213,10 +223,10 @@ var _default = function _default(_, opts) {
|
|
|
213
223
|
var propertyList = normalizedJSAPIList.map(function (name) {
|
|
214
224
|
return babelTypes.objectProperty(babelTypes.identifier(name), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_").concat(name, "__")));
|
|
215
225
|
});
|
|
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(
|
|
226
|
+
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
227
|
};
|
|
218
228
|
|
|
219
|
-
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(
|
|
229
|
+
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))])); // Do not generate the `if statement` when there is just one target.
|
|
220
230
|
|
|
221
231
|
if (targets.length === 1) {
|
|
222
232
|
var _targetSplit = splitTarget(targets[0]);
|
|
@@ -224,7 +234,7 @@ var _default = function _default(_, opts) {
|
|
|
224
234
|
var propertyList = normalizedJSAPIList.map(function (name) {
|
|
225
235
|
return babelTypes.objectProperty(babelTypes.identifier(name), babelTypes.identifier("".concat(identifierPrefix).concat(_targetSplit[0], "_").concat(_targetSplit[1], "_").concat(name, "__")));
|
|
226
236
|
});
|
|
227
|
-
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(
|
|
237
|
+
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList))));
|
|
228
238
|
} else {
|
|
229
239
|
var _elseIfNode = _buildElseIf(targets);
|
|
230
240
|
|