BVB Source Codes

prettier Show const.js Source code

Return Download prettier: download const.js Source code - Download prettier Source code - Type:.js
  1. /***
  2.  * consts retain refinements
  3.  * @flow
  4.  */
  5.  
  6. // global, anybody can call it at any time
  7. var call_me: () => void = () => {};
  8.  
  9. function g(x: ?number) {
  10.  
  11.   const const_x = x;
  12.   if (const_x) {
  13.     // ok: if const_x is truthy here, it's truthy everywhere
  14.     call_me = () => { var y:number = const_x; };
  15.   }
  16.  
  17.   var var_x = x;
  18.   if (var_x) {
  19.     // error: var_x might no longer be truthy when call_me is called
  20.     call_me = () => { var y:number = var_x; };  // error
  21.   }
  22.   var_x = null;
  23. }
  24.  
  25. function h(x: number | string | boolean) {
  26.  
  27.   const const_x = x;
  28.   if (typeof(const_x) == "number") {
  29.     call_me = () => { var y:number = const_x; };  // ok
  30.   } else if (typeof(const_x) == "string") {
  31.     call_me = () => { var y:string = const_x; };  // ok
  32.   } else if (typeof(const_x) == "boolean") {
  33.     call_me = () => { var y:boolean = const_x; };  // ok
  34.   }
  35.  
  36.   var var_x = x;
  37.   if (typeof(var_x) == "number") {
  38.     call_me = () => { var y:number = var_x; };  // error
  39.   } else if (typeof(var_x) == "string") {
  40.     call_me = () => { var y:string = var_x; };  // error
  41.   } else if (typeof(var_x) == "boolean") {
  42.     call_me = () => { var y:boolean = var_x; };  // error
  43.   }
  44. }
  45.  
  46. // in a galaxy far far away
  47. call_me();
  48.  
downloadconst.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