BVB Source Codes

prettier Show generators.js Source code

Return Download prettier: download generators.js Source code - Download prettier Source code - Type:.js
  1. function *stmt_yield(): Generator<number, void, void> {
  2.   yield 0; // ok
  3.   yield ""; // error: string ~> number
  4. }
  5.  
  6. function *stmt_next(): Generator<void, void, number> {
  7.   var a = yield;
  8.   if (a) {
  9.     (a : number); // ok
  10.   }
  11.  
  12.   var b = yield;
  13.   if (b) {
  14.     (b : string); // error: number ~> string
  15.   }
  16. }
  17.  
  18. function *stmt_return_ok(): Generator<void, number, void> {
  19.   return 0; // ok
  20. }
  21.  
  22. function *stmt_return_err(): Generator<void, number, void> {
  23.   return ""; // error: string ~> number
  24. }
  25.  
  26. function *infer_stmt() {
  27.   var x: boolean = yield 0;
  28.   return "";
  29. }
  30. for (var x of infer_stmt()) { (x : string) } // error: number ~> string
  31. var infer_stmt_next = infer_stmt().next(0).value; // error: number ~> boolean
  32. if (typeof infer_stmt_next === "undefined") {
  33. } else if (typeof infer_stmt_next === "number") {
  34. } else {
  35.   (infer_stmt_next : boolean) // error: string ~> boolean
  36. }
  37.  
  38. function *widen_next() {
  39.   var x = yield 0;
  40.   if (typeof x === "number") {
  41.   } else if (typeof x === "boolean") {
  42.   } else {
  43.     (x : string) // ok, sherlock
  44.   }
  45. }
  46. widen_next().next(0)
  47. widen_next().next("")
  48. widen_next().next(true)
  49.  
  50. function *widen_yield() {
  51.   yield 0;
  52.   yield "";
  53.   yield true;
  54. }
  55. for (var x of widen_yield()) {
  56.   if (typeof x === "number") {
  57.   } else if (typeof x === "boolean") {
  58.   } else {
  59.     (x : string) // ok, sherlock
  60.   }
  61. }
  62.  
  63. function *delegate_next_generator() {
  64.   function *inner() {
  65.     var x: number = yield; // error: string ~> number
  66.   }
  67.   yield *inner();
  68. }
  69. delegate_next_generator().next("");
  70.  
  71. function *delegate_yield_generator() {
  72.   function *inner() {
  73.     yield "";
  74.   }
  75.  
  76.   yield *inner();
  77. }
  78. for (var x of delegate_yield_generator()) {
  79.   (x : number) // error: string ~> number
  80. }
  81.  
  82. function *delegate_return_generator() {
  83.   function *inner() {
  84.     return "";
  85.   }
  86.  
  87.   var x: number = yield *inner(); // error: string ~> number
  88. }
  89.  
  90. // only generators can make use of a value passed to next
  91. function *delegate_next_iterable(xs: Array<number>) {
  92.   yield *xs;
  93. }
  94. delegate_next_iterable([]).next(""); // error: Iterator has no next value
  95.  
  96. function *delegate_yield_iterable(xs: Array<number>) {
  97.   yield *xs;
  98. }
  99. for (var x of delegate_yield_iterable([])) {
  100.   (x : string) // error: number ~> string
  101. }
  102.  
  103. function *delegate_return_iterable(xs: Array<number>) {
  104.   var x: void = yield *xs // ok: Iterator has no yield value
  105. }
  106.  
  107. function *generic_yield<Y>(y: Y): Generator<Y,void,void> {
  108.   yield y;
  109. }
  110.  
  111. function *generic_return<R>(r: R): Generator<void,R,void> {
  112.   return r;
  113. }
  114.  
  115. function *generic_next<N>(): Generator<void,N,N> {
  116.   return yield undefined;
  117. }
  118.  
  119. function *multiple_return(b) {
  120.   if (b) {
  121.     return 0;
  122.   } else {
  123.     return "foo";
  124.   }
  125. }
  126. let multiple_return_result = multiple_return().next();
  127. if (multiple_return_result.done) {
  128.   (multiple_return_result.value: void); // error: number|string ~> void
  129. }
  130.  
downloadgenerators.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