BVB Source Codes

prettier Show tdz.js Source code

Return Download prettier: download tdz.js Source code - Download prettier Source code - Type:.js
  1. /** @flow */
  2.  
  3. // -- types ---
  4.  
  5. // type aliases are hoisted and always available
  6.  
  7. type T1 = T2;   // ok
  8. type T2 = number;
  9.  
  10. // --- lets ---
  11.  
  12. // to be correct, we would
  13. // - not allow forward refs to lets from value positions,
  14. // while let is in TDZ.
  15. // - allow forward refs to lets from type positions.
  16. //
  17. // currently we're too lenient about TDZ in closures -
  18. // from value positions, we currently enforce TDZ only in-scope.
  19. // this is unsound - a let or const may remain uninitialized when
  20. // a lambda runs. But a simple conservative approach would prohibit
  21. // forward references to let/consts from within lambdas entirely,
  22. // which would be annoying. TODO
  23.  
  24. function f0() {
  25.   var v = x * c;  // errors, let + const referenced before decl
  26.   let x = 0;
  27.   const c = 0;
  28. }
  29.  
  30. function f1(b) {
  31.   x = 10;         // error, attempt to write to let before decl
  32.   let x = 0;
  33.   if (b) {
  34.     y = 10;       // error, attempt to write to let before decl
  35.     let y = 0;
  36.   }
  37. }
  38.  
  39. function f2() {
  40.   {
  41.     var v = x * c; // errors, let + const referenced before decl
  42.   }
  43.   let x = 0;
  44.   const c = 0;
  45. }
  46.  
  47. // functions are let-scoped and hoisted
  48. function f3() {
  49.   var s: string = foo();          // ok, finds hoisted outer
  50.   {
  51.     var n: number = foo();        // ok, finds hoisted inner
  52.     function foo() { return 0; }
  53.   }
  54.   var s2: string = foo();         // ok, hoisted outer not clobbered
  55.   function foo() { return ""; }
  56. }
  57.  
  58. // out-of-scope TDZ not enforced. sometimes right...
  59. function f4() {
  60.   function g() { return x + c; }  // ok, g doesn't run in TDZ
  61.   let x = 0;
  62.   const c = 0;
  63. }
  64.  
  65. // ...sometimes wrong
  66. function f5() {
  67.   function g() { return x; }
  68.   g();          // should error, but doesn't currently
  69.   let x = 0;
  70.   const c = 0;
  71. }
  72.  
  73. // - from type positions, we currently error on forward refs to any
  74. // value (i.e., class or function). this is a basic flaw in our
  75. // phasing of AST traversal, and will be fixed.
  76. //
  77.  
  78. var x: C;       // ok
  79.  
  80. var y = new C(); // error: let ref before decl from value position
  81.  
  82. class C {}
  83.  
  84. var z: C = new C(); // ok
  85.  
  86. // --- vars ---
  87.  
  88. // it's possible to annotate a var with a non-maybe type,
  89. // but leave it uninitialized until later (as long as it's
  90. // initialized before use)
  91.  
  92. var a: number;  // not an error per se - only if used before init
  93.  
  94. function f(n: number) { return n; }
  95.  
  96. f(a); // error: undefined ~/> number
  97.  
  98. a = 10;
  99.  
  100. f(a); // ok, a: number (not ?number)
  101.  
downloadtdz.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