webpack-gc-i18n-plugin 1.1.12 → 1.1.14
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/customLoader/index.cjs +26 -41
- package/dist/customLoader/index.cjs.map +1 -1
- package/dist/customLoader/index.mjs +26 -41
- package/dist/customLoader/index.mjs.map +1 -1
- package/dist/index.cjs +26 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +26 -41
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -570,7 +570,7 @@ function splitTrailingInlineText(value) {
|
|
|
570
570
|
*/
|
|
571
571
|
function checkNeedSplit(str) {
|
|
572
572
|
// 检查字符串中是否包含需要切割的特殊字符
|
|
573
|
-
return str.includes('\\') ||
|
|
573
|
+
return str.includes('\\') || /<\/?[A-Za-z][^>]*>/.test(str);
|
|
574
574
|
}
|
|
575
575
|
|
|
576
576
|
/**
|
|
@@ -579,49 +579,29 @@ function checkNeedSplit(str) {
|
|
|
579
579
|
* @return {types.CallExpression} - babel的深度扫描的表达式
|
|
580
580
|
*/
|
|
581
581
|
function convertToTemplateLiteral(strArray, option) {
|
|
582
|
-
const quasis = [
|
|
582
|
+
const quasis = [types__namespace.templateElement({
|
|
583
|
+
raw: '',
|
|
584
|
+
cooked: ''
|
|
585
|
+
}, false)];
|
|
583
586
|
const expressions = [];
|
|
584
|
-
strArray.forEach(
|
|
585
|
-
if (
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
}));
|
|
596
|
-
} else {
|
|
597
|
-
quasis.push(types__namespace.templateElement({
|
|
598
|
-
raw: str,
|
|
599
|
-
cooked: str
|
|
600
|
-
}, false));
|
|
601
|
-
}
|
|
587
|
+
strArray.forEach(str => {
|
|
588
|
+
if (getOriginRegex().test(str)) {
|
|
589
|
+
expressions.push(createI18nTranslator({
|
|
590
|
+
value: str,
|
|
591
|
+
isExpression: true,
|
|
592
|
+
insertOption: option
|
|
593
|
+
}));
|
|
594
|
+
quasis.push(types__namespace.templateElement({
|
|
595
|
+
raw: '',
|
|
596
|
+
cooked: ''
|
|
597
|
+
}, false));
|
|
602
598
|
} else {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
isExpression: true,
|
|
607
|
-
insertOption: option
|
|
608
|
-
}));
|
|
609
|
-
} else {
|
|
610
|
-
quasis.push(types__namespace.templateElement({
|
|
611
|
-
raw: str,
|
|
612
|
-
cooked: str
|
|
613
|
-
}, false));
|
|
614
|
-
}
|
|
599
|
+
const quasi = quasis[quasis.length - 1];
|
|
600
|
+
quasi.value.raw += str;
|
|
601
|
+
quasi.value.cooked = `${quasi.value.cooked || ''}${str}`;
|
|
615
602
|
}
|
|
616
603
|
});
|
|
617
|
-
|
|
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
|
-
}
|
|
604
|
+
quasis[quasis.length - 1].tail = true;
|
|
625
605
|
const templateLiteral = types__namespace.templateLiteral(quasis, expressions);
|
|
626
606
|
const deepScanCall = types__namespace.callExpression(types__namespace.identifier('$deepScan'), [templateLiteral]);
|
|
627
607
|
// 打印转换结果
|
|
@@ -717,7 +697,12 @@ function hasOriginSymbols$1(value) {
|
|
|
717
697
|
const originRegex = REGEX_MAP[option.originLang];
|
|
718
698
|
return originRegex ? originRegex.test(value) : false;
|
|
719
699
|
}
|
|
700
|
+
function isTemplateFragmentSegment(value) {
|
|
701
|
+
return /[^\p{Script=Han}A-Za-z0-9_\s]/u.test(value);
|
|
702
|
+
}
|
|
720
703
|
function getTemplateSemanticSplitSegments(value) {
|
|
704
|
+
const expressionCount = value.match(/\$\{[^}]+}/g)?.length || 0;
|
|
705
|
+
if (expressionCount < 2) return [];
|
|
721
706
|
const segments = value.split(/\$\{[^}]+}/g);
|
|
722
707
|
const result = new Set();
|
|
723
708
|
for (let index = 0; index < segments.length - 1; index++) {
|
|
@@ -725,7 +710,7 @@ function getTemplateSemanticSplitSegments(value) {
|
|
|
725
710
|
const afterValue = segments[index + 1];
|
|
726
711
|
if (!hasOriginSymbols$1(beforeValue) || !hasOriginSymbols$1(afterValue)) continue;
|
|
727
712
|
[beforeValue, afterValue].forEach(segment => {
|
|
728
|
-
if (segment.trim().length > 1) {
|
|
713
|
+
if (segment.trim().length > 1 && isTemplateFragmentSegment(segment)) {
|
|
729
714
|
result.add(segment);
|
|
730
715
|
}
|
|
731
716
|
});
|