babel-plugin-hylid-bridge 3.2.0-alpha.0 → 3.2.0-alpha.10
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/lib/helper.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -8
- package/package.json +2 -2
package/lib/helper.js
CHANGED
|
@@ -24,7 +24,7 @@ function snakeCaseTarget(input) {
|
|
|
24
24
|
var wordArray = words.split(' ');
|
|
25
25
|
var snakeCasedWords = wordArray.map(function (word) {
|
|
26
26
|
return word.replace(/[A-Z]/g, function (match, index) {
|
|
27
|
-
return index === 0 ? match.toLowerCase() : "_".concat(match);
|
|
27
|
+
return index === 0 ? match.toLowerCase() : "_".concat(match.toLowerCase());
|
|
28
28
|
});
|
|
29
29
|
});
|
|
30
30
|
return snakeCasedWords.join('_');
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -26,24 +26,27 @@ var identifierPrefix = '__hylid_bridge__';
|
|
|
26
26
|
var libraryName = 'hylid-bridge';
|
|
27
27
|
var myLocalName = "".concat(identifierPrefix, "my__");
|
|
28
28
|
var _default = exports.default = function _default(core, opts) {
|
|
29
|
-
var _opts$libraryDir, _opts$transformMy;
|
|
29
|
+
var _opts$libraryDir, _opts$transformMy, _opts$compact;
|
|
30
30
|
var libraryDir = (_opts$libraryDir = opts === null || opts === void 0 ? void 0 : opts.libraryDir) !== null && _opts$libraryDir !== void 0 ? _opts$libraryDir : (0, _getLibraryDir.default)();
|
|
31
31
|
var targets = (0, _helper.getTargets)(libraryDir, opts === null || opts === void 0 ? void 0 : opts.targets);
|
|
32
32
|
var userAppEnvPath = (0, _helper.getUserAppEnvPath)(opts === null || opts === void 0 ? void 0 : opts.appEnvPath);
|
|
33
33
|
var polyfillDir = opts === null || opts === void 0 ? void 0 : opts.polyfillDir;
|
|
34
34
|
var transformMy = (_opts$transformMy = opts === null || opts === void 0 ? void 0 : opts.transformMy) !== null && _opts$transformMy !== void 0 ? _opts$transformMy : false;
|
|
35
|
+
var compact = (_opts$compact = opts === null || opts === void 0 ? void 0 : opts.compact) !== null && _opts$compact !== void 0 ? _opts$compact : false;
|
|
35
36
|
// 生成 babel-compact 文件
|
|
36
|
-
(0, _generateJSAPIs.default)(targets);
|
|
37
|
+
compact && (0, _generateJSAPIs.default)(targets);
|
|
37
38
|
return {
|
|
38
39
|
name: 'babel-plugin-hylid-bridge',
|
|
39
40
|
visitor: {
|
|
40
41
|
ImportDeclaration: function ImportDeclaration(path) {
|
|
42
|
+
if (!compact) return;
|
|
41
43
|
if (path.node.source.value === libraryName) {
|
|
42
44
|
path.node.source = core.types.stringLiteral("".concat(libraryName, "/babel-compact"));
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
ExportNamedDeclaration: function ExportNamedDeclaration(path) {
|
|
46
48
|
var _path$node$source;
|
|
49
|
+
if (!compact) return;
|
|
47
50
|
if (((_path$node$source = path.node.source) === null || _path$node$source === void 0 ? void 0 : _path$node$source.value) === libraryName) {
|
|
48
51
|
path.node.source = core.types.stringLiteral("".concat(libraryName, "/babel-compact"));
|
|
49
52
|
}
|
|
@@ -134,13 +137,13 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
134
137
|
var normalizedIndexPath = polyfillIndexPath && (_fsExtra.default.existsSync("".concat(polyfillIndexPath, ".js")) || _fsExtra.default.existsSync("".concat(polyfillIndexPath, ".ts"))) ? (0, _combineExports.default)(require.resolve(innerIndexPath), polyfillIndexPath) : innerIndexPath;
|
|
135
138
|
return babelTypes.importDeclaration([babelTypes.importDefaultSpecifier(babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_my__")))], babelTypes.stringLiteral(normalizedIndexPath));
|
|
136
139
|
})));
|
|
137
|
-
var
|
|
140
|
+
var _buildElseIf = function buildElseIf(targetList) {
|
|
138
141
|
if (!targetList.length) {
|
|
139
142
|
return;
|
|
140
143
|
}
|
|
141
144
|
var target = targetList[0];
|
|
142
145
|
var targetSplit = (0, _helper.splitTarget)(target);
|
|
143
|
-
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat((0, _helper.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__"))))]),
|
|
146
|
+
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat((0, _helper.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)));
|
|
144
147
|
};
|
|
145
148
|
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))]));
|
|
146
149
|
// Do not generate the `if statement` when there is just one target.
|
|
@@ -148,7 +151,7 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
148
151
|
var targetSplit = (0, _helper.splitTarget)(targets[0]);
|
|
149
152
|
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_my__")))));
|
|
150
153
|
} else {
|
|
151
|
-
var elseIfNode =
|
|
154
|
+
var elseIfNode = _buildElseIf(targets);
|
|
152
155
|
elseIfNode && nodes.push(elseIfNode);
|
|
153
156
|
}
|
|
154
157
|
} else if (usedJSAPIList.length) {
|
|
@@ -163,7 +166,7 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
163
166
|
nodes.push(n);
|
|
164
167
|
});
|
|
165
168
|
});
|
|
166
|
-
var
|
|
169
|
+
var _buildElseIf2 = function buildElseIf(targetList) {
|
|
167
170
|
if (!targetList.length) {
|
|
168
171
|
return;
|
|
169
172
|
}
|
|
@@ -172,7 +175,7 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
172
175
|
var propertyList = normalizedJSAPIList.map(function (name) {
|
|
173
176
|
return babelTypes.objectProperty(babelTypes.identifier(name), babelTypes.identifier("".concat(identifierPrefix).concat(targetSplit[0], "_").concat(targetSplit[1], "_").concat(name, "__")));
|
|
174
177
|
});
|
|
175
|
-
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat((0, _helper.camelCase)("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList)))]),
|
|
178
|
+
return babelTypes.ifStatement(babelTypes.identifier("".concat(appEnvLocalName, ".").concat((0, _helper.camelCase)("is_".concat(targetSplit[0], "_").concat(targetSplit[1])))), babelTypes.blockStatement([babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList)))]), _buildElseIf2(targetList.slice(1)));
|
|
176
179
|
};
|
|
177
180
|
nodes.push(babelTypes.variableDeclaration('var', [babelTypes.variableDeclarator(babelTypes.identifier(myLocalName))]));
|
|
178
181
|
// Do not generate the `if statement` when there is just one target.
|
|
@@ -183,7 +186,7 @@ var _default = exports.default = function _default(core, opts) {
|
|
|
183
186
|
});
|
|
184
187
|
nodes.push(babelTypes.expressionStatement(babelTypes.assignmentExpression('=', babelTypes.identifier(myLocalName), babelTypes.objectExpression(propertyList))));
|
|
185
188
|
} else {
|
|
186
|
-
var _elseIfNode =
|
|
189
|
+
var _elseIfNode = _buildElseIf2(targets);
|
|
187
190
|
_elseIfNode && nodes.push(_elseIfNode);
|
|
188
191
|
}
|
|
189
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-hylid-bridge",
|
|
3
|
-
"version": "3.2.0-alpha.
|
|
3
|
+
"version": "3.2.0-alpha.10",
|
|
4
4
|
"description": "babel-plugin-hylid-bridge",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/babel-plugin-tester": "^9.0.7",
|
|
24
24
|
"babel-plugin-tester": "^10.1.0",
|
|
25
|
-
"hylid-bridge": "^3.2.0-alpha.
|
|
25
|
+
"hylid-bridge": "^3.2.0-alpha.10"
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"registry": "https://registry.npmjs.org/",
|