BVB Source Codes

prettier Show rebinding.js Source code

Return Download prettier: download rebinding.js Source code - Download prettier Source code - Type:.js
  1. /* @flow
  2.  * test errors on illegal rebinding/reassignment
  3.  *
  4.  *       type class let const var (reassign)
  5.  * type  x    x      x   x     x   x
  6.  * class x    x      x   x     x
  7.  * let   x    x      x   x     x
  8.  * const x    x      x   x     x   x
  9.  * var   x    x      x   x
  10.  */
  11.  
  12. // type x *
  13.  
  14. function type_type() {
  15.   type A = number;
  16.   type A = number;  // error: name already bound
  17. }
  18.  
  19. function type_class() {
  20.   type A = number;
  21.   class A {}        // error: name already bound
  22. }
  23.  
  24. function type_let() {
  25.   type A = number;
  26.   let A = 0;        // error: name already bound
  27. }
  28.  
  29. function type_const() {
  30.   type A = number;
  31.   const A = 0;     // error: name already bound
  32. }
  33.  
  34. function type_var() {
  35.   type A = number;
  36.   var A = 0;        // error: name already bound
  37. }
  38.  
  39. function type_reassign() {
  40.   type A = number;
  41.   A = 42;           // error: type alias ref'd from value pos
  42. }
  43.  
  44. // class x *
  45.  
  46. function class_type() {
  47.   class A {}
  48.   type A = number;  // error: name already bound
  49. }
  50.  
  51. function class_class() {
  52.   class A {}
  53.   class A {}        // error: name already bound
  54. }
  55.  
  56. function class_let() {
  57.   class A {}
  58.   let A = 0;        // error: name already bound
  59. }
  60.  
  61. function class_const() {
  62.   class A {}
  63.   const A = 0;     // error: name already bound
  64. }
  65.  
  66. function class_var() {
  67.   class A {}
  68.   var A = 0;        // error: name already bound
  69. }
  70.  
  71. // let x *
  72.  
  73. function let_type() {
  74.   let A = 0;
  75.   type A = number;  // error: name already bound
  76. }
  77.  
  78. function let_class() {
  79.   let A = 0;
  80.   class A {}        // error: name already bound
  81. }
  82.  
  83. function let_let() {
  84.   let A = 0;
  85.   let A = 0;        // error: name already bound
  86. }
  87.  
  88. function let_const() {
  89.   let A = 0;
  90.   const A = 0;     // error: name already bound
  91. }
  92.  
  93. function let_var() {
  94.   let A = 0;
  95.   var A = 0;        // error: name already bound
  96. }
  97.  
  98. // const x *
  99.  
  100. function const_type() {
  101.   const A = 0;
  102.   type A = number;  // error: name already bound
  103. }
  104.  
  105. function const_class() {
  106.   const A = 0;
  107.   class A {}        // error: name already bound
  108. }
  109.  
  110. function const_let() {
  111.   const A = 0;
  112.   let A = 0;        // error: name already bound
  113. }
  114.  
  115. function const_const() {
  116.   const A = 0;
  117.   const A = 0;     // error: name already bound
  118. }
  119.  
  120. function const_var() {
  121.   const A = 0;
  122.   var A = 0;        // error: name already bound
  123. }
  124.  
  125. function const_reassign() {
  126.   const A = 0;
  127.   A = 42;           // error: cannot be reassigned
  128. }
  129.  
  130. // var x *
  131.  
  132. function var_type() {
  133.   var A = 0;
  134.   type A = number;  // error: name already bound
  135. }
  136.  
  137. function var_class() {
  138.   var A = 0;
  139.   class A {}        // error: name already bound
  140. }
  141.  
  142. function var_let() {
  143.   var A = 0;
  144.   let A = 0;        // error: name already bound
  145. }
  146.  
  147. function var_const() {
  148.   var A = 0;
  149.   const A = 0;      // error: name already bound
  150. }
  151.  
  152. function var_var() {
  153.   var A = 0;
  154.   var A = 0;       // OK
  155. }
  156.  
  157. // function x *
  158.  
  159. function function_toplevel() {
  160.   function a() {};
  161.   function a() {}; // OK
  162. }
  163.  
  164. function function_block() {
  165.   {
  166.     function a() {};
  167.     function a() {}; // error: name already bound
  168.   }
  169. }
  170.  
  171. // corner cases
  172.  
  173. function var_shadow_nested_scope() {
  174.   {
  175.     let x = 0;
  176.     {
  177.       var x = 0; // error: name already bound
  178.     }
  179.   }
  180. }
  181.  
  182. function type_shadow_nested_scope() {
  183.   {
  184.     let x = 0;
  185.     {
  186.       type x = string; // error: name already bound
  187.     }
  188.   }
  189. }
  190.  
  191. // fn params name clash
  192.  
  193. function fn_params_name_clash(x, x /* error: x already bound */) {}
  194. function fn_params_clash_fn_binding(x,y) {
  195.   let x = 0; // error: x already bound
  196.   var y = 0; // OK
  197. }
  198.  
downloadrebinding.js Source code - Download prettier Source code
Related Source Codes/Software:
storybook - 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
parse-server - Parse-compatible API server module for Node/Expres... 2017-06-07
inferno - An extremely fast, React-like JavaScript library f... 2017-06-08
guetzli - Perceptual JPEG encoder 2017-06-08
cs-video-courses - List of Computer Science courses with video lectur... 2017-06-08
interviews - Everything you need to know to get the job. 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top