vue-i18n-extract-plugin 1.0.72 → 1.0.73
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 +16 -12
- 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,23 @@ 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
350
|
} else if (isVNodeCall(parentPath, "_createElementVNode")) {
|
|
351
351
|
const callExpr = parentPath.node;
|
|
352
352
|
const args = callExpr.arguments;
|
|
353
|
-
|
|
354
|
-
// 当前是第三个参数,且参数数量为3
|
|
353
|
+
// 第 3 个参数是 children
|
|
355
354
|
const argIndex = args.findIndex(arg => arg === path.node);
|
|
356
|
-
if (argIndex === 2
|
|
357
|
-
args[2] = callExpression;
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
if (argIndex === 2) {
|
|
356
|
+
args[2] = callExpression;
|
|
357
|
+
// 强制 patchFlag = 1
|
|
358
|
+
if (args.length < 4) {
|
|
359
|
+
args.push(t.numericLiteral(1));
|
|
360
|
+
} else {
|
|
361
|
+
args[3] = t.numericLiteral(1);
|
|
362
|
+
}
|
|
363
|
+
unwrapVueCacheCallIfNeeded(parentPath);
|
|
360
364
|
}
|
|
361
365
|
} else {
|
|
362
366
|
const hasCreateVNode = transformDirectiveIfNeeded(path, parentPath);
|