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.
package/dist/index.cjs CHANGED
@@ -50,7 +50,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
50
50
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
51
51
  PERFORMANCE OF THIS SOFTWARE.
52
52
  ***************************************************************************** */
53
- /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
53
+ /* global Reflect, Promise, SuppressedError, Symbol */
54
54
 
55
55
  var __assign = function () {
56
56
  __assign = Object.assign || function __assign(t) {
@@ -102,8 +102,12 @@ function __generator(thisArg, body) {
102
102
  f,
103
103
  y,
104
104
  t,
105
- g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
106
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function () {
105
+ g;
106
+ return g = {
107
+ next: verb(0),
108
+ "throw": verb(1),
109
+ "return": verb(2)
110
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
107
111
  return this;
108
112
  }), g;
109
113
  function verb(n) {
@@ -1069,7 +1073,7 @@ function splitTrailingInlineText(value) {
1069
1073
  */
1070
1074
  function checkNeedSplit(str) {
1071
1075
  // 检查字符串中是否包含需要切割的特殊字符
1072
- return str.includes('\\') || str.includes('>') || str.includes('<');
1076
+ return str.includes('\\') || /<\/?[A-Za-z][^>]*>/.test(str);
1073
1077
  }
1074
1078
 
1075
1079
  /**
@@ -1078,49 +1082,29 @@ function checkNeedSplit(str) {
1078
1082
  * @return {types.CallExpression} - babel的深度扫描的表达式
1079
1083
  */
1080
1084
  function convertToTemplateLiteral(strArray, option) {
1081
- const quasis = [];
1085
+ const quasis = [types__namespace.templateElement({
1086
+ raw: '',
1087
+ cooked: ''
1088
+ }, false)];
1082
1089
  const expressions = [];
1083
- strArray.forEach((str, index) => {
1084
- if (index === 0) {
1085
- if (getOriginRegex().test(str)) {
1086
- quasis.push(types__namespace.templateElement({
1087
- raw: '',
1088
- cooked: ''
1089
- }, false));
1090
- expressions.push(createI18nTranslator({
1091
- value: str,
1092
- isExpression: true,
1093
- insertOption: option
1094
- }));
1095
- } else {
1096
- quasis.push(types__namespace.templateElement({
1097
- raw: str,
1098
- cooked: str
1099
- }, false));
1100
- }
1090
+ strArray.forEach(str => {
1091
+ if (getOriginRegex().test(str)) {
1092
+ expressions.push(createI18nTranslator({
1093
+ value: str,
1094
+ isExpression: true,
1095
+ insertOption: option
1096
+ }));
1097
+ quasis.push(types__namespace.templateElement({
1098
+ raw: '',
1099
+ cooked: ''
1100
+ }, false));
1101
1101
  } else {
1102
- if (getOriginRegex().test(str)) {
1103
- expressions.push(createI18nTranslator({
1104
- value: str,
1105
- isExpression: true,
1106
- insertOption: option
1107
- }));
1108
- } else {
1109
- quasis.push(types__namespace.templateElement({
1110
- raw: str,
1111
- cooked: str
1112
- }, false));
1113
- }
1102
+ const quasi = quasis[quasis.length - 1];
1103
+ quasi.value.raw += str;
1104
+ quasi.value.cooked = `${quasi.value.cooked || ''}${str}`;
1114
1105
  }
1115
1106
  });
1116
- if (quasis.length === expressions.length) {
1117
- quasis.push(types__namespace.templateElement({
1118
- raw: '',
1119
- cooked: ''
1120
- }, true));
1121
- } else if (quasis.length > expressions.length) {
1122
- quasis[quasis.length - 1].tail = true;
1123
- }
1107
+ quasis[quasis.length - 1].tail = true;
1124
1108
  const templateLiteral = types__namespace.templateLiteral(quasis, expressions);
1125
1109
  const deepScanCall = types__namespace.callExpression(types__namespace.identifier('$deepScan'), [templateLiteral]);
1126
1110
  // 打印转换结果
@@ -2986,6 +2970,7 @@ function StringLiteralFn (insertOption) {
2986
2970
 
2987
2971
  // 防止导入语句,只处理那些当前节点不是键值对的键的字符串字面量,调用语句判断当前调用语句是否包含需要过滤的调用语句
2988
2972
  if (isTranslateCall(parent) || types__namespace.isImportDeclaration(parent) || parent.key === node || types__namespace.isCallExpression(parent) && extractFnName && (exports.option.excludedCall.includes(extractFnName) || extractFnName?.split('.')?.pop() && exports.option.excludedCall.includes(extractFnName?.split('.')?.pop() || ''))) return;
2973
+ const vueVNodeCallPath = getVueCompiledVNodeCallPath(path);
2989
2974
  let replaceNode;
2990
2975
  if (exports.option.deepScan && checkNeedSplit(value)) {
2991
2976
  replaceNode = convertToTemplateLiteral(splitByRegex(value, getOriginRegex()), insertOption);
@@ -3004,9 +2989,47 @@ function StringLiteralFn (insertOption) {
3004
2989
  });
3005
2990
  }
3006
2991
  path.replaceWith(replaceNode);
2992
+ markVueCompiledVNodeDynamic(vueVNodeCallPath);
3007
2993
  }
3008
2994
  };
3009
2995
  }
2996
+ function getVueCompiledVNodeCallPath(path) {
2997
+ const callPath = path.parentPath;
2998
+ if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
2999
+ if (!isVueVNodeCreateCall(callPath.node)) return;
3000
+ if (path.listKey !== 'arguments' || path.key !== 2) return;
3001
+ return callPath;
3002
+ }
3003
+ function markVueCompiledVNodeDynamic(callPath) {
3004
+ if (!callPath || !types__namespace.isCallExpression(callPath.node)) return;
3005
+ const patchFlag = callPath.node.arguments[3];
3006
+ if (isCachedPatchFlag(patchFlag)) {
3007
+ const textPatchFlag = types__namespace.numericLiteral(1);
3008
+ textPatchFlag.leadingComments = null;
3009
+ textPatchFlag.innerComments = null;
3010
+ textPatchFlag.trailingComments = null;
3011
+ callPath.node.arguments[3] = textPatchFlag;
3012
+ }
3013
+ const logicalPath = callPath.findParent(parentPath => {
3014
+ const node = parentPath.node;
3015
+ if (!types__namespace.isLogicalExpression(node) || node.operator !== '||') return false;
3016
+ const right = node.right;
3017
+ return types__namespace.isAssignmentExpression(right) && right.operator === '=' && right.right === callPath.node && isVueRenderCacheMember(node.left) && isVueRenderCacheMember(right.left);
3018
+ });
3019
+ if (logicalPath) {
3020
+ logicalPath.replaceWith(callPath.node);
3021
+ }
3022
+ }
3023
+ function isCachedPatchFlag(node) {
3024
+ return types__namespace.isNumericLiteral(node) && node.value === -1 || types__namespace.isUnaryExpression(node) && node.operator === '-' && types__namespace.isNumericLiteral(node.argument) && node.argument.value === 1;
3025
+ }
3026
+ function isVueVNodeCreateCall(node) {
3027
+ const callee = node.callee;
3028
+ return types__namespace.isIdentifier(callee) && ['_createElementVNode', '_createVNode', 'createElementVNode', 'createVNode'].includes(callee.name);
3029
+ }
3030
+ function isVueRenderCacheMember(node) {
3031
+ return types__namespace.isMemberExpression(node) && types__namespace.isIdentifier(node.object) && node.object.name === '_cache';
3032
+ }
3010
3033
  function isTranslateCall(node) {
3011
3034
  if (!types__namespace.isCallExpression(node)) return false;
3012
3035
  const callee = node.callee;