webpack-gc-i18n-plugin 1.1.6 → 1.1.8
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/customLoader/index.cjs +54 -11
- package/dist/customLoader/index.cjs.map +1 -1
- package/dist/customLoader/index.mjs +54 -11
- package/dist/customLoader/index.mjs.map +1 -1
- package/dist/index.cjs +494 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +121 -2
- package/dist/index.mjs +481 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -50,6 +50,16 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
50
50
|
***************************************************************************** */
|
|
51
51
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
52
52
|
|
|
53
|
+
var __assign = function () {
|
|
54
|
+
__assign = Object.assign || function __assign(t) {
|
|
55
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
56
|
+
s = arguments[i];
|
|
57
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
};
|
|
61
|
+
return __assign.apply(this, arguments);
|
|
62
|
+
};
|
|
53
63
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
54
64
|
function adopt(value) {
|
|
55
65
|
return value instanceof P ? value : new P(function (resolve) {
|
|
@@ -807,6 +817,13 @@ function createI18nTranslator(createOption) {
|
|
|
807
817
|
uncodeValue: valStr,
|
|
808
818
|
namespace: nameSpace
|
|
809
819
|
};
|
|
820
|
+
insertOption?.collector?.record?.({
|
|
821
|
+
key: option.useValueAsKey ? trimmedValue : generatedKey,
|
|
822
|
+
value: trimmedValue,
|
|
823
|
+
namespace: nameSpace,
|
|
824
|
+
resourcePath: insertOption?.resourcePath,
|
|
825
|
+
root: insertOption?.root
|
|
826
|
+
});
|
|
810
827
|
if (option.translateExtends) {
|
|
811
828
|
const {
|
|
812
829
|
handleCodeCall,
|
|
@@ -1164,9 +1181,13 @@ function getExpressionPlaceholder(expression) {
|
|
|
1164
1181
|
return getExpressionPlaceholder(expression.expression);
|
|
1165
1182
|
}
|
|
1166
1183
|
const generateCode = generate__namespace.default?.default || generate__namespace.default || generate__namespace;
|
|
1167
|
-
return generateCode(expression, {
|
|
1184
|
+
return normalizeExpressionPlaceholder(generateCode(expression, {
|
|
1168
1185
|
comments: false
|
|
1169
|
-
}).code;
|
|
1186
|
+
}).code);
|
|
1187
|
+
}
|
|
1188
|
+
function normalizeExpressionPlaceholder(placeholder) {
|
|
1189
|
+
if (placeholder === null) return null;
|
|
1190
|
+
return placeholder.replace(/(^|[^\w$])(?:_vm|\$data)\s*\./g, '$1').replace(/(^|[^\w$])(?:_vm|\$data)\s*\[/g, '$1[');
|
|
1170
1191
|
}
|
|
1171
1192
|
function optimizeConditionalExpression(expression) {
|
|
1172
1193
|
if (!types.isConditionalExpression(expression)) return null;
|
|
@@ -1412,11 +1433,11 @@ function CallExpressionFn (insertOption) {
|
|
|
1412
1433
|
isExpression: true
|
|
1413
1434
|
});
|
|
1414
1435
|
path.replaceWith(replaceNode);
|
|
1415
|
-
translateSetLang(replaceNode);
|
|
1436
|
+
translateSetLang(replaceNode, insertOption);
|
|
1416
1437
|
}
|
|
1417
1438
|
} else if (option.translateType === TranslateTypeEnum.FULL_AUTO) {
|
|
1418
1439
|
// 全自动模式下还是只收集 单独 $t 调用
|
|
1419
|
-
if (callee.name === option.translateKey || callee.property && callee.property.name === option.translateKey) translateSetLang(node);
|
|
1440
|
+
if (callee.name === option.translateKey || callee.property && callee.property.name === option.translateKey) translateSetLang(node, insertOption);
|
|
1420
1441
|
}
|
|
1421
1442
|
}
|
|
1422
1443
|
};
|
|
@@ -1427,17 +1448,34 @@ function CallExpressionFn (insertOption) {
|
|
|
1427
1448
|
* @param node - 调用表达式节点
|
|
1428
1449
|
* @return
|
|
1429
1450
|
*/
|
|
1430
|
-
function translateSetLang(node) {
|
|
1451
|
+
function translateSetLang(node, insertOption) {
|
|
1431
1452
|
// 获取调用表达式的参数
|
|
1432
1453
|
let arg = node.arguments || [];
|
|
1433
1454
|
// 提取参数作为值
|
|
1434
1455
|
// 检查参数是否为字符串字面量
|
|
1435
|
-
const
|
|
1436
|
-
const
|
|
1456
|
+
const idArg = arg[0];
|
|
1457
|
+
const valueArg = arg[1];
|
|
1458
|
+
const id = types__namespace.isStringLiteral(idArg) ? idArg.value : '';
|
|
1459
|
+
const value = types__namespace.isStringLiteral(valueArg) ? valueArg.value : '';
|
|
1437
1460
|
// 检查 ID 和值是否存在,并且第二个参数是字符串字面量
|
|
1438
|
-
if (id && value && types__namespace.isStringLiteral(
|
|
1461
|
+
if (id && value && types__namespace.isStringLiteral(idArg) && types__namespace.isStringLiteral(valueArg)) {
|
|
1462
|
+
const resolvedId = resolveLangKey(id, value);
|
|
1463
|
+
if (resolvedId !== id) {
|
|
1464
|
+
idArg.value = resolvedId;
|
|
1465
|
+
idArg.extra = {
|
|
1466
|
+
raw: `'${resolvedId}'`,
|
|
1467
|
+
rawValue: resolvedId
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1439
1470
|
// 调用翻译工具的 setLangObj 方法设置语言对象属性
|
|
1440
|
-
setLangObj(
|
|
1471
|
+
setLangObj(resolvedId, value);
|
|
1472
|
+
insertOption?.collector?.record?.({
|
|
1473
|
+
key: option.useValueAsKey ? value : resolvedId,
|
|
1474
|
+
value,
|
|
1475
|
+
namespace: option.namespace,
|
|
1476
|
+
resourcePath: insertOption?.resourcePath,
|
|
1477
|
+
root: insertOption?.root
|
|
1478
|
+
});
|
|
1441
1479
|
}
|
|
1442
1480
|
}
|
|
1443
1481
|
|
|
@@ -1592,7 +1630,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
1592
1630
|
*/
|
|
1593
1631
|
module.exports = function (source) {
|
|
1594
1632
|
return __awaiter(this, void 0, void 0, function () {
|
|
1595
|
-
var baseUtils, option$1, filter, global, sourceObj, result, e_1;
|
|
1633
|
+
var baseUtils, option$1, filter, global, loaderOptions, sourceObj, result, e_1;
|
|
1596
1634
|
var _a;
|
|
1597
1635
|
return __generator(this, function (_b) {
|
|
1598
1636
|
switch (_b.label) {
|
|
@@ -1610,6 +1648,7 @@ module.exports = function (source) {
|
|
|
1610
1648
|
if (option$1.excludedPath.length && baseUtils.checkAgainstRegexArray(global.resourcePath, option$1.excludedPath)) {
|
|
1611
1649
|
return [2 /*return*/, source]; // 在黑名单目录中的文件,不处理,直接返回原始代码。
|
|
1612
1650
|
}
|
|
1651
|
+
loaderOptions = global.getOptions ? global.getOptions() : {};
|
|
1613
1652
|
if (!option$1.translateExtends) return [3 /*break*/, 2];
|
|
1614
1653
|
return [4 /*yield*/, (_a = option$1.translateExtends) === null || _a === void 0 ? void 0 : _a.handleInitFile(source, global.resourcePath)];
|
|
1615
1654
|
case 1:
|
|
@@ -1625,7 +1664,11 @@ module.exports = function (source) {
|
|
|
1625
1664
|
return [4 /*yield*/, babel__namespace.transformAsync(sourceObj.source, {
|
|
1626
1665
|
configFile: false,
|
|
1627
1666
|
// 不加载本地 Babel 配置文件
|
|
1628
|
-
plugins: [filter.default(sourceObj)
|
|
1667
|
+
plugins: [filter.default(__assign(__assign({}, sourceObj), {
|
|
1668
|
+
resourcePath: global.resourcePath,
|
|
1669
|
+
root: loaderOptions.root || global.rootContext,
|
|
1670
|
+
collector: loaderOptions.collector
|
|
1671
|
+
}))] // 使用核心模块提供的 `filter` 插件
|
|
1629
1672
|
})
|
|
1630
1673
|
// 如果转换成功,返回转换后的代码;否则返回空字符串。
|
|
1631
1674
|
];
|