BVB Source Codes

prettier Show logical.js Source code

Return Download prettier: download logical.js Source code - Download prettier Source code - Type:.js
  1. /* @flow */
  2.  
  3. /**
  4.  * A falsy variable on the left side of &&
  5.  */
  6. function logical1a(): number { // expected `: boolean`
  7.     var x = false;
  8.     return x && '123';
  9. }
  10.  
  11. /**
  12.  * A truthy variable on the left side of &&
  13.  */
  14. function logical1b(): string {
  15.     var x = true;
  16.     return x && '123';
  17. }
  18.  
  19. /**
  20.  * A literal on the left side of &&
  21.  */
  22. function logical2a(): number { // expected `: boolean`
  23.     return false && '123';
  24. }
  25.  
  26. /**
  27.  * A literal on the left side of &&
  28.  */
  29. function logical2b(): number {
  30.     return 0 && '123';
  31. }
  32.  
  33. /**
  34.  * A literal on the left side of &&
  35.  */
  36. function logical2c(): string {
  37.     return "" && 123;
  38. }
  39.  
  40. /**
  41.  * A literal on the left side of &&
  42.  */
  43. function logical2d(): string {
  44.     return true && '123';
  45. }
  46.  
  47. /**
  48.  * A literal on the left side of &&
  49.  */
  50. function logical2e(): number {
  51.     return 'foo' && 123;
  52. }
  53.  
  54. /**
  55.  * A literal on the left side of &&
  56.  */
  57. function logical2f(): string {
  58.     return 123 && 'foo';
  59. }
  60.  
  61. /**
  62.  * A literal on the left side of &&
  63.  */
  64. function logical2g(): string {
  65.     return [1,2,3] && 'foo';
  66. }
  67.  
  68. /**
  69.  * A literal on the left side of &&
  70.  */
  71. function logical2h(x: {a: number}): string {
  72.     return x && 'foo';
  73. }
  74.  
  75. /**
  76.  * A literal on the left side of &&
  77.  */
  78. function logical2i(x: Object): string {
  79.     return x && 'foo';
  80. }
  81.  
  82. /**
  83.  * A literal on the left side of &&
  84.  */
  85. function logical2j(x: (a: number) => number): string {
  86.     return x && 'foo';
  87. }
  88.  
  89. /**
  90.  * A literal on the left side of &&
  91.  */
  92. function logical2k(x: Function): string {
  93.     return x && 'foo';
  94. }
  95.  
  96. /**
  97.  * An expression on the left side of &&
  98.  */
  99. function logical3a(): string { // expected `: boolean`
  100.     var x: ?number = null;
  101.     return x != null && x > 10;
  102. }
  103.  
  104. /**
  105.  * An expression on the left side of &&
  106.  */
  107. function logical3b(): number { // expected `: boolean | number`
  108.     var x: ?number = null;
  109.     return x != null && x;
  110. }
  111.  
  112. /**
  113.  * An expression on the left side of &&
  114.  */
  115. function logical3c(): ?number { // expected `: boolean | ?number`
  116.     var x: ?number = null;
  117.     return x != undefined && x;
  118. }
  119.  
  120. /**
  121.  * Maybe truthy returns both types
  122.  */
  123. function logical4(x: boolean): string { // expected `: boolean | string`
  124.     return x && '123';
  125. }
  126.  
  127. /**
  128.  * A falsy variable on the left side of ||
  129.  */
  130. function logical5a(): number {
  131.     var x = false;
  132.     return x || 0;
  133. }
  134.  
  135. /**
  136.  * A maybe variable on the left side of ||
  137.  */
  138. function logical5b(): number {
  139.     var x: ?number = null;
  140.     return x || 0;
  141. }
  142.  
  143. /**
  144.  * A truthy variable on the left side of ||
  145.  */
  146. function logical5c(): string { // expected `: boolean`
  147.     var x = true;
  148.     return x || 0;
  149. }
  150.  
  151. /**
  152.  * A literal on the left side of ||
  153.  */
  154. function logical6a(): string {
  155.     return false || '123';
  156. }
  157.  
  158. /**
  159.  * A literal on the left side of ||
  160.  */
  161. function logical6b(): string {
  162.     return 0 || '123';
  163. }
  164.  
  165. /**
  166.  * A literal on the left side of ||
  167.  */
  168. function logical6c(): number {
  169.     return "" || 123;
  170. }
  171.  
  172. /**
  173.  * A literal on the left side of ||
  174.  */
  175. function logical6d(): number { // expected `: boolean`
  176.     return true || '123';
  177. }
  178.  
  179. /**
  180.  * A literal on the left side of ||
  181.  */
  182. function logical6e(): string {
  183.     return 'foo' || 123;
  184. }
  185.  
  186. /**
  187.  * A literal on the left side of ||
  188.  */
  189. function logical6f(): number {
  190.     return 123 || 'foo';
  191. }
  192.  
  193. /**
  194.  * A composite && and ||
  195.  */
  196. function logical7a(): number {
  197.     var x: ?number = null;
  198.     return x != null && x || 0;
  199. }
  200.  
  201. /**
  202.  * A composite && and || where the truthiness is unknown
  203.  */
  204. function logical7b(x: boolean, y: number): number {
  205.     return x && y || 0;
  206. }
  207.  
  208. /**
  209.  * A composite && and ||
  210.  */
  211. function logical7c(x: string): number {
  212.     return x && 1 || 0;
  213. }
  214.  
  215. /**
  216.  * A composite && and ||
  217.  */
  218. function logical7d(x: number): string {
  219.     return x && 'foo' || 'bar';
  220. }
  221.  
  222. /**
  223.  * A composite && and ||
  224.  */
  225. function logical7e(x: number): string {
  226.     return false && x || 'bar';
  227. }
  228.  
  229. /**
  230.  * A composite || and &&
  231.  *
  232.  * `x || 0` always returns a number (never a boolean) and then short
  233.  * circuits the && because 0 is falsy, so this should just return number.
  234.  */
  235. function logical8a(): number {
  236.     var x = false;
  237.     return (x || 0) && 'foo';
  238. }
  239.  
  240. /**
  241.  * A composite || and &&
  242.  *
  243.  * `x || 1` always returns something truthy, so this returns a string
  244.  */
  245. function logical8b(): string {
  246.     var x = false;
  247.     return (x || 1) && 'foo';
  248. }
  249.  
  250. /**
  251.  * A composite || and &&
  252.  *
  253.  * `x` is always truthy, so this returns a string
  254.  */
  255. function logical8c(): string {
  256.     var x = true;
  257.     return (x || 1) && 'foo';
  258. }
  259.  
  260. /**
  261.  * A composite || and &&
  262.  */
  263. function logical8d(): number {
  264.     var x = false;
  265.     return x || (0 && 'foo');
  266. }
  267.  
  268. /**
  269.  * A composite || and &&
  270.  */
  271. function logical8e(): string {
  272.     var x = false;
  273.     return x || (1 && 'foo');
  274. }
  275.  
  276. /**
  277.  * A composite || and &&
  278.  */
  279. function logical8f(): string { // expected `: boolean`
  280.     var x = true;
  281.     return x || (1 && 'foo');
  282. }
  283.  
  284. /**
  285.  * A composite || and ||
  286.  */
  287. function logical9a(
  288.     x: number,
  289.     y: string
  290. ): number | string { // expected `: number | string | boolean`
  291.     return x || y || false;
  292. }
  293.  
  294. /**
  295.  * A composite || and ||
  296.  */
  297. function logical9b(x: number, y: string): number | string {
  298.     return false || x || y;
  299. }
  300.  
  301. /**
  302.  * A composite || and ||
  303.  */
  304. function logical9c(x: number, y: boolean): string {
  305.     return 'a' || x || y;
  306. }
  307.  
  308. /**
  309.  * A composite && and &&
  310.  */
  311. function logical10a(
  312.     x: number,
  313.     y: string
  314. ): number | string { // expected `: number | string | boolean`
  315.     return x && y && false;
  316. }
  317.  
  318. /**
  319.  * A composite && and &&
  320.  */
  321. function logical10b(x: number, y: string): Array<any> { // expected `: boolean`
  322.     return false && x && y;
  323. }
  324.  
  325. /**
  326.  * A composite && and &&
  327.  */
  328. function logical10c(x: number, y: string): Array<any> { // expected `number | boolean`
  329.     return x && false && y;
  330. }
  331.  
  332. /**
  333.  * || in a loop
  334.  */
  335. function logical11a(): number {
  336.     var y = 1;
  337.     for (var x = 0; x < 5; x++) {
  338.         y = y || true;
  339.     }
  340.     return y;
  341. }
  342.  
  343. /**
  344.  * || in a loop
  345.  */
  346. function logical11b(y: number): number {
  347.     for (var x = 0; x < 5; x++) {
  348.         y = y || true; // expected a number
  349.     }
  350.     return y;
  351. }
  352.  
  353. /**
  354.  * && in a loop
  355.  */
  356. function logical12a(): number {
  357.     var y = 1;
  358.     var z = true;
  359.     for (var x = 0; x < 5; x++) {
  360.         y = z && y;
  361.         z = false;
  362.     }
  363.     return y;
  364. }
  365.  
  366. /**
  367.  * && in a loop
  368.  */
  369. function logical12b(y: number): number {
  370.     for (var x = 0; x < 5; x++) {
  371.         y = y && true; // expected a number
  372.     }
  373.     return y;
  374. }
  375.  
  376. /**
  377.  * Complex &&
  378.  */
  379. function logical13(x: number): Array<{x: string}> {
  380.     return [
  381.         {x: x && "bar"},
  382.         {x: true && "bar"},
  383.         {x: true && false},
  384.         {x: false && false},
  385.         {x: 1 && "bar"},
  386.         {x: "foo" && "bar"},
  387.         {x: "foo" && "bar"},
  388.         {x: "foo" && "bar"},
  389.     ];
  390. }
  391.  
  392. /**
  393.  * Complex ||
  394.  */
  395. function logical14(x: number): Array<{x: string}> {
  396.     return [
  397.         {x: x || "bar"},
  398.         {x: false || "bar"},
  399.         {x: false || true},
  400.         {x: true || false},
  401.         {x: 0 || "bar"},
  402.         {x: "foo" || "bar"},
  403.         {x: "foo" || "bar"},
  404.         {x: "foo" || "bar"},
  405.     ];
  406. }
  407.  
  408. /**
  409.  * || in an addition
  410.  */
  411. function logical15a(x: number): number {
  412.     return 5 + (x || 7);
  413. }
  414.  
  415. /**
  416.  * || in an addition
  417.  */
  418. function logical15b(x: number): number {
  419.     return (x || 7) + 5;
  420. }
  421.  
  422. /**
  423.  * && in an addition
  424.  */
  425. function logical15c(x: number): number {
  426.     return 5 + (x && 7);
  427. }
  428.  
  429. /**
  430.  * && in an addition
  431.  */
  432. function logical15d(x: number): number {
  433.     return (x && 7) + 5;
  434. }
  435.  
  436. /**
  437.  * || in a comparison
  438.  */
  439. function logical16a(x: number): boolean {
  440.     return 5 < (x || 7);
  441. }
  442.  
  443. /**
  444.  * || in a comparison
  445.  */
  446. function logical16b(x: number): boolean {
  447.     return (x || 7) < 5;
  448. }
  449.  
  450. /**
  451.  * && in a comparison
  452.  */
  453. function logical16c(x: number): boolean {
  454.     return 5 < (x && 7);
  455. }
  456.  
  457. /**
  458.  * && in a comparison
  459.  */
  460. function logical16d(x: number): boolean {
  461.     return (x && 7) < 5;
  462. }
  463.  
  464. /**
  465.  * || in an equality
  466.  */
  467. function logical17a(x: number): boolean {
  468.     return 5 == (x || 7);
  469. }
  470.  
  471. /**
  472.  * || in an equality
  473.  */
  474. function logical17b(x: number): boolean {
  475.     return (x || 7) == 5;
  476. }
  477.  
  478. /**
  479.  * && in an equality
  480.  */
  481. function logical17c(x: number): boolean {
  482.     return 5 == (x && 7);
  483. }
  484.  
  485. /**
  486.  * && in an equality
  487.  */
  488. function logical17d(x: number): boolean {
  489.     return (x && 7) == 5;
  490. }
  491.  
  492. /**
  493.  * Expressions on each side that return truthy things
  494.  */
  495. function logical18a(x: number, y: number): number {
  496.     return x - 1 || y - 1;
  497. }
  498.  
  499. /**
  500.  * Sentinel properties should not interfere
  501.  */
  502. function logical18b(x: {a: number}, y: {b: number}): number {
  503.     return x.a - 1 || y.b - 1;
  504. }
  505.  
  506. /**
  507.  * Layer of indirection in the LHS (get prop)
  508.  */
  509. function logical19a(x: { y: string, z: boolean }): boolean {
  510.   return (x.y && x.z); // error: x.y is a string
  511. }
  512. function logical19b(x: { y: string, z: boolean }): boolean {
  513.   return (x.y || x.z); // error: x.y is a string
  514. }
  515.  
downloadlogical.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