sequences.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. make_sequences_1: {
  2. options = {
  3. sequences: true
  4. };
  5. input: {
  6. foo();
  7. bar();
  8. baz();
  9. }
  10. expect: {
  11. foo(),bar(),baz();
  12. }
  13. }
  14. make_sequences_2: {
  15. options = {
  16. sequences: true
  17. };
  18. input: {
  19. if (boo) {
  20. foo();
  21. bar();
  22. baz();
  23. } else {
  24. x();
  25. y();
  26. z();
  27. }
  28. }
  29. expect: {
  30. if (boo) foo(),bar(),baz();
  31. else x(),y(),z();
  32. }
  33. }
  34. make_sequences_3: {
  35. options = {
  36. sequences: true
  37. };
  38. input: {
  39. function f() {
  40. foo();
  41. bar();
  42. return baz();
  43. }
  44. function g() {
  45. foo();
  46. bar();
  47. throw new Error();
  48. }
  49. }
  50. expect: {
  51. function f() {
  52. return foo(), bar(), baz();
  53. }
  54. function g() {
  55. throw foo(), bar(), new Error();
  56. }
  57. }
  58. }
  59. make_sequences_4: {
  60. options = {
  61. sequences: true
  62. };
  63. input: {
  64. x = 5;
  65. if (y) z();
  66. x = 5;
  67. for (i = 0; i < 5; i++) console.log(i);
  68. x = 5;
  69. for (; i < 5; i++) console.log(i);
  70. x = 5;
  71. switch (y) {}
  72. x = 5;
  73. with (obj) {}
  74. }
  75. expect: {
  76. if (x = 5, y) z();
  77. for (x = 5, i = 0; i < 5; i++) console.log(i);
  78. for (x = 5; i < 5; i++) console.log(i);
  79. switch (x = 5, y) {}
  80. with (x = 5, obj);
  81. }
  82. }
  83. lift_sequences_1: {
  84. options = { sequences: true };
  85. input: {
  86. foo = !(x(), y(), bar());
  87. }
  88. expect: {
  89. x(), y(), foo = !bar();
  90. }
  91. }
  92. lift_sequences_2: {
  93. options = { sequences: true, evaluate: true };
  94. input: {
  95. q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5);
  96. }
  97. expect: {
  98. foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36
  99. }
  100. }
  101. lift_sequences_3: {
  102. options = { sequences: true, conditionals: true };
  103. input: {
  104. x = (foo(), bar(), baz()) ? 10 : 20;
  105. }
  106. expect: {
  107. foo(), bar(), x = baz() ? 10 : 20;
  108. }
  109. }
  110. lift_sequences_4: {
  111. options = { side_effects: true };
  112. input: {
  113. x = (foo, bar, baz);
  114. }
  115. expect: {
  116. x = baz;
  117. }
  118. }
  119. for_sequences: {
  120. options = { sequences: true };
  121. input: {
  122. // 1
  123. foo();
  124. bar();
  125. for (; false;);
  126. // 2
  127. foo();
  128. bar();
  129. for (x = 5; false;);
  130. // 3
  131. x = (foo in bar);
  132. for (; false;);
  133. // 4
  134. x = (foo in bar);
  135. for (y = 5; false;);
  136. }
  137. expect: {
  138. // 1
  139. for (foo(), bar(); false;);
  140. // 2
  141. for (foo(), bar(), x = 5; false;);
  142. // 3
  143. x = (foo in bar);
  144. for (; false;);
  145. // 4
  146. x = (foo in bar);
  147. for (y = 5; false;);
  148. }
  149. }