BVB Source Codes

prettier Show hoisted2.js Source code

Return Download prettier: download hoisted2.js Source code - Download prettier Source code - Type:.js
  1. /**
  2.  * test initialization tracking for vars
  3.  * note: for try/catch/finally, see tests/try/init.js
  4.  * @flow
  5.  */
  6.  
  7. // deferred init on annotated vars is ok
  8. function linear_deferred_init() {
  9.   var x:number;
  10.   x = 0;
  11.   var y:number = x;
  12. }
  13.  
  14. // ...but use of var before init gives undefined
  15. function linear_pre_init() {
  16.   var x:number;
  17.   var y:number = x; // error
  18. }
  19.  
  20. // local use of annotated vars in an if is ok
  21. function if_scoped_init(b) {
  22.   if (b) {
  23.     var x:number = 0;
  24.     var y:number = x;
  25.   }
  26. }
  27.  
  28. // but not across if/else
  29. function if_else_partial_init(b) {
  30.   if (b) {
  31.     var x:number = 0;
  32.   } else {
  33.     var y:number = x; // error
  34.   }
  35. }
  36.  
  37. // use of var before if gives undefined
  38. function if_pre_init(b) {
  39.   var y:number = x; // error
  40.   if (b) {
  41.     var x:number = 0;
  42.   }
  43. }
  44.  
  45. // ...and after
  46. function if_partial_post_init(b) {
  47.   if (b) {
  48.     var x:number = 0;
  49.   }
  50.   var y:number = x; // error
  51. }
  52.  
  53. // ...unless both branches have initialized
  54. function if_post_init(b) {
  55.   if (b) {
  56.     var x:number = 0;
  57.   } else {
  58.     var x:number = 1;
  59.   }
  60.   var y:number = x;
  61. }
  62.  
  63. // use of var after partial init (non-exhaustive if) gives undefined
  64. function if_partial_post_init(b) {
  65.   var x:number;
  66.   if (b) {
  67.     x = 0;
  68.   }
  69.   var y:number = x; // error, possibly uninitialized
  70. }
  71.  
  72. // use of var after guaranteed init (exhaustive if) is ok
  73. function if_post_init(b) {
  74.   var x:number;
  75.   if (b) {
  76.     x = 0;
  77.   } else {
  78.     x = 1;
  79.   }
  80.   var y:number = x;
  81. }
  82.  
  83. // use of var after partial init (non-exhaustive switch) gives undefined
  84. function switch_partial_post_init(i) {
  85.   var x:number;
  86.   switch (i) {
  87.     case 0:
  88.       x = 0;
  89.       break;
  90.     case 1:
  91.       x = 1;
  92.       break;
  93.   }
  94.   var y:number = x; // error, possibly uninitialized
  95. }
  96.  
  97. // use of var after guaranteed init (exhaustive switch) is ok
  98. function switch_post_init(i) {
  99.   var x:number;
  100.   switch (i) {
  101.     case 0:
  102.       x = 0;
  103.       break;
  104.     case 1:
  105.       x = 1;
  106.       break;
  107.     default:
  108.       x = 2;
  109.   }
  110.   var y:number = x; // no error, all cases covered
  111. }
  112.  
  113. // local use of annotated var in switch is ok
  114. function switch_scoped_init_1(i) {
  115.   switch (i) {
  116.     case 0:
  117.       var x:number = 0;
  118.       var y:number = x;
  119.   }
  120. }
  121.  
  122. // ...but use of var before switch gives undefined
  123. function switch_scoped_init_2(i) {
  124.   var y:number = x; // error
  125.   switch (i) {
  126.     case 0:
  127.       var x:number = 0;
  128.   }
  129. }
  130.  
  131. // ...and after
  132. function switch_scoped_init_3(i) {
  133.   switch (i) {
  134.     case 0:
  135.       var x:number = 0;
  136.   }
  137.   var y:number = x; // error
  138. }
  139.  
  140. // ...and in a fallthrough case without initialization
  141. function switch_scoped_init_4(i) {
  142.   switch (i) {
  143.     case 0:
  144.       var x:number = 0;
  145.     case 1:
  146.       var y:number = x; // error
  147.   }
  148. }
  149.  
  150. // local use of annotated var in while is ok
  151. function while_scoped_init(b) {
  152.   while (b) {
  153.     var x:number = 0;
  154.     var y:number = x;
  155.   }
  156. }
  157.  
  158. // ...but use of var before while gives undefined
  159. function while_pre_init(b) {
  160.   var y:number = x; // error
  161.   while (b) {
  162.     var x:number = 0;
  163.   }
  164. }
  165.  
  166. // ...and after
  167. function while_post_init(b) {
  168.    while (b) {
  169.     var x:number = 0;
  170.   }
  171.   var y:number = x; // error
  172. }
  173.  
  174. // local use of annotated var in do-while is ok
  175. function do_while_scoped_init(b) {
  176.   do {
  177.     var x:number = 0;
  178.     var y:number = x;
  179.   } while (b);
  180. }
  181.  
  182. // ...but use before do-while gives undefined
  183. function do_while_pre_init(b) {
  184.   var y:number = x; // error
  185.   do {
  186.     var x:number = 0;
  187.   } while (b);
  188. }
  189.  
  190. // after is ok, because loop is guaranteed to run
  191. function do_while_post_init(b) {
  192.   do {
  193.     var x:number = 0;
  194.   } while (b);
  195.   var y:number = x;
  196. }
  197.  
  198. // local use of annotated var in for is ok
  199. function for_scoped_init(b) {
  200.   for (;b;) {
  201.     var x:number = 0;
  202.     var y:number = x;
  203.   }
  204. }
  205.  
  206. // ...but use before for gives undefined
  207. function for_pre_init(b) {
  208.   var y:number = x; // error
  209.   for (;b;) {
  210.     var x:number = 0;
  211.   }
  212. }
  213.  
  214. // ...and after
  215. function for_post_init(b) {
  216.    for (;b;) {
  217.     var x:number = 0;
  218.   }
  219.   var y:number = x; // error
  220. }
  221.  
  222. // local use of annotated var in for-in is ok
  223. function for_in_scoped_init() {
  224.   for (var p in { a:1, b: 2 }) {
  225.     var x:number = 0;
  226.     var y:number = x;
  227.   }
  228. }
  229.  
  230. // ...but use before while gives undefined
  231. function for_in_pre_init() {
  232.   var y:number = x; // error
  233.   for (var p in { a:1, b: 2 }) {
  234.     var x:number = 0;
  235.   }
  236. }
  237.  
  238. // ...and after
  239. function for_in_post_init() {
  240.   for (var p in { a:1, b: 2 }) {
  241.     var x:number = 0;
  242.   }
  243.   var y:number = x; // error
  244. }
  245.  
  246. // local use of annotated var in for-of is ok
  247. function for_of_scoped_init() {
  248.   for (var x of [1, 2, 3]) {
  249.     var x:number = 0;
  250.     var y:number = x;
  251.   }
  252. }
  253.  
  254. // ...but use before while gives undefined
  255. function for_in_pre_init() {
  256.   var y:number = x; // error
  257.   for (var x of [1, 2, 3]) {
  258.     var x:number = 0;
  259.   }
  260. }
  261.  
  262. // ...and after
  263. function for_in_post_init() {
  264.   for (var x of [1, 2, 3]) {
  265.     var x:number = 0;
  266.   }
  267.   var y:number = x; // error
  268. }
  269.  
downloadhoisted2.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