td-web-cli 0.1.25 → 0.1.26
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/i18n/extractEntry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/i18n/extractEntry/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsWpC;;GAEG;AACH,wBAAsB,YAAY,CAAC,OAAO,EAAE,OAAO,iBAkNlD"}
|
|
@@ -73,6 +73,7 @@ function extractStringsFromExpression(expr) {
|
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* 使用 Babel AST 从 JavaScript/TypeScript/JSX 代码中提取包含中文的字符串
|
|
76
|
+
* 注意:Babel 解析时会自动忽略注释,因此注释中的中文不会被提取
|
|
76
77
|
*/
|
|
77
78
|
function extractFromJS(code) {
|
|
78
79
|
const strings = new Set();
|
|
@@ -117,7 +118,7 @@ function extractFromVue(content) {
|
|
|
117
118
|
var _a, _b;
|
|
118
119
|
const strings = new Set();
|
|
119
120
|
const { descriptor } = vueParse(content);
|
|
120
|
-
// 处理 script
|
|
121
|
+
// 处理 script 部分(注释已被 Babel 解析忽略)
|
|
121
122
|
if (descriptor.script || descriptor.scriptSetup) {
|
|
122
123
|
const scriptContent = ((_a = descriptor.script) === null || _a === void 0 ? void 0 : _a.content) || ((_b = descriptor.scriptSetup) === null || _b === void 0 ? void 0 : _b.content) || '';
|
|
123
124
|
if (scriptContent) {
|
|
@@ -132,7 +133,9 @@ function extractFromVue(content) {
|
|
|
132
133
|
}
|
|
133
134
|
// 处理 template 部分
|
|
134
135
|
if (descriptor.template) {
|
|
135
|
-
|
|
136
|
+
// 移除 HTML 注释,避免提取注释中的中文
|
|
137
|
+
let templateContent = descriptor.template.content;
|
|
138
|
+
templateContent = templateContent.replace(/<!--[\s\S]*?-->/g, '');
|
|
136
139
|
// 1. 提取文本节点中的中文
|
|
137
140
|
const textRegex = />([^<]+)</g;
|
|
138
141
|
let match;
|
|
@@ -178,6 +181,7 @@ function extractFromVue(content) {
|
|
|
178
181
|
}
|
|
179
182
|
/**
|
|
180
183
|
* 使用 node-html-parser 解析 HTML 文件
|
|
184
|
+
* 注意:HTML 注释节点(nodeType 8)会被自动忽略,因此注释中的中文不会被提取
|
|
181
185
|
*/
|
|
182
186
|
function extractFromHTML(html) {
|
|
183
187
|
const strings = new Set();
|
|
@@ -228,6 +232,7 @@ function extractFromHTML(html) {
|
|
|
228
232
|
node.childNodes.forEach((child) => walk(child));
|
|
229
233
|
}
|
|
230
234
|
}
|
|
235
|
+
// 注释节点(nodeType 8)不处理,直接忽略
|
|
231
236
|
}
|
|
232
237
|
walk(root);
|
|
233
238
|
return strings;
|