BVB Source Codes

prettier Show class.js Source code

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