@dongmingzhixiu/vuexir-compiler 0.3.15 → 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.
@@ -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;引号归一双引号) */
@@ -701,7 +709,12 @@ function kotlinClickAction(p, ctx, loop) {
701
709
  return dec[1] + ' = ' + dec[1] + ' - 1';
702
710
  const push = h.match(/router(?:\.push|Push)?\(\s*(.+?)\s*\)/);
703
711
  if (push) {
704
- const arg = push[1].trim();
712
+ const arg0 = push[1].trim();
713
+ // R111:router.push({ name: 'x' }) / { path: 'x' } → 只取目标值(Kotlin 里对象字面量会被当 lambda)
714
+ const objM = arg0.match(/^\{[^}]*?(?:name|path)\s*:\s*['"]([^'"]+)['"]/);
715
+ if (objM)
716
+ return 'Runtime.push("' + objM[1] + '")';
717
+ const arg = arg0;
705
718
  const isLit = (arg.startsWith("'") && arg.endsWith("'")) || (arg.startsWith('"') && arg.endsWith('"'));
706
719
  if (isLit)
707
720
  return 'Runtime.push(' + kotlinStr(arg.slice(1, -1)) + ')';
@@ -960,7 +973,7 @@ function emitNode(node, ctx, depth, loop, useParamModifier = false, parentStretc
960
973
  if (node.condition && node.type !== 'root') {
961
974
  return (pad + 'if (' + kotlinCondExpr(node.condition) + ') {\n' +
962
975
  emitNodeInner(node, ctx, depth + 1, loop, useParamModifier, parentStretch) +
963
- '\n' + pad + '}');
976
+ '\n' + pad + '}\n');
964
977
  }
965
978
  return emitNodeInner(node, ctx, depth, loop, useParamModifier, parentStretch);
966
979
  }
@@ -1029,10 +1042,10 @@ function emitNodeInner(node, ctx, depth, loop, useParamModifier = false, parentS
1029
1042
  pre += cpad + 'Spacer(\n' + cpad + ' modifier = Modifier.width(' + dp(cp.marginLeft) + '),\n' + cpad + ')\n';
1030
1043
  }
1031
1044
  if (kind === 'Row' && cp.marginRight !== undefined) {
1032
- 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';
1033
1046
  }
1034
1047
  if (kind === 'Column' && cp.marginBottom !== undefined) {
1035
- 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';
1036
1049
  }
1037
1050
  const stretch = kind === 'Column' && cp.width === undefined && cp.flex === undefined && cp.position !== 'absolute' && !cp.marginLeftAuto;
1038
1051
  return pre + emitNode(c, ctx, d, undefined, false, stretch) + post;
@@ -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) {
@@ -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
- const cond = swiftExpr(m[1]);
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
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dongmingzhixiu/vuexir-compiler",
3
- "version": "0.3.15",
3
+ "version": "0.3.17",
4
4
  "description": "Vue SFC → IR → 原生源码(SwiftUI / Compose)编译器核心:纯函数、零 IO",
5
5
  "type": "module",
6
6
  "license": "MIT",