webpack-gc-i18n-plugin 1.1.7 → 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.
@@ -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,7 +1448,7 @@ 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
  // 提取参数作为值
@@ -1448,6 +1469,13 @@ function translateSetLang(node) {
1448
1469
  }
1449
1470
  // 调用翻译工具的 setLangObj 方法设置语言对象属性
1450
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
+ });
1451
1479
  }
1452
1480
  }
1453
1481
 
@@ -1602,7 +1630,7 @@ var index$1 = /*#__PURE__*/Object.freeze({
1602
1630
  */
1603
1631
  module.exports = function (source) {
1604
1632
  return __awaiter(this, void 0, void 0, function () {
1605
- var baseUtils, option$1, filter, global, sourceObj, result, e_1;
1633
+ var baseUtils, option$1, filter, global, loaderOptions, sourceObj, result, e_1;
1606
1634
  var _a;
1607
1635
  return __generator(this, function (_b) {
1608
1636
  switch (_b.label) {
@@ -1620,6 +1648,7 @@ module.exports = function (source) {
1620
1648
  if (option$1.excludedPath.length && baseUtils.checkAgainstRegexArray(global.resourcePath, option$1.excludedPath)) {
1621
1649
  return [2 /*return*/, source]; // 在黑名单目录中的文件,不处理,直接返回原始代码。
1622
1650
  }
1651
+ loaderOptions = global.getOptions ? global.getOptions() : {};
1623
1652
  if (!option$1.translateExtends) return [3 /*break*/, 2];
1624
1653
  return [4 /*yield*/, (_a = option$1.translateExtends) === null || _a === void 0 ? void 0 : _a.handleInitFile(source, global.resourcePath)];
1625
1654
  case 1:
@@ -1635,7 +1664,11 @@ module.exports = function (source) {
1635
1664
  return [4 /*yield*/, babel__namespace.transformAsync(sourceObj.source, {
1636
1665
  configFile: false,
1637
1666
  // 不加载本地 Babel 配置文件
1638
- plugins: [filter.default(sourceObj)] // 使用核心模块提供的 `filter` 插件
1667
+ plugins: [filter.default(__assign(__assign({}, sourceObj), {
1668
+ resourcePath: global.resourcePath,
1669
+ root: loaderOptions.root || global.rootContext,
1670
+ collector: loaderOptions.collector
1671
+ }))] // 使用核心模块提供的 `filter` 插件
1639
1672
  })
1640
1673
  // 如果转换成功,返回转换后的代码;否则返回空字符串。
1641
1674
  ];