vue-i18n-extract-plugin 1.0.72 → 1.0.74
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 +28 -13
- package/package.json +1 -1
package/lib/visitors.js
CHANGED
|
@@ -153,14 +153,14 @@ function generateJSXElement(name, id, msg) {
|
|
|
153
153
|
return t.jsxElement(openingElement, null, [], true);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
function
|
|
156
|
+
function unwrapVueCacheCallIfNeeded(path) {
|
|
157
157
|
const assignPath = path.parentPath;
|
|
158
|
-
if (!assignPath
|
|
158
|
+
if (!assignPath?.isAssignmentExpression({ operator: "=" })) {
|
|
159
159
|
return false;
|
|
160
160
|
}
|
|
161
161
|
|
|
162
162
|
const logicalPath = assignPath.parentPath;
|
|
163
|
-
if (!logicalPath
|
|
163
|
+
if (!logicalPath?.isLogicalExpression({ operator: "||" })) {
|
|
164
164
|
return false;
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -169,8 +169,8 @@ function unwrapVueCacheIfNeeded(path) {
|
|
|
169
169
|
// 校验 left: _cache[x]
|
|
170
170
|
const isCacheMember =
|
|
171
171
|
t.isMemberExpression(left) &&
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
t.isIdentifier(left.object) &&
|
|
173
|
+
left.object.name.startsWith("_cache");
|
|
174
174
|
|
|
175
175
|
// 校验 right: (_cache[x] = createTextVNode(...))
|
|
176
176
|
const isSameAssignment =
|
|
@@ -344,19 +344,34 @@ function createI18nVisitor(option, i18nMap) {
|
|
|
344
344
|
// 先尝试 [...(_cache2[4] || (_cache2[4] = [ createTextVNode(...) ]))]
|
|
345
345
|
if (!unwrapVueSlotArrayCache(parentPath)) {
|
|
346
346
|
// 再尝试拆 _cache2[0] || (_cache2[0] = createTextVNode(...))
|
|
347
|
-
|
|
347
|
+
unwrapVueCacheCallIfNeeded(parentPath);
|
|
348
348
|
}
|
|
349
349
|
// 是否 vue.createElementVNode(...),且该 StringLiteral 是第三个参数
|
|
350
|
-
} else if (
|
|
350
|
+
} else if (
|
|
351
|
+
isVNodeCall(parentPath, "_createElementVNode") ||
|
|
352
|
+
isVNodeCall(parentPath, "_createElementBlock")
|
|
353
|
+
) {
|
|
351
354
|
const callExpr = parentPath.node;
|
|
352
355
|
const args = callExpr.arguments;
|
|
353
|
-
|
|
354
|
-
// 当前是第三个参数,且参数数量为3
|
|
356
|
+
// 第 3 个参数是 children
|
|
355
357
|
const argIndex = args.findIndex(arg => arg === path.node);
|
|
356
|
-
if (argIndex === 2
|
|
357
|
-
args[2] = callExpression;
|
|
358
|
-
|
|
359
|
-
|
|
358
|
+
if (argIndex === 2) {
|
|
359
|
+
args[2] = callExpression;
|
|
360
|
+
// 强制 patchFlag = 1
|
|
361
|
+
if (args.length < 4) {
|
|
362
|
+
args.push(t.numericLiteral(1));
|
|
363
|
+
} else {
|
|
364
|
+
args[3] = t.numericLiteral(1);
|
|
365
|
+
}
|
|
366
|
+
// 先尝试 [...(_cache2[4] || (_cache2[4] = [ createTextVNode(...) ]))]
|
|
367
|
+
if (!unwrapVueSlotArrayCache(parentPath)) {
|
|
368
|
+
// 再尝试拆 _cache2[0] || (_cache2[0] = createTextVNode(...))
|
|
369
|
+
unwrapVueCacheCallIfNeeded(parentPath);
|
|
370
|
+
}
|
|
371
|
+
// 顶多再往上找一层
|
|
372
|
+
if (!unwrapVueSlotArrayCache(parentPath.parentPath.parentPath)) {
|
|
373
|
+
unwrapVueCacheCallIfNeeded(parentPath.parentPath.parentPath);
|
|
374
|
+
}
|
|
360
375
|
}
|
|
361
376
|
} else {
|
|
362
377
|
const hasCreateVNode = transformDirectiveIfNeeded(path, parentPath);
|