no-semi.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // with preexisting semi
  2. x; [1, 2, 3].forEach(fn)
  3. x; [a, b, ...c] = [1, 2]
  4. x; /r/i.test('r')
  5. x; +1
  6. x; - 1
  7. x; ('h' + 'i').repeat(10)
  8. x; (1, 2)
  9. x; (() => {})()
  10. x; ({ a: 1 }).entries()
  11. x; ({ a: 1 }).entries()
  12. x; <Hello />
  13. x; `string`
  14. x; (x, y) => x
  15. // doesn't have to be preceded by a semicolon
  16. class X {} [1, 2, 3].forEach(fn)
  17. // TODO: upgrade parser
  18. // class A {
  19. // async; // The semicolon is *not* necessary
  20. // x(){}
  21. // }
  22. // class B {
  23. // static; // The semicolon *is* necessary
  24. // x(){}
  25. // }
  26. class C {
  27. get; // The semicolon *is* necessary
  28. x(){}
  29. }
  30. class C {
  31. get = () => {}; // The semicolon is *not* necessary
  32. x(){}
  33. }
  34. class C {
  35. set; // The semicolon *is* necessary
  36. x(){}
  37. }
  38. class C {
  39. set = () => {}; // The semicolon is *not* necessary
  40. x(){}
  41. }
  42. // don't semicolon if it doesn't start statement
  43. if (true) (() => {})()
  44. class A {
  45. a = 0;
  46. [b](){}
  47. c = 0;
  48. *d(){}
  49. e = 0;
  50. [f] = 0
  51. // none of the semicolons above this comment can be omitted.
  52. // none of the semicolons below this comment are necessary.
  53. q() {};
  54. [h](){}
  55. p() {};
  56. *i(){}
  57. a = 1;
  58. get ['y']() {}
  59. a = 1;
  60. static ['y']() {}
  61. a = 1;
  62. set ['z'](z) {}
  63. a = 1;
  64. async ['a']() {}
  65. a = 1;
  66. async *g() {}
  67. a = 0;
  68. b = 1;
  69. }
  70. // being first/last shouldn't break things
  71. class G {
  72. x = 1
  73. }
  74. class G {
  75. x() {}
  76. }
  77. class G {
  78. *x() {}
  79. }
  80. class G {
  81. [x] = 1
  82. }
  83. // check indentation
  84. if (true) {
  85. x; (() => {})()
  86. }
  87. // flow
  88. (x: void);
  89. (y: void)
  90. // check statement clauses
  91. do break; while (false)
  92. if (true) do break; while (false)
  93. if (true) 1; else 2
  94. for (;;) ;
  95. for (x of y) ;
  96. debugger
  97. // check that it doesn't break non-ASI
  98. 1
  99. - 1
  100. 1
  101. + 1
  102. 1
  103. / 1
  104. arr
  105. [0]
  106. fn
  107. (x)
  108. !1
  109. 1
  110. < 1
  111. tag
  112. `string`
  113. x; x => x
  114. x; (a || b).c++
  115. x; ++(a || b).c
  116. while (false)
  117. (function(){}())
  118. aReallyLongLine012345678901234567890123456789012345678901234567890123456789 *
  119. (b + c)