coalesce-logic-expression-mixing.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. test("mixing coalescing and logical operators isn't allowed", () => {
  2. expect("if (0) a ?? b || c").not.toEval();
  3. expect("if (0) a ?? b && c").not.toEval();
  4. expect("if (0) a ?? b * c || d").not.toEval();
  5. expect("if (0) a ?? b * c && d").not.toEval();
  6. expect("if (0) a && b ?? c").not.toEval();
  7. expect("if (0) a || b ?? c").not.toEval();
  8. expect("if (0) a && b * c ?? d").not.toEval();
  9. expect("if (0) a || b * c ?? d").not.toEval();
  10. });
  11. test("mixing coalescing and logical operators with parens", () => {
  12. expect("if (0) a ?? (b || c)").toEval();
  13. expect("if (0) (a ?? b) && c").toEval();
  14. expect("if (0) a ?? (b * c || d)").toEval();
  15. expect("if (0) (a ?? b * c) && d").toEval();
  16. expect("if (0) a && (b ?? c)").toEval();
  17. expect("if (0) (a || b) ?? c").toEval();
  18. expect("if (0) a && (b * c) ?? d").not.toEval();
  19. expect("if (0) a || (b * c) ?? d").not.toEval();
  20. });
  21. test("mixing coalescing and logical operators in ternary expressions", () => {
  22. expect("0 || 0 ? 0 : 0 ?? 0").toEval();
  23. expect("0 ?? 0 ? 0 : 0 || 0").toEval();
  24. expect("0 ? 0 || 0 : 0 ?? 0").toEval();
  25. expect("0 ? 0 ?? 0 : 0 || 0").toEval();
  26. expect("0 && 0 ? 0 ?? 0 : 0 || 0").toEval();
  27. expect("0 ?? 0 ? 0 && 0 : 0 || 0").toEval();
  28. expect("0 ?? 0 ? 0 || 0 : 0 && 0").toEval();
  29. expect("0 || 0 ? 0 ?? 0 : 0 && 0").toEval();
  30. expect("0 && 0 ? 0 || 0 : 0 ?? 0").toEval();
  31. expect("0 || 0 ? 0 && 0 : 0 ?? 0").toEval();
  32. });
  33. test("mixing coalescing and logical operators when 'in' isn't allowed", () => {
  34. expect("for (a ?? b || c in a; false;);").not.toEval();
  35. expect("for (a ?? b && c in a; false;);").not.toEval();
  36. expect("for (a || b ?? c in a; false;);").not.toEval();
  37. expect("for (a && b ?? c in a; false;);").not.toEval();
  38. });