BVB Source Codes

prettier Show derived_class.js Source code

Return Download prettier: download derived_class.js Source code - Download prettier Source code - Type:.js
  1. // @flow
  2.  
  3. class Base {
  4.   base_unannotatedField;
  5.   base_annotatedField: number;
  6.   base_initializedField = 42;
  7.   base_initializedFieldWithThis = this.base_initializedField;
  8.   base_annotatedInitializedFieldValid: ?number = 42;
  9.   base_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
  10.  
  11.   static base_unannotatedField;
  12.   static base_annotatedField: number;
  13.   static base_initializedField = 'asdf';
  14.   static base_initializedFieldWithThis = this.base_initializedField;
  15.   static base_annotatedInitializedFieldValid: ?number = 42;
  16.   static base_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
  17.  
  18.   inherited_initializer = 42;
  19.   static inherited_initializer = 42;
  20. }
  21.  
  22. class Child extends Base {
  23.   child_unannotatedField;
  24.   child_annotatedField: number;
  25.   child_initializedField = 42;
  26.   child_initializedFieldWithThis = this.child_initializedField;
  27.   child_annotatedInitializedFieldValid: ?number = 42;
  28.   child_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
  29.  
  30.   static child_unannotatedField;
  31.   static child_annotatedField: number;
  32.   static child_initializedField = 'asdf';
  33.   static child_initializedFieldWithThis = this.child_initializedField;
  34.   static child_annotatedInitializedFieldValid: ?number = 42;
  35.   static child_annotatedInitializedFieldInvalid: number = 'asdf'; // Error: string ~> number
  36.  
  37.   inherited_initializer;
  38.   static inherited_initializer;
  39. }
  40.  
  41. var o = new Child();
  42.  
  43. /**
  44.  * Unannotated fields are open.
  45.  */
  46. (o.base_unannotatedField: string);
  47. (o.base_unannotatedField: number);
  48. (Child.base_unannotatedField: string);
  49. (Child.base_unannotatedField: number);
  50.  
  51. (o.child_unannotatedField: string);
  52. (o.child_unannotatedField: number);
  53. (Child.child_unannotatedField: string);
  54. (Child.child_unannotatedField: number);
  55.  
  56.  
  57. /**
  58.  * Annotated (but uninitialized) fields still have a type.
  59.  */
  60. (o.base_annotatedField: number);
  61. (o.base_annotatedField: string); // Error: number ~> string
  62. (Child.base_annotatedField: number);
  63. (Child.base_annotatedField: string); // Error: number ~> string
  64.  
  65. (o.child_annotatedField: number);
  66. (o.child_annotatedField: string); // Error: number ~> string
  67. (Child.child_annotatedField: number);
  68. (Child.child_annotatedField: string); // Error: number ~> string
  69.  
  70. /**
  71.  * Initialized (but unannotated) fields assume the type of their initializer.
  72.  */
  73. (o.base_initializedField: number);
  74. (o.base_initializedField: string); // Error: number ~> string
  75. (Child.base_initializedField: string);
  76. (Child.base_initializedField: number); // Error: string ~> number
  77.  
  78. (o.child_initializedField: number);
  79. (o.child_initializedField: string); // Error: number ~> string
  80. (Child.child_initializedField: string);
  81. (Child.child_initializedField: number); // Error: string ~> number
  82.  
  83. /**
  84.  * Initialized fields can reference `this`.
  85.  */
  86. (o.base_initializedFieldWithThis: number);
  87. (o.base_initializedFieldWithThis: string); // Error: number ~> string
  88. (Child.base_initializedFieldWithThis: string);
  89. (Child.base_initializedFieldWithThis: number); // Error: string ~> number
  90.  
  91. (o.child_initializedFieldWithThis: number);
  92. (o.child_initializedFieldWithThis: string); // Error: number ~> string
  93. (Child.child_initializedFieldWithThis: string);
  94. (Child.child_initializedFieldWithThis: number); // Error: string ~> number
  95.  
  96. /**
  97.  * Initialized + annotated fields take the type of the annotation.
  98.  * (Note that this matters when the annotation is more general than the type of
  99.  *  the initializer)
  100.  */
  101. (o.base_annotatedInitializedFieldValid: ?number);
  102. (o.base_annotatedInitializedFieldValid: number); // Error: ?number ~> number
  103. (Child.base_annotatedInitializedFieldValid: ?number);
  104. (Child.base_annotatedInitializedFieldValid: number); // Error: ?number ~> number
  105.  
  106. (o.child_annotatedInitializedFieldValid: ?number);
  107. (o.child_annotatedInitializedFieldValid: number); // Error: ?number ~> number
  108. (Child.child_annotatedInitializedFieldValid: ?number);
  109. (Child.child_annotatedInitializedFieldValid: number); // Error: ?number ~> number
  110.  
  111. /**
  112.  * Initialized + annotated fields where the init/annot combo is a mismatch
  113.  * should assume the type of the annotation.
  114.  *
  115.  * (This happens in addition to erroring at the site of initialization)
  116.  */
  117. (o.base_annotatedInitializedFieldInvalid: number);
  118. (o.base_annotatedInitializedFieldInvalid: string); // Error: number ~> string
  119. (Child.base_annotatedInitializedFieldInvalid: number);
  120. (Child.base_annotatedInitializedFieldInvalid: string); // Error: number ~> string
  121.  
  122. (o.child_annotatedInitializedFieldInvalid: number);
  123. (o.child_annotatedInitializedFieldInvalid: string); // Error: number ~> string
  124. (Child.child_annotatedInitializedFieldInvalid: number);
  125. (Child.child_annotatedInitializedFieldInvalid: string); // Error: number ~> string
  126.  
  127. /**
  128.  * Derived fields without an initializer that shadow base fields *with* an
  129.  * initializer should have the type of the base field.
  130.  */
  131. (o.inherited_initializer: number);
  132. (o.inherited_initializer: string); // Error: number ~> string
  133. (Child.inherited_initializer: number);
  134. (Child.inherited_initializer: string); // Error: number ~> string
  135.  
downloadderived_class.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