@dongmingzhixiu/vuexir-compiler 0.3.16 → 0.3.17
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/codegen/compose.js
CHANGED
|
@@ -434,6 +434,14 @@ function kotlinCondExpr(expr) {
|
|
|
434
434
|
return `vrnField(${f[1]}, "${f[2]}").isNotEmpty()`;
|
|
435
435
|
let s = expr.replace(/!==/g, '!=').replace(/===/g, '==');
|
|
436
436
|
s = s.replace(/'(\\[^]|[^'\\])*'/g, (m) => '"' + m.slice(1, -1).replace(/"/g, '\\"') + '"');
|
|
437
|
+
// R111:Kotlin 不接受 String/Int 当条件 → 统一判真
|
|
438
|
+
const neg = s.match(/^!([A-Za-z_$][\w$]*)(?:\.length)?$/);
|
|
439
|
+
if (neg)
|
|
440
|
+
return `vrnTruthy(${neg[1]}.toString()).not()`;
|
|
441
|
+
if (/^[A-Za-z_$][\w$]*\.length$/.test(s))
|
|
442
|
+
return `${s} > 0`;
|
|
443
|
+
if (/^[A-Za-z_$][\w$]*$/.test(s) && !['true', 'false'].includes(s))
|
|
444
|
+
return `vrnTruthy(${s}.toString())`;
|
|
437
445
|
return s;
|
|
438
446
|
}
|
|
439
447
|
/** Swift 风格字符串表达式 → Kotlin(三元 c ? a : b → if (c) a else b;引号归一双引号) */
|
|
@@ -1034,10 +1042,10 @@ function emitNodeInner(node, ctx, depth, loop, useParamModifier = false, parentS
|
|
|
1034
1042
|
pre += cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.width(' + dp(cp.marginLeft) + '),\n' + cpad + ')\n';
|
|
1035
1043
|
}
|
|
1036
1044
|
if (kind === 'Row' && cp.marginRight !== undefined) {
|
|
1037
|
-
post = post + cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.width(' + dp(cp.marginRight) + '),\n' + cpad + ')\n';
|
|
1045
|
+
post = post + '\n' + cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.width(' + dp(cp.marginRight) + '),\n' + cpad + ')\n';
|
|
1038
1046
|
}
|
|
1039
1047
|
if (kind === 'Column' && cp.marginBottom !== undefined) {
|
|
1040
|
-
post = post + cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.height(' + dp(cp.marginBottom) + '),\n' + cpad + ')\n';
|
|
1048
|
+
post = post + '\n' + cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.height(' + dp(cp.marginBottom) + '),\n' + cpad + ')\n';
|
|
1041
1049
|
}
|
|
1042
1050
|
const stretch = kind === 'Column' && cp.width === undefined && cp.flex === undefined && cp.position !== 'absolute' && !cp.marginLeftAuto;
|
|
1043
1051
|
return pre + emitNode(c, ctx, d, undefined, false, stretch) + post;
|
package/dist/codegen/swiftui.js
CHANGED
|
@@ -530,6 +530,12 @@ function swiftCondExpr(expr) {
|
|
|
530
530
|
// R110:裸标识符条件(状态可能是字符串/对象/布尔)→ 统一走判真
|
|
531
531
|
if (/^[A-Za-z_$][\w$]*$/.test(s) && !['true', 'false'].includes(s))
|
|
532
532
|
return `vrnTruthy(String(${s}))`;
|
|
533
|
+
// R112:循环项字段的 && 组合(item && item.cd)→ 判真
|
|
534
|
+
const andExpr = s.match(/^([A-Za-z_$][\w$.]*)\s*&&\s*([A-Za-z_$][\w$.]*)$/);
|
|
535
|
+
if (andExpr) {
|
|
536
|
+
const truthy = (v) => (v.includes('.') ? `!vrnField(${v.split('.')[0]}, "${v.split('.').slice(1).join('.')}").isEmpty` : `vrnTruthy(String(${v}))`);
|
|
537
|
+
return `${truthy(andExpr[1])} && ${truthy(andExpr[2])}`;
|
|
538
|
+
}
|
|
533
539
|
return s;
|
|
534
540
|
}
|
|
535
541
|
function emitNodeInner(node, ctx) {
|
package/dist/transform/vue2ir.js
CHANGED
|
@@ -1416,9 +1416,13 @@ function parseTernaryExpr(exp) {
|
|
|
1416
1416
|
const m = t.match(/^(.+?)\s*\?\s*'([^']+)'\s*:\s*'([^']+)'$/);
|
|
1417
1417
|
if (!m)
|
|
1418
1418
|
return null;
|
|
1419
|
-
|
|
1419
|
+
let cond = swiftExpr(m[1]);
|
|
1420
1420
|
if (cond === null)
|
|
1421
1421
|
return null;
|
|
1422
|
+
// R112:三元条件里的字符串/数字状态要判真(Swift/Kotlin 不接受非 Bool 条件)
|
|
1423
|
+
if (/^[A-Za-z_$][\w$]*$/.test(cond) && !['true', 'false'].includes(cond)) {
|
|
1424
|
+
cond = `vrnTruthy(String(${cond}))`;
|
|
1425
|
+
}
|
|
1422
1426
|
return `${cond} ? "${m[2]}" : "${m[3]}"`;
|
|
1423
1427
|
}
|
|
1424
1428
|
/**
|