/tests/cases/conformance/statements/ifDoWhileStatements/ifDoWhileStatements.ts

https://gitlab.com/jimlamb/TypeScript · TypeScript · 163 lines · 122 code · 38 blank · 3 comment · 54 complexity · 023d6812ac0806a099c9445f428a2091 MD5 · raw file

  1. // @allowUnreachableCode: true
  2. interface I {
  3. id: number;
  4. }
  5. class C implements I {
  6. id: number;
  7. name: string;
  8. }
  9. class C2 extends C {
  10. valid: boolean;
  11. }
  12. class D<T>{
  13. source: T;
  14. recurse: D<T>;
  15. wrapped: D<D<T>>
  16. }
  17. function F(x: string): number { return 42; }
  18. function F2(x: number): boolean { return x < 42; }
  19. module M {
  20. export class A {
  21. name: string;
  22. }
  23. export function F2(x: number): string { return x.toString(); }
  24. }
  25. module N {
  26. export class A {
  27. id: number;
  28. }
  29. export function F2(x: number): string { return x.toString(); }
  30. }
  31. // literals
  32. if (true) { }
  33. while (true) { }
  34. do { }while(true)
  35. if (null) { }
  36. while (null) { }
  37. do { }while(null)
  38. if (undefined) { }
  39. while (undefined) { }
  40. do { }while(undefined)
  41. if (0.0) { }
  42. while (0.0) { }
  43. do { }while(0.0)
  44. if ('a string') { }
  45. while ('a string') { }
  46. do { }while('a string')
  47. if ('') { }
  48. while ('') { }
  49. do { }while('')
  50. if (/[a-z]/) { }
  51. while (/[a-z]/) { }
  52. do { }while(/[a-z]/)
  53. if ([]) { }
  54. while ([]) { }
  55. do { }while([])
  56. if ([1, 2]) { }
  57. while ([1, 2]) { }
  58. do { }while([1, 2])
  59. if ({}) { }
  60. while ({}) { }
  61. do { }while({})
  62. if ({ x: 1, y: 'a' }) { }
  63. while ({ x: 1, y: 'a' }) { }
  64. do { }while({ x: 1, y: 'a' })
  65. if (() => 43) { }
  66. while (() => 43) { }
  67. do { }while(() => 43)
  68. if (new C()) { }
  69. while (new C()) { }
  70. do { }while(new C())
  71. if (new D<C>()) { }
  72. while (new D<C>()) { }
  73. do { }while(new D<C>())
  74. // references
  75. var a = true;
  76. if (a) { }
  77. while (a) { }
  78. do { }while(a)
  79. var b = null;
  80. if (b) { }
  81. while (b) { }
  82. do { }while(b)
  83. var c = undefined;
  84. if (c) { }
  85. while (c) { }
  86. do { }while(c)
  87. var d = 0.0;
  88. if (d) { }
  89. while (d) { }
  90. do { }while(d)
  91. var e = 'a string';
  92. if (e) { }
  93. while (e) { }
  94. do { }while(e)
  95. var f = '';
  96. if (f) { }
  97. while (f) { }
  98. do { }while(f)
  99. var g = /[a-z]/
  100. if (g) { }
  101. while (g) { }
  102. do { }while(g)
  103. var h = [];
  104. if (h) { }
  105. while (h) { }
  106. do { }while(h)
  107. var i = [1, 2];
  108. if (i) { }
  109. while (i) { }
  110. do { }while(i)
  111. var j = {};
  112. if (j) { }
  113. while (j) { }
  114. do { }while(j)
  115. var k = { x: 1, y: 'a' };
  116. if (k) { }
  117. while (k) { }
  118. do { }while(k)
  119. function fn(x?: string): I { return null; }
  120. if (fn()) { }
  121. while (fn()) { }
  122. do { }while(fn())
  123. if (fn) { }
  124. while (fn) { }
  125. do { }while(fn)