BVB Source Codes

prettier Show let.js Source code

Return Download prettier: download let.js Source code - Download prettier Source code - Type:.js
  1. /**
  2.  * test initialization tracking for lets
  3.  * @flow
  4.  */
  5.  
  6. // deferred init on annotated lets is ok
  7. function linear_deferred_init() {
  8.   let x:number;
  9.   x = 0;
  10.   let y:number = x;
  11. }
  12.  
  13. // use of let before init gives undefined
  14. function linear_pre_init() {
  15.   let x:number;
  16.   let y:?number = x;  // ok
  17.   let z:number = x;   // error
  18.   x = 0;
  19.   let w:number = x;   // ok
  20. }
  21.  
  22. // self-references in let bindings are not ok
  23. function self_init() {
  24.   let x = x;  // 'x' not initialized!
  25. }
  26.  
  27. // use of let after partial init (non-exhaustive if) gives undefined
  28. function if_partial_post_init(b) {
  29.   let x:number;
  30.   if (b) {
  31.     x = 0;
  32.   }
  33.   var y:number = x; // error, possibly uninitialized
  34. }
  35.  
  36. // use of let after guaranteed init (exhaustive if) is ok
  37. function if_post_init(b) {
  38.   let x:number;
  39.   if (b) {
  40.     x = 0;
  41.   } else {
  42.     x = 1;
  43.   }
  44.   var y:number = x;
  45. }
  46.  
  47. // use of let after partial init (non-exhaustive switch) gives undefined
  48. function switch_partial_post_init(i) {
  49.   let x:number;
  50.   switch (i) {
  51.     case 0:
  52.       x = 0;
  53.       break;
  54.     case 1:
  55.       x = 1;
  56.       break;
  57.   }
  58.   var y:number = x; // error, possibly uninitialized
  59. }
  60.  
  61. // use of let after guaranteed init (exhaustive switch) is ok
  62. function switch_post_init(i) {
  63.   let x:number;
  64.   switch (i) {
  65.     case 0:
  66.       x = 0;
  67.       break;
  68.     case 1:
  69.       x = 1;
  70.       break;
  71.     default:
  72.       x = 2;
  73.   }
  74.   var y:number = x; // no error, all cases covered
  75. }
  76.  
  77. // use in a switch after a skipped decl is an error
  78. function switch_scoped_init_2(i) {
  79.   switch (i) {
  80.     case 0:
  81.       let x:number;
  82.     case 1:
  83.       let y:number = x; // error, skipped declaration
  84.   }
  85. }
  86.  
  87. // while leaves it possibly uninitialized
  88. function while_post_init(b) {
  89.   let x:number;
  90.   while (b) {
  91.     x = 0;
  92.   }
  93.   var y:number = x; // error
  94. }
  95.  
  96. // do-while is ok, because loop is guaranteed to run at least once
  97. function do_while_post_init(b) {
  98.   let x:number;
  99.   do {
  100.     x = 0;
  101.   } while (b);
  102.   var y:number = x; // ok
  103. }
  104.  
  105. // for-in leaves it possibly uninitialized
  106. function for_in_post_init() {
  107.   var x:number;
  108.   for (var p in {}) {
  109.     x = 0;
  110.   }
  111.   var y:number = x; // error
  112. }
  113.  
  114. // for-of leaves it possibly uninitialized
  115. function for_of_post_init() {
  116.   var x:number;
  117.   for (var x of []) {
  118.     x = 0;
  119.   }
  120.   var y:number = x; // error
  121. }
  122.  
  123. // use of let after guaranteed init (exhaustive switch + throw) is ok
  124. function switch_post_init2(i): number {
  125.   let bar;
  126.   switch (i) {
  127.     case 1:
  128.       bar = 3;
  129.       break;
  130.     default:
  131.       throw new Error('Invalid state');
  132.   }
  133.   return bar; // ok, definitely initialized
  134. }
  135.  
  136. // use of let after guaranteed init (exhaustive switch + throw) is ok
  137. function switch_post_init2(i): number {
  138.   let bar;
  139.   switch (i) {
  140.     case 1:
  141.       bar = 3;
  142.       break;
  143.     default:
  144.       throw new Error('Invalid state');
  145.   }
  146.   return bar; // ok, definitely initialized
  147. }
  148.  
  149. // reference of a let-binding is permitted in a sub-closure within the init expr
  150. function sub_closure_init_reference() {
  151.   let x = function() { return x; };
  152.   const y = function() { return y; };
  153.  
  154.   // var-bindings can reference each other cyclically since they do not incur a
  155.   // TDZ (...even though this is weird...)
  156.   var z = z;
  157. }
  158.  
downloadlet.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