webpack-gc-i18n-plugin 1.1.11 → 1.1.13

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.
@@ -48,7 +48,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
48
48
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
49
49
  PERFORMANCE OF THIS SOFTWARE.
50
50
  ***************************************************************************** */
51
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
51
+ /* global Reflect, Promise, SuppressedError, Symbol */
52
52
 
53
53
  var __assign = function () {
54
54
  __assign = Object.assign || function __assign(t) {
@@ -100,8 +100,12 @@ function __generator(thisArg, body) {
100
100
  f,
101
101
  y,
102
102
  t,
103
- g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
104
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
103
+ g;
104
+ return g = {
105
+ next: verb(0),
106
+ "throw": verb(1),
107
+ "return": verb(2)
108
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
105
109
  return this;
106
110
  }), g;
107
111
  function verb(n) {
@@ -570,7 +574,7 @@ function splitTrailingInlineText(value) {
570
574
  */
571
575
  function checkNeedSplit(str) {
572
576
  // 检查字符串中是否包含需要切割的特殊字符
573
- return str.includes('\\') || str.includes('>') || str.includes('<');
577
+ return str.includes('\\') || /<\/?[A-Za-z][^>]*>/.test(str);
574
578
  }
575
579
 
576
580
  /**
@@ -579,49 +583,29 @@ function checkNeedSplit(str) {
579
583
  * @return {types.CallExpression} - babel的深度扫描的表达式
580
584
  */
581
585
  function convertToTemplateLiteral(strArray, option) {
582
- const quasis = [];
586
+ const quasis = [types__namespace.templateElement({
587
+ raw: '',
588
+ cooked: ''
589
+ }, false)];
583
590
  const expressions = [];
584
- strArray.forEach((str, index) => {
585
- if (index === 0) {
586
- if (getOriginRegex().test(str)) {
587
- quasis.push(types__namespace.templateElement({
588
- raw: '',
589
- cooked: ''
590
- }, false));
591
- expressions.push(createI18nTranslator({
592
- value: str,
593
- isExpression: true,
594
- insertOption: option
595
- }));
596
- } else {
597
- quasis.push(types__namespace.templateElement({
598
- raw: str,
599
- cooked: str
600
- }, false));
601
- }
591
+ strArray.forEach(str => {
592
+ if (getOriginRegex().test(str)) {
593
+ expressions.push(createI18nTranslator({
594
+ value: str,
595
+ isExpression: true,
596
+ insertOption: option
597
+ }));
598
+ quasis.push(types__namespace.templateElement({
599
+ raw: '',
600
+ cooked: ''
601
+ }, false));
602
602
  } else {
603
- if (getOriginRegex().test(str)) {
604
- expressions.push(createI18nTranslator({
605
- value: str,
606
- isExpression: true,
607
- insertOption: option
608
- }));
609
- } else {
610
- quasis.push(types__namespace.templateElement({
611
- raw: str,
612
- cooked: str
613
- }, false));
614
- }
603
+ const quasi = quasis[quasis.length - 1];
604
+ quasi.value.raw += str;
605
+ quasi.value.cooked = `${quasi.value.cooked || ''}${str}`;
615
606
  }
616
607
  });
617
- if (quasis.length === expressions.length) {
618
- quasis.push(types__namespace.templateElement({
619
- raw: '',
620
- cooked: ''
621
- }, true));
622
- } else if (quasis.length > expressions.length) {
623
- quasis[quasis.length - 1].tail = true;
624
- }
608
+ quasis[quasis.length - 1].tail = true;
625
609
  const templateLiteral = types__namespace.templateLiteral(quasis, expressions);
626
610
  const deepScanCall = types__namespace.callExpression(types__namespace.identifier('$deepScan'), [templateLiteral]);
627
611
  // 打印转换结果
@@ -1628,6 +1612,7 @@ function StringLiteralFn (insertOption) {
1628
1612
 
1629
1613
  // 防止导入语句,只处理那些当前节点不是键值对的键的字符串字面量,调用语句判断当前调用语句是否包含需要过滤的调用语句
1630
1614
  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;
1615
+ const vueVNodeCallPath = getVueCompiledVNodeCallPath(path);
1631
1616
  let replaceNode;
1632
1617
  if (option.deepScan && checkNeedSplit(value)) {
1633
1618
  replaceNode = convertToTemplateLiteral(splitByRegex(value, getOriginRegex()), insertOption);
@@ -1646,9 +1631,47 @@ function StringLiteralFn (insertOption) {
1646
1631
  });
1647
1632
  }
1648
1633
  path.replaceWith(replaceNode);
1634
+ markVueCompiledVNodeDynamic(vueVNodeCallPath);
1649
1635
  }
1650
1636
  };
1651
1637
  }
1638
+ function getVueCompiledVNodeCallPath(path) {
1639
+ const callPath = path.parentPath;
1640
+ if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
1641
+ if (!isVueVNodeCreateCall(callPath.node)) return;
1642
+ if (path.listKey !== 'arguments' || path.key !== 2) return;
1643
+ return callPath;
1644
+ }
1645
+ function markVueCompiledVNodeDynamic(callPath) {
1646
+ if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
1647
+ const patchFlag = callPath.node.arguments[3];
1648
+ if (isCachedPatchFlag(patchFlag)) {
1649
+ const textPatchFlag = types__namespace.numericLiteral(1);
1650
+ textPatchFlag.leadingComments = null;
1651
+ textPatchFlag.innerComments = null;
1652
+ textPatchFlag.trailingComments = null;
1653
+ callPath.node.arguments[3] = textPatchFlag;
1654
+ }
1655
+ const logicalPath = callPath.findParent(parentPath => {
1656
+ const node = parentPath.node;
1657
+ if (!types__namespace.isLogicalExpression(node) || node.operator !== '||') return false;
1658
+ const right = node.right;
1659
+ return types__namespace.isAssignmentExpression(right) && right.operator === '=' && right.right === callPath.node && isVueRenderCacheMember(node.left) && isVueRenderCacheMember(right.left);
1660
+ });
1661
+ if (logicalPath) {
1662
+ logicalPath.replaceWith(callPath.node);
1663
+ }
1664
+ }
1665
+ function isCachedPatchFlag(node) {
1666
+ return types__namespace.isNumericLiteral(node) && node.value === -1 || types__namespace.isUnaryExpression(node) && node.operator === '-' && types__namespace.isNumericLiteral(node.argument) && node.argument.value === 1;
1667
+ }
1668
+ function isVueVNodeCreateCall(node) {
1669
+ const callee = node.callee;
1670
+ return types__namespace.isIdentifier(callee) && ['_createElementVNode', '_createVNode', 'createElementVNode', 'createVNode'].includes(callee.name);
1671
+ }
1672
+ function isVueRenderCacheMember(node) {
1673
+ return types__namespace.isMemberExpression(node) && types__namespace.isIdentifier(node.object) && node.object.name === '_cache';
1674
+ }
1652
1675
  function isTranslateCall(node) {
1653
1676
  if (!types__namespace.isCallExpression(node)) return false;
1654
1677
  const callee = node.callee;