webpack-gc-i18n-plugin 1.1.10 → 1.1.11

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.
@@ -843,6 +843,38 @@ function extractFunctionName(node) {
843
843
  return callName;
844
844
  }
845
845
 
846
+ /**
847
+ * @description 判断调用表达式是否是 console.*(...)
848
+ * 只匹配真实点成员调用,例如 console.log(...) / console.debug(...)。
849
+ */
850
+ function isConsoleMemberCall(node) {
851
+ if (!types.isCallExpression(node) || !types.isMemberExpression(node.callee)) {
852
+ return false;
853
+ }
854
+ const {
855
+ object,
856
+ property,
857
+ computed
858
+ } = node.callee;
859
+ return !computed && types.isIdentifier(object) && object.name === 'console' && types.isIdentifier(property);
860
+ }
861
+
862
+ /**
863
+ * @description 判断当前节点是否位于 console.*(...) 的参数子树中。
864
+ */
865
+ function isInsideConsoleCallArgument(path) {
866
+ let currentPath = path;
867
+ while (currentPath?.parentPath) {
868
+ const parentPath = currentPath.parentPath;
869
+ const parentNode = parentPath.node;
870
+ if (isConsoleMemberCall(parentNode)) {
871
+ return parentNode.arguments.some(arg => arg === currentPath.node);
872
+ }
873
+ currentPath = parentPath;
874
+ }
875
+ return false;
876
+ }
877
+
846
878
  /**
847
879
  * @description: 提取文件的中文部分
848
880
  * @param {string} fileContent
@@ -1022,6 +1054,8 @@ var base = /*#__PURE__*/Object.freeze({
1022
1054
  generateId: generateId,
1023
1055
  getOriginRegex: getOriginRegex,
1024
1056
  hasOriginSymbols: hasOriginSymbols,
1057
+ isConsoleMemberCall: isConsoleMemberCall,
1058
+ isInsideConsoleCallArgument: isInsideConsoleCallArgument,
1025
1059
  normalizeTranslateValue: normalizeTranslateValue,
1026
1060
  removeComments: removeComments,
1027
1061
  truncate: truncate,
@@ -1173,6 +1207,9 @@ function TemplateLiteral (insertOption) {
1173
1207
  if (types.isTaggedTemplateExpression(parent)) {
1174
1208
  return;
1175
1209
  }
1210
+ if (isInsideConsoleCallArgument(path)) {
1211
+ return;
1212
+ }
1176
1213
 
1177
1214
  // 获取真实调用函数
1178
1215
  const extractFnName = extractFunctionName(parent);
@@ -1584,6 +1621,8 @@ function StringLiteralFn (insertOption) {
1584
1621
  }
1585
1622
  }
1586
1623
  if (hasOriginSymbols(value) && option.excludedPattern.length && !checkAgainstRegexArray(value, [...option.excludedPattern])) {
1624
+ if (isInsideConsoleCallArgument(path)) return;
1625
+
1587
1626
  // 获取真实调用函数
1588
1627
  const extractFnName = extractFunctionName(parent);
1589
1628