webpack-gc-i18n-plugin 1.1.14 → 1.1.15

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.
@@ -1069,6 +1069,8 @@ let TranslateTypeEnum = /*#__PURE__*/function (TranslateTypeEnum) {
1069
1069
  * @FilePath: /i18n_translation_vite/packages/autoI18nPluginCore/src/option.ts
1070
1070
  */
1071
1071
 
1072
+ const DEFAULT_ORIGIN_LANG = 'zh-cn';
1073
+ const DEFAULT_TARGET_LANG_LIST = ['zh-tw'];
1072
1074
  /**
1073
1075
  * 默认插件配置选项
1074
1076
  */
@@ -1092,10 +1094,10 @@ const DEFAULT_OPTION = {
1092
1094
  distPath: '',
1093
1095
  /** 打包后生成文件的主文件名称,默认是 'index' */
1094
1096
  distKey: 'index',
1095
- /** 来源语言,默认是中文 */
1096
- originLang: OriginLangKeyEnum.ZH,
1097
- /** 翻译目标语言列表,默认包含英文 */
1098
- targetLangList: ['en'],
1097
+ /** 来源语言,由插件固定使用默认值 */
1098
+ originLang: DEFAULT_ORIGIN_LANG,
1099
+ /** 翻译目标语言列表,由插件固定使用默认值 */
1100
+ targetLangList: [...DEFAULT_TARGET_LANG_LIST],
1099
1101
  /** 语言key,用于请求谷歌api和生成配置文件下对应语言的内容文件 */
1100
1102
  langKey: [],
1101
1103
  /** 命名空间,防止全局命名冲突 */
@@ -1613,7 +1615,7 @@ function StringLiteralFn (insertOption) {
1613
1615
 
1614
1616
  // 防止导入语句,只处理那些当前节点不是键值对的键的字符串字面量,调用语句判断当前调用语句是否包含需要过滤的调用语句
1615
1617
  if (isTranslateCall(parent) || types__namespace.isImportDeclaration(parent) || parent.key === node || types__namespace.isCallExpression(parent) && extractFnName && (option.excludedCall.includes(extractFnName) || extractFnName?.split('.')?.pop() && option.excludedCall.includes(extractFnName?.split('.')?.pop() || ''))) return;
1616
- const vueVNodeCallPath = getVueCompiledVNodeCallPath(path);
1618
+ const vueVNodeInfo = getVueCompiledVNodeInfo(path);
1617
1619
  let replaceNode;
1618
1620
  if (option.deepScan && checkNeedSplit(value)) {
1619
1621
  replaceNode = convertToTemplateLiteral(splitByRegex(value, getOriginRegex()), insertOption);
@@ -1632,26 +1634,38 @@ function StringLiteralFn (insertOption) {
1632
1634
  });
1633
1635
  }
1634
1636
  path.replaceWith(replaceNode);
1635
- markVueCompiledVNodeDynamic(vueVNodeCallPath);
1637
+ markVueCompiledVNodeDynamic(vueVNodeInfo?.callPath, vueVNodeInfo?.dynamicPropName);
1636
1638
  }
1637
1639
  };
1638
1640
  }
1639
- function getVueCompiledVNodeCallPath(path) {
1641
+ function getVueCompiledVNodeInfo(path) {
1640
1642
  const callPath = path.parentPath;
1641
- if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
1642
- if (!isVueVNodeCreateCall(callPath.node)) return;
1643
- if (path.listKey !== 'arguments' || path.key !== 2) return;
1644
- return callPath;
1643
+ if (callPath && types__namespace.isCallExpression(callPath.node) && isVueVNodeCreateCall(callPath.node) && path.listKey === 'arguments' && path.key === 2) {
1644
+ return {
1645
+ callPath
1646
+ };
1647
+ }
1648
+ const propertyPath = path.parentPath;
1649
+ const propsPath = propertyPath?.parentPath;
1650
+ const vnodeCallPath = propsPath?.parentPath;
1651
+ if (!propertyPath || !types__namespace.isObjectProperty(propertyPath.node) || propertyPath.node.value !== path.node || propertyPath.node.computed || !propsPath || !types__namespace.isObjectExpression(propsPath.node) || propsPath.listKey !== 'arguments' || propsPath.key !== 1 || !vnodeCallPath || !types__namespace.isCallExpression(vnodeCallPath.node) || !isVueVNodeCreateCall(vnodeCallPath.node)) return;
1652
+ const key = propertyPath.node.key;
1653
+ const dynamicPropName = types__namespace.isIdentifier(key) ? key.name : types__namespace.isStringLiteral(key) ? key.value : undefined;
1654
+ if (!dynamicPropName) return;
1655
+ return {
1656
+ callPath: vnodeCallPath,
1657
+ dynamicPropName
1658
+ };
1645
1659
  }
1646
- function markVueCompiledVNodeDynamic(callPath) {
1660
+ function markVueCompiledVNodeDynamic(callPath, dynamicPropName) {
1647
1661
  if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
1648
- const patchFlag = callPath.node.arguments[3];
1649
- if (isCachedPatchFlag(patchFlag)) {
1650
- const textPatchFlag = types__namespace.numericLiteral(1);
1651
- textPatchFlag.leadingComments = null;
1652
- textPatchFlag.innerComments = null;
1653
- textPatchFlag.trailingComments = null;
1654
- callPath.node.arguments[3] = textPatchFlag;
1662
+ if (dynamicPropName) {
1663
+ markVueCompiledPropDynamic(callPath.node, dynamicPropName);
1664
+ } else {
1665
+ const patchFlag = callPath.node.arguments[3];
1666
+ if (isCachedPatchFlag(patchFlag)) {
1667
+ callPath.node.arguments[3] = createPatchFlag(1);
1668
+ }
1655
1669
  }
1656
1670
  const logicalPath = callPath.findParent(parentPath => {
1657
1671
  const node = parentPath.node;
@@ -1663,6 +1677,33 @@ function markVueCompiledVNodeDynamic(callPath) {
1663
1677
  logicalPath.replaceWith(callPath.node);
1664
1678
  }
1665
1679
  }
1680
+ function markVueCompiledPropDynamic(call, propName) {
1681
+ while (call.arguments.length < 3) {
1682
+ call.arguments.push(types__namespace.nullLiteral());
1683
+ }
1684
+ const patchFlag = call.arguments[3];
1685
+ if (!patchFlag || isCachedPatchFlag(patchFlag)) {
1686
+ call.arguments[3] = createPatchFlag(8);
1687
+ } else if (types__namespace.isNumericLiteral(patchFlag) && (patchFlag.value & 8) !== 8) {
1688
+ call.arguments[3] = createPatchFlag(patchFlag.value | 8);
1689
+ }
1690
+ const dynamicProps = call.arguments[4];
1691
+ if (types__namespace.isArrayExpression(dynamicProps)) {
1692
+ const hasProp = dynamicProps.elements.some(element => types__namespace.isStringLiteral(element) && element.value === propName);
1693
+ if (!hasProp) {
1694
+ dynamicProps.elements.push(types__namespace.stringLiteral(propName));
1695
+ }
1696
+ } else {
1697
+ call.arguments[4] = types__namespace.arrayExpression([types__namespace.stringLiteral(propName)]);
1698
+ }
1699
+ }
1700
+ function createPatchFlag(value) {
1701
+ const patchFlag = types__namespace.numericLiteral(value);
1702
+ patchFlag.leadingComments = null;
1703
+ patchFlag.innerComments = null;
1704
+ patchFlag.trailingComments = null;
1705
+ return patchFlag;
1706
+ }
1666
1707
  function isCachedPatchFlag(node) {
1667
1708
  return types__namespace.isNumericLiteral(node) && node.value === -1 || types__namespace.isUnaryExpression(node) && node.operator === '-' && types__namespace.isNumericLiteral(node.argument) && node.argument.value === 1;
1668
1709
  }