vue-i18n-extract-plugin 1.0.71 → 1.0.72
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/lib/visitors.js +37 -2
- package/package.json +1 -1
package/lib/visitors.js
CHANGED
|
@@ -187,6 +187,38 @@ function unwrapVueCacheIfNeeded(path) {
|
|
|
187
187
|
return true;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
function unwrapVueSlotArrayCache(path) {
|
|
191
|
+
// 1. 找 ArrayExpression
|
|
192
|
+
const arrayPath = path.findParent(p => p.isArrayExpression());
|
|
193
|
+
if (!arrayPath) return false;
|
|
194
|
+
|
|
195
|
+
// 2. array 是 assignment 的 right
|
|
196
|
+
const assignPath = arrayPath.parentPath;
|
|
197
|
+
if (!assignPath?.isAssignmentExpression({ operator: "=" })) return false;
|
|
198
|
+
|
|
199
|
+
// 3. assignment 在 LogicalExpression || 中
|
|
200
|
+
const logicalPath = assignPath.parentPath;
|
|
201
|
+
if (!logicalPath?.isLogicalExpression({ operator: "||" })) return false;
|
|
202
|
+
|
|
203
|
+
// 4. logical 在 SpreadElement 中
|
|
204
|
+
const spreadPath = logicalPath.parentPath;
|
|
205
|
+
if (!spreadPath?.isSpreadElement()) return false;
|
|
206
|
+
|
|
207
|
+
// 5. 校验 _cache[x]
|
|
208
|
+
const left = logicalPath.node.left;
|
|
209
|
+
const isCache =
|
|
210
|
+
t.isMemberExpression(left) &&
|
|
211
|
+
t.isIdentifier(left.object) &&
|
|
212
|
+
left.object.name.startsWith("_cache");
|
|
213
|
+
|
|
214
|
+
if (!isCache) return false;
|
|
215
|
+
|
|
216
|
+
// unwrap:用 array.elements 替换 spread(...)
|
|
217
|
+
spreadPath.replaceWithMultiple(arrayPath.node.elements);
|
|
218
|
+
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
|
|
190
222
|
function isDynamicTextExpression(node) {
|
|
191
223
|
// 只要不是 StringLiteral,100% 是动态文本
|
|
192
224
|
return !t.isStringLiteral(node);
|
|
@@ -309,8 +341,11 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
309
341
|
if (isVNodeCall(parentPath, "_createTextVNode")) {
|
|
310
342
|
// createTextVNode强制补充第二个参数 1
|
|
311
343
|
parentPath.node.arguments = [callExpression, t.numericLiteral(1)];
|
|
312
|
-
//
|
|
313
|
-
|
|
344
|
+
// 先尝试 [...(_cache2[4] || (_cache2[4] = [ createTextVNode(...) ]))]
|
|
345
|
+
if (!unwrapVueSlotArrayCache(parentPath)) {
|
|
346
|
+
// 再尝试拆 _cache2[0] || (_cache2[0] = createTextVNode(...))
|
|
347
|
+
unwrapVueCacheIfNeeded(parentPath);
|
|
348
|
+
}
|
|
314
349
|
// 是否 vue.createElementVNode(...),且该 StringLiteral 是第三个参数
|
|
315
350
|
} else if (isVNodeCall(parentPath, "_createElementVNode")) {
|
|
316
351
|
const callExpr = parentPath.node;
|