From 37601b0a86df7af4f0b799d3453109957e443a46 Mon Sep 17 00:00:00 2001 From: James Long Date: Sun, 1 Jan 2017 20:20:45 -0500 Subject: [PATCH] Update snapshots --- .../abnormal/__snapshots__/jsfmt.spec.js.snap | 4 +- tests/annot/__snapshots__/jsfmt.spec.js.snap | 8 +- tests/any/__snapshots__/jsfmt.spec.js.snap | 5 + tests/arith/__snapshots__/jsfmt.spec.js.snap | 42 +-- .../__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../arraylib/__snapshots__/jsfmt.spec.js.snap | 9 +- tests/arrays/__snapshots__/jsfmt.spec.js.snap | 3 + tests/arrows/__snapshots__/jsfmt.spec.js.snap | 3 +- tests/async/__snapshots__/jsfmt.spec.js.snap | 9 +- .../__snapshots__/jsfmt.spec.js.snap | 6 +- tests/binary/__snapshots__/jsfmt.spec.js.snap | 32 +- .../binding/__snapshots__/jsfmt.spec.js.snap | 49 +-- tests/bom/__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 3 + tests/break/__snapshots__/jsfmt.spec.js.snap | 25 +- .../builtins/__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 2 + .../callable/__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 17 +- .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../classes/__snapshots__/jsfmt.spec.js.snap | 3 + .../closure/__snapshots__/jsfmt.spec.js.snap | 43 +-- .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 61 ++-- .../__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 11 + .../__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 6 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 3 +- tests/demo/1/__snapshots__/jsfmt.spec.js.snap | 1 + tests/demo/2/__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 27 +- .../__snapshots__/jsfmt.spec.js.snap | 61 ++-- .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/dom/__snapshots__/jsfmt.spec.js.snap | 82 ++--- .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 4 + tests/encaps/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 2 + tests/equals/__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 22 +- .../__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 28 +- tests/fetch/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../fixpoint/__snapshots__/jsfmt.spec.js.snap | 6 +- tests/for/__snapshots__/jsfmt.spec.js.snap | 51 +-- tests/forof/__snapshots__/jsfmt.spec.js.snap | 4 +- .../function/__snapshots__/jsfmt.spec.js.snap | 47 +-- .../__snapshots__/jsfmt.spec.js.snap | 46 ++- .../generics/__snapshots__/jsfmt.spec.js.snap | 5 +- .../get-def/__snapshots__/jsfmt.spec.js.snap | 3 + .../get-def2/__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 2 + tests/init/__snapshots__/jsfmt.spec.js.snap | 88 ++++-- .../__snapshots__/jsfmt.spec.js.snap | 17 +- .../__snapshots__/jsfmt.spec.js.snap | 15 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/iter/__snapshots__/jsfmt.spec.js.snap | 3 + .../iterable/__snapshots__/jsfmt.spec.js.snap | 5 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/keys/__snapshots__/jsfmt.spec.js.snap | 29 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/lib/__snapshots__/jsfmt.spec.js.snap | 1 + .../literal/__snapshots__/jsfmt.spec.js.snap | 6 +- tests/locals/__snapshots__/jsfmt.spec.js.snap | 48 +-- .../logical/__snapshots__/jsfmt.spec.js.snap | 10 +- tests/loners/__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/misc/__snapshots__/jsfmt.spec.js.snap | 11 +- .../modules/__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 7 +- .../__snapshots__/jsfmt.spec.js.snap | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 31 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + .../buffer/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../crypto/__snapshots__/jsfmt.spec.js.snap | 30 +- .../__snapshots__/jsfmt.spec.js.snap | 3 + .../os/__snapshots__/jsfmt.spec.js.snap | 2 + .../stream/__snapshots__/jsfmt.spec.js.snap | 2 + .../nullable/__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 26 +- .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 3 + .../objects/__snapshots__/jsfmt.spec.js.snap | 12 +- tests/objmap/__snapshots__/jsfmt.spec.js.snap | 2 +- .../optional/__snapshots__/jsfmt.spec.js.snap | 11 +- .../__snapshots__/jsfmt.spec.js.snap | 7 +- .../overload/__snapshots__/jsfmt.spec.js.snap | 6 +- tests/path/__snapshots__/jsfmt.spec.js.snap | 2 +- .../plsummit/__snapshots__/jsfmt.spec.js.snap | 6 + tests/poly/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 5 + .../__snapshots__/jsfmt.spec.js.snap | 13 +- .../__snapshots__/jsfmt.spec.js.snap | 4 +- .../__snapshots__/jsfmt.spec.js.snap | 4 + .../private/__snapshots__/jsfmt.spec.js.snap | 4 +- .../promises/__snapshots__/jsfmt.spec.js.snap | 12 +- .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/rec/__snapshots__/jsfmt.spec.js.snap | 6 + .../recheck/__snapshots__/jsfmt.spec.js.snap | 1 + .../tmp1b/__snapshots__/jsfmt.spec.js.snap | 1 + tests/record/__snapshots__/jsfmt.spec.js.snap | 2 + tests/refi/__snapshots__/jsfmt.spec.js.snap | 231 +++++++------- .../__snapshots__/jsfmt.spec.js.snap | 298 +++++++++++------- .../require/__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/return/__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 4 + tests/sealed/__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 5 + tests/spread/__snapshots__/jsfmt.spec.js.snap | 5 +- .../statics/__snapshots__/jsfmt.spec.js.snap | 2 + tests/strict/__snapshots__/jsfmt.spec.js.snap | 1 + .../suggest/__snapshots__/jsfmt.spec.js.snap | 1 + tests/super/__snapshots__/jsfmt.spec.js.snap | 29 +- .../suppress/__snapshots__/jsfmt.spec.js.snap | 1 + .../__snapshots__/jsfmt.spec.js.snap | 1 + tests/switch/__snapshots__/jsfmt.spec.js.snap | 59 ++-- tests/taint/__snapshots__/jsfmt.spec.js.snap | 15 +- .../template/__snapshots__/jsfmt.spec.js.snap | 17 +- tests/this/__snapshots__/jsfmt.spec.js.snap | 7 + .../__snapshots__/jsfmt.spec.js.snap | 5 + tests/throw/__snapshots__/jsfmt.spec.js.snap | 1 + tests/try/__snapshots__/jsfmt.spec.js.snap | 30 +- .../__snapshots__/jsfmt.spec.js.snap | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 2 + .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 4 + .../__snapshots__/jsfmt.spec.js.snap | 15 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- .../__snapshots__/jsfmt.spec.js.snap | 2 +- tests/unary/__snapshots__/jsfmt.spec.js.snap | 14 +- .../__snapshots__/jsfmt.spec.js.snap | 20 +- .../__snapshots__/jsfmt.spec.js.snap | 3 + tests/union/__snapshots__/jsfmt.spec.js.snap | 13 +- .../__snapshots__/jsfmt.spec.js.snap | 36 ++- .../__snapshots__/jsfmt.spec.js.snap | 8 +- tests/value/__snapshots__/jsfmt.spec.js.snap | 1 + tests/while/__snapshots__/jsfmt.spec.js.snap | 6 +- 155 files changed, 1383 insertions(+), 751 deletions(-) diff --git a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap index bf79f80d..76e876bc 100644 --- a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap @@ -34,10 +34,10 @@ function bar(x: number) {} function foo() { var x = null; - + if (x == null) return; - + bar(x); } " diff --git a/tests/annot/__snapshots__/jsfmt.spec.js.snap b/tests/annot/__snapshots__/jsfmt.spec.js.snap index a75960e3..fe89b24e 100644 --- a/tests/annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/annot/__snapshots__/jsfmt.spec.js.snap @@ -73,6 +73,7 @@ function barfoo(n : number | null | void) : ?number { return n; } function foo(str: string, i: number): string { return str; } + var bar: (str: number, i: number) => string = foo; var qux = function(str: string, i: number): number { return foo(str, i); @@ -111,6 +112,7 @@ function param_anno2( } ); } + var toz: null = 3; var zer: null = null; @@ -150,14 +152,16 @@ let myClassInstance: MyClass = null; function bar(): MyClass { return null; } + class MyClass {} function foo() { let myClassInstance: MyClass = mk(); - + function mk() { return new MyClass(); } + class MyClass {} } " @@ -271,8 +275,10 @@ function insertMany( function f([ k, v ]: [K, V], m: Map): Map { return m.insertWith(merge, k, v); } + return foldr(f, m, vs); } + class Foo { bar() { return function(a: A, b: B, c: C): void { diff --git a/tests/any/__snapshots__/jsfmt.spec.js.snap b/tests/any/__snapshots__/jsfmt.spec.js.snap index 454a59b0..eca2fa4b 100644 --- a/tests/any/__snapshots__/jsfmt.spec.js.snap +++ b/tests/any/__snapshots__/jsfmt.spec.js.snap @@ -21,6 +21,7 @@ function bar(x: any): mixed { function qux(x: mixed): any { return x; } + var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -82,6 +83,7 @@ function qux(x: $FlowFixMe): $FlowFixMe { function baz(x: $FlowFixMe): $FlowFixMe { return x; } + var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -134,6 +136,7 @@ function qux(x: $FlowIssue): $FlowIssue { function baz(x: $FlowIssue): $FlowIssue { return x; } + var x: string = foo(0); var y: string = bar(0); var z: string = qux(0); @@ -189,6 +192,7 @@ function foo(c: C, x: any): string { let y = x.y; return c.bar(0, y); } + var any_fun1 = require(\"./nonflowfile\"); function bar1(x: mixed) { @@ -196,6 +200,7 @@ function bar1(x: mixed) { (x: boolean); } } + var any_fun2 = require(\"./anyexportflowfile\"); function bar2(x: mixed) { diff --git a/tests/arith/__snapshots__/jsfmt.spec.js.snap b/tests/arith/__snapshots__/jsfmt.spec.js.snap index 9bcbcd2a..57189a5a 100644 --- a/tests/arith/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arith/__snapshots__/jsfmt.spec.js.snap @@ -140,15 +140,15 @@ function foo() { var x = 0; var y = \"...\"; var z = {}; - + num(x + x); - + num(x + y); - + str(x + y); - + str(x + x); - + str(z + y); } @@ -207,38 +207,39 @@ str(null + \"foo\"); str(\"foo\" + undefined); str(undefined + \"foo\"); + let tests = [ function(x: mixed, y: mixed) { x + y; - + x + 0; - + 0 + x; - + x + \"\"; - + \"\" + x; - + x + {}; - + ({}) + x; }, function() { (1 + {}: number); - + ({} + 1: number); - + (\"1\" + {}: string); - + ({} + \"1\": string); }, function(x: any, y: number, z: string) { (x + y: string); - + (y + x: string); - + (x + z: empty); - + (z + x: empty); } ]; @@ -263,6 +264,7 @@ y **= 2; // error let x: number = 2 ** 3; x **= 4; + let y: string = \"123\"; y **= 2; @@ -333,9 +335,11 @@ function num(x: number) {} num(null * 1); num(1 * null); + let x: number = 2 * 3; x *= 4; + let y: string = \"123\"; y *= 2; @@ -405,6 +409,7 @@ let tests = [ \"foo\" < { foo: 1 }; ({ foo: 1 }) < \"foo\"; + var x = (null: ?number); 1 < x; @@ -424,10 +429,11 @@ NaN < 1; 1 < NaN; NaN < NaN; + let tests = [ function(x: any, y: number, z: string) { x > y; - + x > z; } ]; diff --git a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap index e26b48bf..9a670575 100644 --- a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap @@ -49,6 +49,7 @@ function filterItems(items: Array): Array { } ).filter(Boolean); } + const filteredItems = filterItems([ \"foo\", \"b\", 1, 2 ]); console.log(filteredItems); diff --git a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap index f4dc70ce..aa3e6754 100644 --- a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap @@ -15,6 +15,7 @@ var C = [ 1, 2, 3 ]; B.sort((a, b) => a - b); C.sort((a, b) => a - b); + var x: Array = [ \"1\", \"2\" ]; var y: Array = [ \"3\", ...x ]; " diff --git a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap index 4a531058..2407f18e 100644 --- a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap @@ -67,10 +67,12 @@ function from_test() { // error, string ~> number // error, string ~> number function foo(x: string) {} + var a = [ 0 ]; var b = a.map( function(x) { foo(x); + return \"\" + x; } ); @@ -97,13 +99,14 @@ function reduce_test() { return previousValue + currentValue + array[index]; } ); - + [ 0, 1, 2, 3, 4 ].reduce( function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; }, 10 ); + var total = [ 0, 1, 2, 3 ].reduce( function(a, b) { return a + b; @@ -114,9 +117,9 @@ function reduce_test() { return a.concat(b); } ); - + [ \"\" ].reduce((acc, str) => acc * str.length); - + [ \"\" ].reduceRight((acc, str) => acc * str.length); } diff --git a/tests/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/arrays/__snapshots__/jsfmt.spec.js.snap index 4c470695..bcde1447 100644 --- a/tests/arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrays/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,7 @@ module.exports = \"arrays\"; // for literals, composite element type is union of individuals // note: test both tuple and non-tuple inferred literals function foo(x: string) {} + var a = []; a[0] = 1; @@ -50,9 +51,11 @@ a[0] = 1; a[1] = \"...\"; foo(a[1]); + var y; a.forEach(x => y = x); + var alittle: Array = [ 0, 1, 2, 3, null ]; var abig: Array = [ 0, 1, 2, 3, 4, 5, 6, 8, null ]; var abig2: Array<{ x: number; y: number }> = [ diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 07a5e9bc..df21eec1 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -43,8 +43,9 @@ function selectBestEffortImageForWidth( maxWidth: number, images: Array ): Image { var maxPixelWidth = maxWidth; - + images = images.sort((a, b) => a.width - b.width + \"\"); + return images.find(image => image.width >= maxPixelWidth) || images[images.length - 1]; } diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index e0d923f5..9dc530bf 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -89,6 +89,7 @@ async function f3(p: Promise): Promise { async function f4(p: Promise): Promise { return await p; } + var f5: () => Promise = async () => await 1; class C { async m() { @@ -172,6 +173,7 @@ var y = { async }; async function f() {} async function ft(a: T) {} + class C { async m() {} async mt(a: T) {} @@ -187,6 +189,7 @@ var oz = { async async() {} }; var x = { async: 5 }; console.log(x.async); + var async = 3; var y = { async }; " @@ -230,6 +233,7 @@ async function foo2(): Promise { async function foo3(): Promise { function bar() {} + return bar(); } " @@ -322,7 +326,7 @@ function test1() { async function foo() { return 42; } - + async function bar() { var a = await foo(); var b: number = a; @@ -334,6 +338,7 @@ function test2() { async function voidoid1() { console.log(\"HEY\"); } + var voidoid2: () => Promise = voidoid1; var voidoid3: () => void = voidoid1; } @@ -455,6 +460,7 @@ async function f() { async function ft(a: T) { await 1; } + class C { async m() { await 1; @@ -496,6 +502,7 @@ var oz = { var x = { await: 5 }; console.log(x.await); + var await = 3; var y = { await }; " diff --git a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap index 014a53e8..388610f4 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -33,7 +33,7 @@ async function* delegate_next() { async function* inner() { var x: void = yield; } - + yield* inner(); } @@ -43,7 +43,7 @@ async function* delegate_yield() { async function* inner() { yield 0; } - + yield* inner(); } @@ -57,6 +57,7 @@ async function* delegate_return() { async function* inner() { return 0; } + var x: void = yield* inner(); } " @@ -225,6 +226,7 @@ async () => { async function* yield_return() { try { yield 0; + return; } catch (e) { yield e; diff --git a/tests/binary/__snapshots__/jsfmt.spec.js.snap b/tests/binary/__snapshots__/jsfmt.spec.js.snap index 44033c7e..58da2c14 100644 --- a/tests/binary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary/__snapshots__/jsfmt.spec.js.snap @@ -78,58 +78,58 @@ let tests = [ let tests = [ function() { \"foo\" in {}; - + \"foo\" in { foo: null }; - + 0 in {}; - + 0 in { \"0\": null }; }, function() { \"foo\" in []; - + 0 in []; - + \"length\" in []; }, function() { \"foo\" in new String(\"bar\"); - + \"foo\" in new Number(123); }, function() { \"foo\" in 123; - + \"foo\" in \"bar\"; - + \"foo\" in void 0; - + \"foo\" in null; }, function() { null in {}; - + void 0 in {}; - + ({}) in {}; - + [] in {}; - + false in []; }, function() { if (\"foo\" in 123) {} - + if (!\"foo\" in {}) {} - + if (!(\"foo\" in {})) {} }, function(x: Object, y: mixed) { \"foo\" in x; - + \"foo\" in y; } ]; diff --git a/tests/binding/__snapshots__/jsfmt.spec.js.snap b/tests/binding/__snapshots__/jsfmt.spec.js.snap index 2c9fa916..fdbd971e 100644 --- a/tests/binding/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binding/__snapshots__/jsfmt.spec.js.snap @@ -57,12 +57,14 @@ x |= 0; x ^= 0; x &= 0; + const { foo } = { foo: \"foo\" }; const [ bar ] = [ \"bar\" ]; (foo: number); (bar: number); + declare var bazzes: { baz: string }[]; for (const { baz } of bazzes) { @@ -349,7 +351,7 @@ function type_var() { function type_reassign() { type A = number; - + A = 42; } @@ -430,7 +432,7 @@ function const_var() { function const_reassign() { const A = 0; - + A = 42; } @@ -461,15 +463,17 @@ function var_var() { function function_toplevel() { function a() {} - + function a() {} + } function function_block() { { function a() {} - + function a() {} + } } @@ -664,8 +668,9 @@ function switch_scope(x: string) { function switch_scope2(x: number) { switch (x) { case 0: - + a = \"\"; + break; case 1: var b = a; @@ -674,14 +679,15 @@ function switch_scope2(x: number) { let a = \"\"; break; case 3: - + a = \"\"; + break; case 4: var c: string = a; break; } - + a = \"\"; } @@ -698,42 +704,42 @@ function try_scope() { function for_scope_let() { let a: number = 0; - + for (let a = \"\"; ; ) {} } function for_scope_var() { var a: number = 0; - + for (var a = \"\"; ; ) {} } function for_in_scope_let(o: Object) { let a: number = 0; - + for (let a in o) {} } function for_in_scope_var(o: Object) { var a: number = 0; - + for (var a in o) {} } function for_of_scope_let(xs: string[]) { let a: number = 0; - + for (let a of xs) {} } function for_of_scope_var(xs: string[]) { var a: number = 0; - + for (var a of xs) {} } @@ -746,12 +752,12 @@ function default_param_1() { function default_param_2() { let a = \"\"; - + function f0(x = () => a): number { let a = 0; return x(); } - + function f1(x = b): number { let b = 0; return x; @@ -915,10 +921,12 @@ function f0() { function f1(b) { x = 10; + let x = 0; - + if (b) { y = 10; + let y = 0; } } @@ -935,13 +943,13 @@ function f3() { var s: string = foo(); { var n: number = foo(); - + function foo() { return 0; } } var s2: string = foo(); - + function foo() { return \"\"; } @@ -951,6 +959,7 @@ function f4() { function g() { return x + c; } + let x = 0; const c = 0; } @@ -959,11 +968,13 @@ function f5() { function g() { return x; } - + g(); + let x = 0; const c = 0; } + var x: C; var y = new C(); class C {} diff --git a/tests/bom/__snapshots__/jsfmt.spec.js.snap b/tests/bom/__snapshots__/jsfmt.spec.js.snap index 42d33ea1..f868ef83 100644 --- a/tests/bom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bom/__snapshots__/jsfmt.spec.js.snap @@ -131,6 +131,7 @@ new FormData(\"\"); new FormData(document.createElement(\"input\")); new FormData(document.createElement(\"form\")); + const b: boolean = a.has(\"foo\"); const c: ?(string | File) = a.get(\"foo\"); const d: string = a.get(\"foo\"); @@ -138,6 +139,7 @@ const e: Blob = a.get(\"foo\"); const f: ?(string | File | Blob) = a.get(\"foo\"); a.get(2); + const a1: Array = a.getAll(\"foo\"); const a2: Array = a.getAll(\"foo\"); const a3: Array = a.getAll(\"foo\"); @@ -276,6 +278,7 @@ function callback( ): void { return; } + const o: MutationObserver = new MutationObserver(callback); new MutationObserver((arr: Array) => true); @@ -287,6 +290,7 @@ new MutationObserver(); new MutationObserver(42); new MutationObserver((n: number) => {}); + const div = document.createElement(\"div\"); o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] }); diff --git a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap index 0739497c..c993d28a 100644 --- a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap @@ -56,6 +56,7 @@ function foo(x: T): T { var y: string = x; return x; } + class C { bar(x: U): T { return x; @@ -69,8 +70,10 @@ class C { function example(o: T): T { o.x = 0; + return o; } + var obj1: { x: number; y: string } = example({ x: 0, y: \"\" }); var obj2: { x: number } = example({ x: 0 }); var c: C = new C(); diff --git a/tests/break/__snapshots__/jsfmt.spec.js.snap b/tests/break/__snapshots__/jsfmt.spec.js.snap index 39604d62..9263509f 100644 --- a/tests/break/__snapshots__/jsfmt.spec.js.snap +++ b/tests/break/__snapshots__/jsfmt.spec.js.snap @@ -87,8 +87,10 @@ function foo(b) { while (b) { if (x == null) { z = \"\"; + break; } + var y: number = x; } var w: number = z; @@ -96,14 +98,16 @@ function foo(b) { function bar(b) { var x = (b ? null : false); - + if (x == null) return; + switch (\"\") { case 0: var y: number = x; - + x = \"\"; + case 1: var z: number = x; break; @@ -114,14 +118,15 @@ function bar(b) { function bar2(b) { var x = (b ? null : false); - + if (x == null) return; + switch (\"\") { case 0: { let y: number = x; - + x = \"\"; } case 1: @@ -138,12 +143,13 @@ function qux(b) { var z = 0; while (b) { var y: number = z; - + if (b) { z = \"\"; + continue; } - + z = 0; } var w: number = z; @@ -151,16 +157,17 @@ function qux(b) { function test_const() { let st: string = \"abc\"; - + for (let i = 1; i < 100; i++) { const fooRes: ?string = \"HEY\"; - + if (!fooRes) { break; } - + st = fooRes; } + return st; } " diff --git a/tests/builtins/__snapshots__/jsfmt.spec.js.snap b/tests/builtins/__snapshots__/jsfmt.spec.js.snap index e725d4b6..f6c1b5b1 100644 --- a/tests/builtins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtins/__snapshots__/jsfmt.spec.js.snap @@ -35,8 +35,10 @@ function f() { return \"...\"; } ); + var x: number = array[0]; } + var Foo = require(\"./genericfoo\"); var foo = new Foo(); @@ -47,7 +49,7 @@ function g() { } ); var x: number = foo1.get(); - + foo = foo1; } " diff --git a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap index e9048a5c..85fbde8a 100644 --- a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap @@ -226,6 +226,7 @@ function e(x: { (): string; (x: number): string }): () => number { function a(f: { (): string; (x: number): string }): string { return f() + f(123); } + var b: { (): string; (x: number): string } = function(x?: number): string { return \"hi\"; }; @@ -263,6 +264,7 @@ var b: { apply: Function } = function() {}; var f = function() {}; f.myProp = 123; + var c: { myProp: number } = f; " `; diff --git a/tests/callable/__snapshots__/jsfmt.spec.js.snap b/tests/callable/__snapshots__/jsfmt.spec.js.snap index 51a757bb..73e94b81 100644 --- a/tests/callable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/callable/__snapshots__/jsfmt.spec.js.snap @@ -53,15 +53,18 @@ var x = Boolean(4); function foo(fn: (value: any) => boolean) {} foo(Boolean); + var dict: { [k: string]: any } = {}; dict(); + interface ICall { (x: string): void } declare var icall: ICall; icall(0); icall.call(null, 0); + type Callable = { (x: string): void }; declare var callable: Callable; diff --git a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap index 50285692..f4c16f89 100644 --- a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap @@ -82,22 +82,23 @@ class A { } A.qux = function(x: string) {}; + class B extends A { static x: string; static foo(x: string) {} static main() { B.x = 0; - + B.x = \"\"; - + B.foo(0); - + B.foo(\"\"); - + B.y = 0; - + B.bar(0); - + B.qux(0); } static create(): A { @@ -117,7 +118,7 @@ class C { class D extends C { static main() { D.foo(0); - + D.bar(0); } } @@ -126,10 +127,12 @@ var d: C<*> = D.create(); (new A(): typeof A); (B: typeof A); + class E { static x: number; static foo(): string { this.bar(); + return this.x; } } diff --git a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap index 0f0d790d..2524c13c 100644 --- a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap @@ -68,9 +68,11 @@ class C { } function foo(c: C, x: X) {} + type O = { f: number }; foo((new C(): C), { f_: 0 }); + class D extends C { bar() { this.x; diff --git a/tests/class_type/__snapshots__/jsfmt.spec.js.snap b/tests/class_type/__snapshots__/jsfmt.spec.js.snap index 82b645d8..820819e9 100644 --- a/tests/class_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_type/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,7 @@ class A {} function foo(x: Class): A { return new x(); } + class B { constructor(_: any) {} } diff --git a/tests/classes/__snapshots__/jsfmt.spec.js.snap b/tests/classes/__snapshots__/jsfmt.spec.js.snap index c1393bd2..5bd00775 100644 --- a/tests/classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/classes/__snapshots__/jsfmt.spec.js.snap @@ -136,11 +136,13 @@ x.b; x.c; x.d; + var y: Foo = x; y.b; y.d; + class Test2Superclass { a: number; c: ?number; @@ -263,6 +265,7 @@ C.p = \"hi\"; (C: { p: string }); (C: { p: number }); + declare var o: { p: number }; (o: Class); diff --git a/tests/closure/__snapshots__/jsfmt.spec.js.snap b/tests/closure/__snapshots__/jsfmt.spec.js.snap index 07178866..55c2ec1f 100644 --- a/tests/closure/__snapshots__/jsfmt.spec.js.snap +++ b/tests/closure/__snapshots__/jsfmt.spec.js.snap @@ -105,6 +105,7 @@ function local_meth() { // error // shouldn\'t pollute linear refinement function takes_string(_: string) {} + var global_x = \"hello\"; function global_f() {} @@ -125,23 +126,24 @@ global_x = 42; function local_func() { var local_x = \"hello\"; - + function local_f() {} - + function local_g() { local_x = 42; } - + local_f(); - + takes_string(local_x); - + local_g(); - + takes_string(local_x); - + local_x = 42; } + var global_y = \"hello\"; var global_o = { f: function() {}, @@ -168,15 +170,15 @@ function local_meth() { local_y = 42; } }; - + local_o.f(); - + takes_string(local_y); - + local_o.g(); - + takes_string(local_y); - + local_y = 42; } " @@ -204,14 +206,15 @@ function example(b: bool): number { // error, string ~/~> number (return type anno) TODO function example(b: boolean): number { var x = 0; - + function f() { x = \"\"; } - + if (b) { f(); } + return x; } " @@ -285,26 +288,27 @@ var call_me: () => void = () => {}; function g(x: ?number) { const const_x = x; - + if (const_x) { call_me = () => { var y: number = const_x; }; } + var var_x = x; - + if (var_x) { call_me = () => { var y: number = var_x; }; } - + var_x = null; } function h(x: number | string | boolean) { const const_x = x; - + if (typeof const_x == \"number\") { call_me = () => { var y: number = const_x; @@ -320,8 +324,9 @@ function h(x: number | string | boolean) { var y: boolean = const_x; }; } + var var_x = x; - + if (typeof var_x == \"number\") { call_me = () => { var y: number = var_x; diff --git a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap index 0a1f59cb..9ef4e637 100644 --- a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap @@ -50,12 +50,13 @@ class A { } A._sProperty = 48; + class B extends A { _property1: string; static _sProperty: string; constructor() { super(); - + this._property1 = \"another string\"; } _method1(): string { diff --git a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap index 21652ccc..2a216b3b 100644 --- a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap @@ -50,12 +50,13 @@ class A { } A._sProperty = 48; + class B extends A { _property1: string; static _sProperty: string; constructor() { super(); - + this._property1 = \"another string\"; } _method1(): string { diff --git a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap index 6603a0e4..8d3b1719 100644 --- a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap +++ b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap @@ -42,6 +42,7 @@ Foo.prototype = { }; exports.Foo = Foo; + interface IFooPrototype { m(): number } interface IFoo extends IFooPrototype { static (): void; diff --git a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap index 0a245301..e6fd84cd 100644 --- a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap +++ b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap @@ -51,27 +51,28 @@ let tests = [ let tests = [ function() { new Boolean(); - + new Boolean(0); - + new Boolean(-0); - + new Boolean(null); - + new Boolean(false); - + new Boolean(NaN); - + new Boolean(undefined); - + new Boolean(\"\"); }, function() { true.toString(); + let x: boolean = false; - + x.toString(); - + new Boolean(true).toString(); }, function() { @@ -79,19 +80,19 @@ let tests = [ }, function() { Boolean(); - + Boolean(0); - + Boolean(-0); - + Boolean(null); - + Boolean(false); - + Boolean(NaN); - + Boolean(undefined); - + Boolean(\"\"); } ]; @@ -145,6 +146,7 @@ function* generator(): Iterable<[string, number]> { yield [ \"foo\", 123 ]; } } + let tests = [ function() { let w = new Map(); @@ -161,7 +163,7 @@ let tests = [ }, function(x: Map) { (x.get(\"foo\"): boolean); - + x.get(123); } ]; @@ -212,33 +214,33 @@ let tests = [ let tests = [ function() { new RegExp(\"foo\"); - + new RegExp(/foo/); - + new RegExp(\"foo\", \"i\"); - + new RegExp(\"foo\", \"ig\"); - + new RegExp(/foo/, \"i\"); - + new RegExp(/foo/g, \"i\"); }, function() { RegExp(\"foo\"); - + RegExp(/foo/); - + RegExp(\"foo\", \"i\"); - + RegExp(\"foo\", \"ig\"); - + RegExp(/foo/, \"i\"); - + RegExp(/foo/g, \"i\"); }, function() { RegExp(\"foo\", \"z\"); - + new RegExp(\"foo\", \"z\"); } ]; @@ -307,6 +309,7 @@ ws.delete(window); ws.delete(obj); ws.delete(dict); + let ws2 = new WeakSet([ obj, dict ]); let ws3 = new WeakSet([ 1, 2, 3 ]); @@ -315,6 +318,7 @@ function* generator(): Iterable<{ foo: string }> { yield { foo: \"bar\" }; } } + let ws4 = new WeakSet(generator()); function* numbers(): Iterable { @@ -323,6 +327,7 @@ function* numbers(): Iterable { yield i++; } } + let ws5 = new WeakSet(numbers()); " `; diff --git a/tests/covariance/__snapshots__/jsfmt.spec.js.snap b/tests/covariance/__snapshots__/jsfmt.spec.js.snap index c241a615..b680c9a3 100644 --- a/tests/covariance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/covariance/__snapshots__/jsfmt.spec.js.snap @@ -91,6 +91,7 @@ var b: CovArrayVerbose = []; var y: CovArrayVerbose = b; y[0] = \"\"; + class NVerbose { x: CovArrayVerbose; foo(): CovArrayVerbose { diff --git a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap index 3eaee5bc..593fee81 100644 --- a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap @@ -70,9 +70,11 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); var Implicit = require(\"ImplicitProvidesModule\"); (Implicit.fun(): string); + var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); (ExplicitSameName.fun(): string); + var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); (ExplicitDifferentName.fun(): string); diff --git a/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap index 552fd2b1..412a0f72 100644 --- a/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap @@ -95,9 +95,11 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); var Implicit = require(\"ImplicitProvidesModule\"); (Implicit.fun(): boolean); + var ExplicitSameName = require(\"ExplicitProvidesModuleSameName\"); (ExplicitSameName.fun(): boolean); + var ExplicitDifferentName = require(\"ExplicitProvidesModuleDifferentName\"); (ExplicitDifferentName.fun(): boolean); diff --git a/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap index a468d3d0..7347646a 100644 --- a/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap @@ -72,36 +72,47 @@ var F = require(\'package_with_dir_main\'); var B1 = require(\"B\"); (B1.fun(): boolean); + var B2 = require(\"B.js\"); (B2.fun(): boolean); + var C = require(\"package_with_full_main\"); (C.fun(): boolean); + var D = require(\"package_with_partial_main\"); (D.fun(): boolean); + var E = require(\"package_with_no_package_json\"); (E.fun(): boolean); + var F = require(\"package_with_dir_main\"); (F.fun(): boolean); + var B1 = require(\"B\"); (B1.fun(): boolean); + var B2 = require(\"B.js\"); (B2.fun(): boolean); + var C = require(\"package_with_full_main\"); (C.fun(): boolean); + var D = require(\"package_with_partial_main\"); (D.fun(): boolean); + var E = require(\"package_with_no_package_json\"); (E.fun(): boolean); + var F = require(\"package_with_dir_main\"); (F.fun(): boolean); diff --git a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap index 6d7aa63e..5baccdd1 100644 --- a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap @@ -52,18 +52,23 @@ var F = require(\'package_with_dir_main\'); var B1 = require(\"B\"); (B1.fun(): string); + var B2 = require(\"B.js\"); (B2.fun(): string); + var C = require(\"package_with_full_main\"); (C.fun(): string); + var D = require(\"package_with_partial_main\"); (D.fun(): string); + var E = require(\"package_with_no_package_json\"); (E.fun(): string); + var F = require(\"package_with_dir_main\"); (F.fun(): string); @@ -94,9 +99,11 @@ var CJS = require(\'./CJS.js\'); var A1 = require(\"./A\"); (A1.fun(): string); + var A2 = require(\"./A.js\"); (A2.fun(): string); + var CJS = require(\"./CJS.js\"); (CJS: string); diff --git a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap index 03c17847..58d7571f 100644 --- a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap @@ -992,11 +992,13 @@ var e1: number = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3; CJS_Clobb_Lit.doesntExist; + import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; CJS_Clobb_Lit_NS.default.default; + var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; import { doesntExist2 } from \"CommonJS_Clobbering_Class\"; @@ -1006,6 +1008,7 @@ import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; new CJS_Clobb_Class(); new CJS_Clobb_Class().doesntExist; + var h1: number = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2(); var h3: number = new CJS_Clobb_Class().instNumber1(); @@ -1013,6 +1016,7 @@ var h4: string = new CJS_Clobb_Class().instNumber1(); import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; new CJS_Clobb_Class_NS(); + var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); @@ -1028,6 +1032,7 @@ var l1: number = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1; CJS_Named.doesntExist; + import * as CJS_Named_NS from \"CommonJS_Named\"; var m1: number = CJS_Named_NS.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4; @@ -1079,6 +1084,7 @@ var ac1: number = numberValue5; var ac2: string = numberValue5; require(\"ES6_Default_AnonFunction2\").doesntExist; + var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ad1: number = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2(); diff --git a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap index b74156ce..e75f58a8 100644 --- a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap @@ -40,17 +40,20 @@ import declare_module_exports from \"declare_module_exports\"; (declare_module_exports: number); (declare_module_exports: string); + import { str } from \"declare_m_e_with_other_value_declares\"; import type { str2 } from \"declare_m_e_with_other_type_declares\"; (\"asdf\": str2); (42: str2); + import DEPRECATED__declare_var_exports from \"DEPRECATED__declare_var_exports\"; (DEPRECATED__declare_var_exports: number); (DEPRECATED__declare_var_exports: string); + import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; (declare_m_e_with_declare_var_e: number); diff --git a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap index ff4b3943..c7510e63 100644 --- a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap @@ -58,9 +58,10 @@ class B extends A {} function subtyping(v1: Variance, v2: Variance) { (v1: Variance); - + (v2: Variance); } + class PropVariance<+Out, -In> { inv1: Out; inv2: In; diff --git a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap index c053c77b..4b03d887 100644 --- a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,7 @@ f(x); function f(x) { return 42 / x; } + var x = null; f(x); diff --git a/tests/demo/2/__snapshots__/jsfmt.spec.js.snap b/tests/demo/2/__snapshots__/jsfmt.spec.js.snap index bb139e95..e4017d9c 100644 --- a/tests/demo/2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/2/__snapshots__/jsfmt.spec.js.snap @@ -37,6 +37,7 @@ class A { function callback(x: string) { return x.length; } + var a = new A(42); a.onLoad(callback); diff --git a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap index 58122218..704fbb65 100644 --- a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap +++ b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap @@ -31,6 +31,7 @@ let d = zs[1]; (c: void); (d: void); + let [ ...e ] = 0; " `; @@ -52,10 +53,12 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" }; var { [\"key\"]: val1 } = { key: \"val\" }; (val1: void); + var key: string = \"key\"; var { [key]: val2 } = { key: \"val\" }; (val2: void); + var { [\"key\"]: val3, ...spread } = { key: \"val\" }; (spread.key: void); @@ -201,7 +204,7 @@ obj_prop_fun({ p: { q: null } }); function obj_prop_var(o = { p: { q: \"\" } }) { var { p: { q = 0 } = { q: true } } = o; - + (q: void); } @@ -230,6 +233,7 @@ obj_rest({ p: { q: 0, r: null } }); function obj_prop_annot({ p = true }: { p: string } = { p: 0 }) { (p: void); } + var { p = true }: { p: string } = { p: 0 }; (p: void); @@ -348,9 +352,11 @@ declare var b: string; declare var c: string; [ { a1: a, b }, c ] = [ { a1: 0, b: 1 }, 2 ]; + var { m } = { m: 0 }; ({ m } = { m: m }); + var obj; ({ n: obj.x } = { n: 3 }); @@ -359,9 +365,9 @@ var obj; function foo({ p, z: [ r ] }) { a = p; - + b = z; - + c = r; } @@ -374,6 +380,7 @@ function bar({ x, ...z }) { } bar({ x: \"\", y: 0 }); + var spread = { y: \"\" }; var extend: { x: number; y: string; z: boolean } = { x: 0, ...spread }; @@ -384,6 +391,7 @@ qux({ a: \"\" }); function corge({ b }: { b: string }) {} corge({ b: 0 }); + var { n }: { n: number } = { n: \"\" }; function test() { @@ -394,13 +402,14 @@ function test() { function test() { var x = { foo: \"abc\", bar: 123 }; var { foo, ...rest } = x; - + (x.baz: string); - + (rest.baz: string); } module.exports = corge; + class Base { baseprop1: number; baseprop2: number; @@ -507,16 +516,19 @@ function arr_rest_pattern([ _, ...a ] : ArrRest) { // a: [X] // a: [X] // a: [X] function obj_pattern({ prop }: { prop: X }) {} + type Prop = { prop: X }; function obj_pattern2({ prop }: Prop) {} function arr_pattern([ elem ]: X[]) {} + type Elem = X[]; function arr_pattern2([ elem ]: Elem) {} function tup_pattern([ proj ]: [X]) {} + type Proj = [X]; function tup_pattern2([ proj ]: Proj) {} @@ -528,6 +540,7 @@ function rest_pattern(...r: X[]) {} function obj_rest_pattern({ _, ...o }: { _: any; x: X }) { o.x; } + type ObjRest = { _: any; x: X }; function obj_rest_pattern({ _, ...o }: ObjRest) { @@ -537,6 +550,7 @@ function obj_rest_pattern({ _, ...o }: ObjRest) { function arr_rest_pattern([ _, ...a ]: [any, X]) { a[0]; } + type ArrRest = [any, X]; function arr_rest_pattern([ _, ...a ]: ArrRest) { @@ -574,12 +588,14 @@ var { x: o } = o; let foo = (i: number) => [ i ]; const bar = (i: number) => { [ i ] = foo(i); + return [ i ]; }; foo = (i: number) => { return bar(i); }; + declare var o; var { x: o } = o; " @@ -597,6 +613,7 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; var { \"key\": val } = { key: \"val\" }; (val: void); + var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; (with_dash: \"motivating example\"); diff --git a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap index 97598de5..2331dcfa 100644 --- a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,7 @@ function foo0(x: Array<{ [key: string]: mixed }>): Array<{ [key: string]: mixed }> { x[0].fooBar = \"foobar\"; + return x; } @@ -511,23 +512,23 @@ function set_prop_to_string_key(o: { [k: string]: any }) { function unsound_dict_has_every_key(o: { [k: string]: X }) { (o.p: X); - + (o[\"p\"]: X); } function set_prop_covariant(o: { [k: string]: B }) { o.p = new A(); - + o.p = new B(); - + o.p = new C(); } function get_prop_contravariant(o: { [k: string]: B }) { (o.p: A); - + (o.p: B); - + (o.p: C); } @@ -541,11 +542,11 @@ function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) { function mix_with_declared_props(o: { [k: number]: X; p: Y }, x: X, y: Y) { (o[0]: X); - + (o.p: Y); - + o[0] = x; - + o.p = y; } @@ -554,6 +555,7 @@ function object_prototype(o: { [k: string]: number }): { +toString: () => string } { (o.toString(): boolean); + return o; } @@ -565,21 +567,23 @@ function unsound_string_conversion_alias_declared_prop( function unification_dict_values_invariant(x: Array<{ [k: string]: B }>) { let a: Array<{ [k: string]: A }> = x; - + a[0].p = new A(); + let b: Array<{ [k: string]: B }> = x; let c: Array<{ [k: string]: C }> = x; - + (x[0].p: C); } function subtype_dict_values_invariant(x: { [k: string]: B }) { let a: { [k: string]: A } = x; - + a.p = new A(); + let b: { [k: string]: B } = x; let c: { [k: string]: C } = x; - + (x.p: C); } @@ -605,11 +609,12 @@ function unification_mix_with_declared_props_invariant_l( x: Array<{ [k: string]: B }> ) { let a: Array<{ [k: string]: B; p: A }> = x; - + a[0].p = new A(); + let b: Array<{ [k: string]: B; p: B }> = x; let c: Array<{ [k: string]: B; p: C }> = x; - + (x[0].p: C); } @@ -619,21 +624,23 @@ function unification_mix_with_declared_props_invariant_r( xc: Array<{ [k: string]: C; p: B }> ) { let a: Array<{ [k: string]: A }> = xa; - + a[0].p = new A(); + let b: Array<{ [k: string]: B }> = xb; let c: Array<{ [k: string]: C }> = xc; - + (xc[0].p: C); } function subtype_mix_with_declared_props_invariant_l(x: { [k: string]: B }) { let a: { [k: string]: B; p: A } = x; - + a.p = new A(); + let b: { [k: string]: B; p: B } = x; let c: { [k: string]: B; p: C } = x; - + (x.p: C); } @@ -643,11 +650,12 @@ function subtype_mix_with_declared_props_invariant_r( xc: { [k: string]: C; p: B } ) { let a: { [k: string]: A } = xa; - + a.p = new A(); + let b: { [k: string]: B } = xb; let c: { [k: string]: C } = xc; - + (xc.p: C); } @@ -665,21 +673,23 @@ function unification_obj_to_dict(x: Array<{ p: X }>): Array<{ function subtype_dict_to_obj(x: { [k: string]: B }) { let a: { p: A } = x; - + a.p = new A(); + let b: { p: B } = x; let c: { p: C } = x; - + (x.p: C); } function subtype_obj_to_dict(x: { p: B }) { let a: { [k: string]: A } = x; - + a.p = new A(); + let b: { [k: string]: B } = x; let c: { [k: string]: C } = x; - + (x.p: C); } @@ -825,6 +835,7 @@ function foo2(x: Array<{ [key: string]: mixed }>): Array<{ fooBar: string }> { x[0].fooBar = 123; + return x; } @@ -853,7 +864,7 @@ function foo7(x: { [key: string]: number; bar: string }) { function foo8(x: { [key: string]: number }) { (x.foo: string); - + (x.foo: number); } " diff --git a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap index 422389c1..72753784 100644 --- a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap @@ -230,6 +230,7 @@ function getBinaryOp( throw new Error(\"Invalid binary operator: \" + op); } } + export function emitExpression(node: TypedNode): t.Expression { switch (node.exprNodeType) { case \"string_literal\": diff --git a/tests/dom/__snapshots__/jsfmt.spec.js.snap b/tests/dom/__snapshots__/jsfmt.spec.js.snap index 0b1180a5..74eda3ec 100644 --- a/tests/dom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dom/__snapshots__/jsfmt.spec.js.snap @@ -44,7 +44,7 @@ let tests = [ let tests = [ function(document: Document) { const event = document.createEvent(\"CustomEvent\"); - + event.initCustomEvent(\"butts\", true, false, { nice: 42 }); } ]; @@ -69,11 +69,11 @@ let tests = [ let tests = [ function(document: Document) { (document.createElement(\"canvas\"): HTMLCanvasElement); - + (document.createElement(\"link\"): HTMLLinkElement); - + (document.createElement(\"option\"): HTMLOptionElement); - + (document.createElement(\"select\"): HTMLSelectElement); } ]; @@ -106,21 +106,21 @@ let tests = [ let tests = [ function(element: Element) { element.scrollIntoView(); - + element.scrollIntoView(false); - + element.scrollIntoView({}); - + element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); - + element.scrollIntoView({ block: \"end\" }); - + element.scrollIntoView({ behavior: \"smooth\" }); - + element.scrollIntoView({ behavior: \"invalid\" }); - + element.scrollIntoView({ block: \"invalid\" }); - + element.scrollIntoView(1); } ]; @@ -173,21 +173,21 @@ let tests = [ let tests = [ function(element: HTMLElement) { element.scrollIntoView(); - + element.scrollIntoView(false); - + element.scrollIntoView({}); - + element.scrollIntoView({ behavior: \"smooth\", block: \"end\" }); - + element.scrollIntoView({ block: \"end\" }); - + element.scrollIntoView({ behavior: \"smooth\" }); - + element.scrollIntoView({ behavior: \"invalid\" }); - + element.scrollIntoView({ block: \"invalid\" }); - + element.scrollIntoView(1); } ]; @@ -215,13 +215,13 @@ let tests = [ let tests = [ function(el: HTMLInputElement) { el.setRangeText(\"foo\"); - + el.setRangeText(\"foo\", 123); - + el.setRangeText(\"foo\", 123, 234); - + el.setRangeText(\"foo\", 123, 234, \"select\"); - + el.setRangeText(\"foo\", 123, 234, \"bogus\"); } ]; @@ -326,16 +326,16 @@ let listener: EventListener = function(event: Event): void {}; let tests = [ function() { let target = new EventTarget(); - + (target.attachEvent(\"foo\", listener): void); - + (target.attachEvent && target.attachEvent(\"foo\", listener): void); }, function() { let target = new EventTarget(); - + (target.detachEvent(\"foo\", listener): void); - + (target.detachEvent && target.detachEvent(\"foo\", listener): void); }, function() { @@ -368,11 +368,11 @@ let tests = [ let tests = [ function() { let path = new Path2D(); - + (path.arcTo(0, 0, 0, 0, 10): void); - + (path.arcTo(0, 0, 0, 0, 10, 20, 5): void); - + (path.arcTo(0, 0, 0, 0, 10, \"20\", 5): void); } ]; @@ -737,12 +737,12 @@ let tests = [ }, function() { document.createNodeIterator(document.body); - + document.createNodeIterator({}); }, function() { document.createTreeWalker(document.body); - + document.createTreeWalker({}); }, function() { @@ -904,21 +904,21 @@ let tests = [ -1, node => NodeFilter.FILTER_ACCEPT ); - + document.createNodeIterator(document.body, -1, node => \"accept\"); - + document.createNodeIterator( document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT } ); - + document.createNodeIterator( document.body, -1, { accept: node => \"accept\" } ); - + document.createNodeIterator(document.body, -1, {}); }, function() { @@ -927,17 +927,17 @@ let tests = [ -1, node => NodeFilter.FILTER_ACCEPT ); - + document.createTreeWalker(document.body, -1, node => \"accept\"); - + document.createTreeWalker( document.body, -1, { accept: node => NodeFilter.FILTER_ACCEPT } ); - + document.createTreeWalker(document.body, -1, { accept: node => \"accept\" }); - + document.createTreeWalker(document.body, -1, {}); } ]; diff --git a/tests/dump-types/__snapshots__/jsfmt.spec.js.snap b/tests/dump-types/__snapshots__/jsfmt.spec.js.snap index 572f4fc2..29db5281 100644 --- a/tests/dump-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dump-types/__snapshots__/jsfmt.spec.js.snap @@ -46,11 +46,13 @@ var num = require(\"./import\"); function foo(x) {} foo(0); + var a: string = num; function unannotated(x) { return x; } + const nullToUndefined = val => (val === null ? undefined : val); function f0(x: ?Object) { @@ -68,6 +70,7 @@ function f2(x: ?string) { function f3(x: ?string) { return nullToUndefined(x); } + declare var idx: $Facebookism$Idx; declare var obj: { a?: { b: ?{ c: null | { d: number } } } }; const idxResult = idx(obj, obj => obj.a.b.c.d); diff --git a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap index 824f0064..8eb108bc 100644 --- a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap +++ b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap @@ -41,6 +41,7 @@ class C1 { } new C1().m(); + class C2 { get m() { return 42; @@ -49,12 +50,14 @@ class C2 { } new C2().m(); + class C3 { set m(x) {} m() {} } new C3().m(); + class C4 { get m() { return 42; @@ -63,6 +66,7 @@ class C4 { } new C4().m = new C4().m - 42; + class C5 { m() {} get m() { diff --git a/tests/encaps/__snapshots__/jsfmt.spec.js.snap b/tests/encaps/__snapshots__/jsfmt.spec.js.snap index 2af69fbe..a09e17e1 100644 --- a/tests/encaps/__snapshots__/jsfmt.spec.js.snap +++ b/tests/encaps/__snapshots__/jsfmt.spec.js.snap @@ -28,11 +28,13 @@ function tag(strings, ...values) { var x: number = strings[0]; return x; } + var s2 = tag\`l\${42}r\`; function tag2(strings, ...values) { return { foo: \"\" }; } + var s3 = tag2\`la la la\`; (s3.foo: number); diff --git a/tests/enumerror/__snapshots__/jsfmt.spec.js.snap b/tests/enumerror/__snapshots__/jsfmt.spec.js.snap index 5eccbf4b..3285e438 100644 --- a/tests/enumerror/__snapshots__/jsfmt.spec.js.snap +++ b/tests/enumerror/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,7 @@ function isActive( } isActive({ state: \"PAUSE\" }); + var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" }; function isActive2(ad: { state: $Keys }): boolean { @@ -43,6 +44,7 @@ function isActive2(ad: { state: $Keys }): boolean { } isActive2({ state: \"PAUSE\" }); + type Keys = $Keys<{ x: any; y: any }>; type Union = \"x\" | \"y\"; diff --git a/tests/equals/__snapshots__/jsfmt.spec.js.snap b/tests/equals/__snapshots__/jsfmt.spec.js.snap index a5cde890..dd104c69 100644 --- a/tests/equals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/equals/__snapshots__/jsfmt.spec.js.snap @@ -26,6 +26,7 @@ null == 1; 1 == \"\"; \"\" == 1; + var x = (null: ?number); x == 1; diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap index 6a23fea2..ead27c17 100644 --- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap @@ -1102,11 +1102,13 @@ var e1: number = CJS_Clobb_Lit.numberValue3; var e2: string = CJS_Clobb_Lit.numberValue3; CJS_Clobb_Lit.doesntExist; + import * as CJS_Clobb_Lit_NS from \"CommonJS_Clobbering_Lit\"; var f1: number = CJS_Clobb_Lit_NS.numberValue4; var f2: number = CJS_Clobb_Lit_NS.default.numberValue4; CJS_Clobb_Lit_NS.default.default; + var f3: string = CJS_Clobb_Lit_NS.numberValue4; var f4: string = CJS_Clobb_Lit_NS.default.numberValue5; import { doesntExist2 } from \"CommonJS_Clobbering_Class\"; @@ -1116,6 +1118,7 @@ import CJS_Clobb_Class from \"CommonJS_Clobbering_Class\"; new CJS_Clobb_Class(); new CJS_Clobb_Class().doesntExist; + var h1: number = CJS_Clobb_Class.staticNumber2(); var h2: string = CJS_Clobb_Class.staticNumber2(); var h3: number = new CJS_Clobb_Class().instNumber1(); @@ -1123,6 +1126,7 @@ var h4: string = new CJS_Clobb_Class().instNumber1(); import * as CJS_Clobb_Class_NS from \"CommonJS_Clobbering_Class\"; new CJS_Clobb_Class_NS(); + var i1: number = CJS_Clobb_Class_NS.staticNumber3(); var i2: number = new CJS_Clobb_Class_NS.default().instNumber2(); var i3: string = new CJS_Clobb_Class_NS.default().instNumber2(); @@ -1138,6 +1142,7 @@ var l1: number = CJS_Named.numberValue1; var l2: string = CJS_Named.numberValue1; CJS_Named.doesntExist; + import * as CJS_Named_NS from \"CommonJS_Named\"; var m1: number = CJS_Named_NS.numberValue4; var m2: string = CJS_Named_NS.default.numberValue4; @@ -1198,6 +1203,7 @@ var ac1: number = numberValue5; var ac2: string = numberValue5; require(\"ES6_Default_AnonFunction2\").doesntExist; + var ES6_Def_AnonFunc2 = require(\"ES6_Default_AnonFunction2\").default; var ad1: number = ES6_Def_AnonFunc2(); var ad2: string = ES6_Def_AnonFunc2(); @@ -1352,38 +1358,46 @@ function testRequires() { import * as DefaultA from \"A\"; DefaultA.numberValue1 = 123; + import * as ES6_Named1 from \"ES6_Named1\"; ES6_Named1.varDeclNumber1 = 123; + import * as CommonJS_Star from \"CommonJS_Clobbering_Lit\"; CommonJS_Star.numberValue1 = 123; CommonJS_Star.default.numberValue1 = 123; + import CommonJS_Clobbering_Lit from \"CommonJS_Clobbering_Lit\"; CommonJS_Clobbering_Lit.numberValue1 = 123; + import * as CommonJS_Frozen_Star from \"CommonJS_Clobbering_Frozen\"; CommonJS_Frozen_Star.numberValue1 = 123; CommonJS_Frozen_Star.default.numberValue1 = 123; + import CommonJS_Clobbering_Frozen from \"CommonJS_Clobbering_Frozen\"; CommonJS_Clobbering_Frozen.numberValue1 = 123; function testRequires() { var DefaultA = require(\"A\"); - + DefaultA.numberValue1 = 123; + var ES6_Named1 = require(\"ES6_Named1\"); - + ES6_Named1.numberValue = 123; + var CommonJS_Star = require(\"CommonJS_Clobbering_Lit\"); - + CommonJS_Star.numberValue1 = 123; + var CommonJS_Frozen_Star = require(\"CommonJS_Clobbering_Frozen\"); - + CommonJS_Frozen_Star.numberValue1 = 123; } " diff --git a/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap b/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap index 6c18783e..738358f1 100644 --- a/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap @@ -70,28 +70,33 @@ import CJS_Named from \"CJS_Named\"; (CJS_Named: { num1: number; str1: string }); (CJS_Named: number); + import { num2 } from \"CJS_Clobbered\"; import { numExport } from \"CJS_Clobbered\"; (numExport: number); (numExport: string); + import type { numType } from \"CJS_Clobbered\"; (42: numType); (\"asdf\": numType); + import { strHidden } from \"ES\"; import { str3 } from \"ES\"; (str3: string); (str3: number); + import { num3 } from \"ES\"; (num3: number); (num3: string); + import { C } from \"ES\"; import type { C as CType } from \"ES\"; @@ -102,12 +107,14 @@ import type { C as CType } from \"ES\"; (new C(): CType); (42: CType); + import { T } from \"ES\"; import type { T as T2 } from \"ES\"; (42: T2); (\"asdf\": T2); + import { exports as nope } from \"ES\"; " `; diff --git a/tests/export_default/__snapshots__/jsfmt.spec.js.snap b/tests/export_default/__snapshots__/jsfmt.spec.js.snap index 8509e6a7..7fb847c6 100644 --- a/tests/export_default/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_default/__snapshots__/jsfmt.spec.js.snap @@ -20,9 +20,11 @@ var M = require(\"M\"); var N = require(\"N\"); N.x = M(N.x); + var P = require(\"./P\"); N.y = P(N.y); + var Q = require(\"Q\"); N.z = Q(N.z); diff --git a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap index a9e945a1..bd5a7a99 100644 --- a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap @@ -63,9 +63,9 @@ let tests = [ }, function(copyProperties: Object$Assign) { let result = {}; - + result.baz = false; - + (copyProperties(result, { foo: \"a\" }, { bar: 123 }): { foo: string; bar: number; @@ -76,17 +76,17 @@ let tests = [ const copyProperties = require(\"copyProperties\"); let x = { foo: \"a\" }; let y = { bar: 123 }; - + (copyProperties({}, x, y): { foo: string; bar: number }); }, function(copyProperties: Object$Assign) { copyProperties(); - + (copyProperties({ foo: \"a\" }): { foo: number }); }, function(copyProperties: Object$Assign) { function x(cb: Function) {} - + x(copyProperties); } ]; @@ -114,14 +114,14 @@ let tests = [ let tests = [ function() { let x: ?string = null; - + invariant(x, \"truthy only\"); }, function(invariant: Function) { let x: ?string = null; - + invariant(x); - + (x: string); } ]; @@ -202,17 +202,17 @@ let tests = [ }, function(mergeInto: $Facebookism$MergeInto) { let result = {}; - + result.baz = false; - + (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); - + (result: { foo: string; bar: number; baz: boolean }); }, function() { const mergeInto = require(\"mergeInto\"); let result: { foo?: string; bar?: number; baz: boolean } = { baz: false }; - + (mergeInto(result, { foo: \"a\" }, { bar: 123 }): void); }, function(mergeInto: $Facebookism$MergeInto) { @@ -220,7 +220,7 @@ let tests = [ }, function(mergeInto: $Facebookism$MergeInto) { function x(cb: Function) {} - + x(mergeInto); } ]; @@ -243,7 +243,7 @@ var mixin = require(\"mixin\"); class Foo extends mixin(Bar) { m() { var x: string = this.x; - + this.y = \"\"; } } diff --git a/tests/fetch/__snapshots__/jsfmt.spec.js.snap b/tests/fetch/__snapshots__/jsfmt.spec.js.snap index c32c6e63..03815286 100644 --- a/tests/fetch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fetch/__snapshots__/jsfmt.spec.js.snap @@ -110,6 +110,7 @@ e.set(\"Content-Type\", \"image/jpeg\"); e.set(\"Content-Type\"); e.set({ \"Content-Type\", \"image/jpeg\" }); + const f: Headers = e.append(\"Content-Type\", \"image/jpeg\"); const g: string = e.get(\"Content-Type\"); const h: number = e.get(\"Content-Type\"); @@ -412,6 +413,7 @@ e.set(\"key1\", \"value1\"); e.set(\"key1\"); e.set({ \"key1\", \"value1\" }); + const f: URLSearchParams = e.append(\"key1\", \"value1\"); const g: string = e.get(\"key1\"); const h: number = e.get(\"key1\"); diff --git a/tests/find-module/__snapshots__/jsfmt.spec.js.snap b/tests/find-module/__snapshots__/jsfmt.spec.js.snap index 697b1ef8..8a762fae 100644 --- a/tests/find-module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/find-module/__snapshots__/jsfmt.spec.js.snap @@ -14,6 +14,7 @@ import x from \'./req\'; var x = require(\"./req\"); (x: string); + import x from \"./req\"; " `; diff --git a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap index 0e02c629..ed69dec0 100644 --- a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap @@ -62,11 +62,13 @@ function mk_factorial() { if (eq(n, 1)) { return 1; } + return mul(factorial(sub(n, 1)), n); }; } ); } + var factorial = mk_factorial(); factorial(\"...\"); @@ -103,7 +105,7 @@ function Y(f) { function g(x) { return f(x(x)); } - + g(g); } @@ -111,6 +113,7 @@ function func1(f) { function fix_f(x: number): number { return f(x); } + return fix_f; } @@ -118,6 +121,7 @@ function func2(f) { function fix_f(x: string): string { return f(x); } + return fix_f; } diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 074fab5f..6475c32b 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -50,34 +50,35 @@ function corge(x: boolean) { /* @flow */ function foo(x: boolean) { var max = 10; - + for (var ii = 0; ii < max; ii++) { if (x) { continue; } + return; } - + console.log(\"this is still reachable\"); } function bar(x: boolean) { var max = 0; - + for (var ii = 0; ii < max; ii++) { return; } - + console.log(\"this is still reachable\"); } function baz(x: boolean) { var max = 0; - + for (var ii = 0; ii < max; ii++) { continue; } - + console.log(\"this is still reachable\"); } @@ -89,20 +90,20 @@ function bliffl(x: boolean) { for (var jj = 0; jj < max; jj++) { break loop1; } - + console.log(\"this is still reachable\"); } - + console.log(\"this is still reachable\"); } function corge(x: boolean) { var max = 0; - + for (var ii = 0; ii < max; ii++) { break; } - + console.log(\"this is still reachable\"); } " @@ -154,14 +155,15 @@ function corge(x: boolean) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: boolean) { var obj = { a: 1, b: 2 }; - + for (var prop in obj) { if (x) { continue; } + return; } - + console.log(\"this is still reachable\"); } @@ -169,7 +171,7 @@ function bar(x: boolean) { for (var prop in {}) { return; } - + console.log(\"this is still reachable\"); } @@ -177,7 +179,7 @@ function baz(x: boolean) { for (var prop in {}) { continue; } - + console.log(\"this is still reachable\"); } @@ -189,10 +191,10 @@ function bliffl(x: boolean) { for (var prop2 in obj) { break loop1; } - + console.log(\"this is still reachable\"); } - + console.log(\"this is still reachable\"); } @@ -200,7 +202,7 @@ function corge(x: boolean) { for (var prop in {}) { break; } - + console.log(\"this is still reachable\"); } " @@ -252,14 +254,15 @@ function corge(x: boolean) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: boolean) { var arr = [ 1, 2, 3 ]; - + for (var elem of arr) { if (x) { continue; } + return; } - + console.log(\"this is still reachable\"); } @@ -267,7 +270,7 @@ function bar(x: boolean) { for (var elem of []) { return; } - + console.log(\"this is still reachable\"); } @@ -275,7 +278,7 @@ function baz(x: boolean) { for (var elem of []) { continue; } - + console.log(\"this is still reachable\"); } @@ -287,10 +290,10 @@ function bliffl(x: boolean) { for (var elem of arr) { break loop1; } - + console.log(\"this is still reachable\"); } - + console.log(\"this is still reachable\"); } @@ -298,7 +301,7 @@ function corge(x: boolean) { for (var elem of []) { break; } - + console.log(\"this is still reachable\"); } " diff --git a/tests/forof/__snapshots__/jsfmt.spec.js.snap b/tests/forof/__snapshots__/jsfmt.spec.js.snap index 66b73fce..ef70b0ae 100644 --- a/tests/forof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/forof/__snapshots__/jsfmt.spec.js.snap @@ -91,7 +91,7 @@ function testString(str: string): void { function testMap1(map: Map): void { for (var elem of map) { (elem: [string, number]); - + (elem: number); } } @@ -99,7 +99,7 @@ function testMap1(map: Map): void { function testMap2(map: Map<*, *>): void { for (var elem of map) { (elem: [number, string]); - + (elem: number); } } diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index 287d9de5..ff8bdb28 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -123,9 +123,9 @@ let tests = [ let tests = [ function(x: (a: string, b: string) => void) { let y = x.bind(x, \"foo\"); - + y(\"bar\"); - + y(123); } ]; @@ -325,19 +325,21 @@ var c: Function = C; function good(x: Function, MyThing: Function): number { var o: Object = x; - + x.foo = 123; - + x[\"foo\"] = 456; - + x(); - + ; + var { ...something } = x; - + Object.assign(x, { hi: \"there\" }); - + Object.keys(x); + return x.bar + x[\"bar\"] + x.lala(); } @@ -346,39 +348,40 @@ function bad(x: Function, y: Object): void { var b: string = x; var c: Function = y; } + let tests = [ function(y: () => void, z: Function) { function x() {} - + (x.length: void); - + (y.length: void); - + (z.length: void); - + (x.name: void); - + (y.name: void); - + (z.name: void); }, function(y: () => void, z: Function) { function x() {} - + x.length = \"foo\"; - + y.length = \"foo\"; - + z.length = \"foo\"; - + x.name = 123; - + y.name = 123; - + z.name = 123; - + (z.foo: number); - + (z.foo: string); } ]; diff --git a/tests/generators/__snapshots__/jsfmt.spec.js.snap b/tests/generators/__snapshots__/jsfmt.spec.js.snap index 1ae917a6..c68c2740 100644 --- a/tests/generators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generators/__snapshots__/jsfmt.spec.js.snap @@ -151,17 +151,18 @@ for (var x of examples.delegate_yield_iterable([])) { class GeneratorExamples { *stmt_yield(): Generator { yield 0; - + yield \"\"; } *stmt_next(): Generator { var a = yield; - + if (a) { (a: number); } + var b = yield; - + if (b) { (b: string); } @@ -178,7 +179,7 @@ class GeneratorExamples { } *widen_next() { var x = yield 0; - + if (typeof x === \"number\") {} else @@ -190,29 +191,30 @@ else { } *widen_yield() { yield 0; - + yield \"\"; - + yield true; } *delegate_next_generator() { function* inner() { var x: number = yield; } - + yield* inner(); } *delegate_yield_generator() { function* inner() { yield \"\"; } - + yield* inner(); } *delegate_return_generator() { function* inner() { return \"\"; } + var x: number = yield* inner(); } *delegate_next_iterable(xs: Array) { @@ -239,6 +241,7 @@ var examples = new GeneratorExamples(); for (var x of examples.infer_stmt()) { (x: string); } + var infer_stmt_next = examples.infer_stmt().next(0).value; if (typeof infer_stmt_next === \"undefined\") @@ -319,6 +322,7 @@ var examples = new GeneratorExamples(); for (var x of examples.infer_stmt()) { (x: string); } + var infer_stmt_next = examples.infer_stmt().next(0).value; if (typeof infer_stmt_next === \"undefined\") @@ -484,18 +488,19 @@ if (multiple_return_result.done) { // error: number|string ~> void function* stmt_yield(): Generator { yield 0; - + yield \"\"; } function* stmt_next(): Generator { var a = yield; - + if (a) { (a: number); } + var b = yield; - + if (b) { (b: string); } @@ -517,6 +522,7 @@ function* infer_stmt() { for (var x of infer_stmt()) { (x: string); } + var infer_stmt_next = infer_stmt().next(0).value; if (typeof infer_stmt_next === \"undefined\") @@ -530,7 +536,7 @@ else { function* widen_next() { var x = yield 0; - + if (typeof x === \"number\") {} else @@ -549,9 +555,9 @@ widen_next().next(true); function* widen_yield() { yield 0; - + yield \"\"; - + yield true; } @@ -570,7 +576,7 @@ function* delegate_next_generator() { function* inner() { var x: number = yield; } - + yield* inner(); } @@ -580,7 +586,7 @@ function* delegate_yield_generator() { function* inner() { yield \"\"; } - + yield* inner(); } @@ -592,6 +598,7 @@ function* delegate_return_generator() { function* inner() { return \"\"; } + var x: number = yield* inner(); } @@ -632,6 +639,7 @@ function* multiple_return(b) { return \"foo\"; } } + let multiple_return_result = multiple_return().next(); if (multiple_return_result.done) { @@ -671,7 +679,7 @@ if (refuse_return_result.done) { // error: number | void ~> string function test1(gen: Generator) { var ret = gen.return(0); - + (ret.value: void); } @@ -682,6 +690,7 @@ function* refuse_return() { return 0; } } + var refuse_return_gen = refuse_return(); var refuse_return_result = refuse_return_gen.return(\"string\"); @@ -727,6 +736,7 @@ function* catch_return() { return e; } } + var catch_return_value = catch_return().throw(\"\").value; if (catch_return_value !== undefined) { @@ -736,11 +746,13 @@ if (catch_return_value !== undefined) { function* yield_return() { try { yield 0; + return; } catch (e) { yield e; } } + var yield_return_value = yield_return().throw(\"\").value; if (yield_return_value !== undefined) { diff --git a/tests/generics/__snapshots__/jsfmt.spec.js.snap b/tests/generics/__snapshots__/jsfmt.spec.js.snap index b62dfa86..b9e80fcd 100644 --- a/tests/generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generics/__snapshots__/jsfmt.spec.js.snap @@ -63,8 +63,9 @@ class D { x: T; m(z: S, u: T, v): S { this.x = u; - + v.u = u; + return z; } } @@ -76,6 +77,7 @@ var n: number = o.u; class E extends C { set(x: X): X { this.x = x; + return this.get(); } } @@ -92,6 +94,7 @@ class H extends G> { var h1 = new H(); h1.foo([ \"...\" ]); + var h2: F>>> = h1; var obj: Object = {}; var fn: Function = function() { diff --git a/tests/get-def/__snapshots__/jsfmt.spec.js.snap b/tests/get-def/__snapshots__/jsfmt.spec.js.snap index 94e8a498..ee8f0b5a 100644 --- a/tests/get-def/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def/__snapshots__/jsfmt.spec.js.snap @@ -23,6 +23,7 @@ var lib = require(\"./library\"); function add(a: number, b: number): number { return a + b; } + var re = /^keynote (talk){2} (lightning){3,5} (talk){2} closing partytime!!!/; add(lib.iTakeAString(42), 7); @@ -48,11 +49,13 @@ things; import thing from \"./helpers/exports_default.js\"; thing; + import { foo, bar as baz } from \"./helpers/exports_named.js\"; foo; baz; + import * as things from \"./helpers/exports_named.js\"; things; diff --git a/tests/get-def2/__snapshots__/jsfmt.spec.js.snap b/tests/get-def2/__snapshots__/jsfmt.spec.js.snap index b64d3503..c92f86cc 100644 --- a/tests/get-def2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def2/__snapshots__/jsfmt.spec.js.snap @@ -50,17 +50,21 @@ let ParentFoo; ({ ParentFoo } = Parent); ParentFoo; + let ParentFoo2; ParentFoo2 = Parent; ParentFoo2; + let ParentFoo3 = Parent; ParentFoo3; + let foo = require(\"./Parent\").ParentFoo.foo; foo; + import type { Foo } from \"./types\"; " `; diff --git a/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap b/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap index 52ef4f0b..94def9a4 100644 --- a/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap +++ b/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap @@ -121,6 +121,7 @@ foo.goodSetterWithAnnotation = 123; foo.goodSetterNoAnnotation = \"hello\"; foo.goodSetterWithAnnotation = \"hello\"; + var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; @@ -259,9 +260,11 @@ obj.goodSetterWithAnnotation = 123; obj.goodSetterNoAnnotation = \"hello\"; obj.goodSetterWithAnnotation = \"hello\"; + var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; obj.exampleOfOrderOfGetterAndSetter = new C(); + var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; " `; diff --git a/tests/import_type/__snapshots__/jsfmt.spec.js.snap b/tests/import_type/__snapshots__/jsfmt.spec.js.snap index e68d9b3b..1563fa9a 100644 --- a/tests/import_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_type/__snapshots__/jsfmt.spec.js.snap @@ -303,23 +303,27 @@ var a1: ClassFoo1 = foo1Inst; var a2: number = foo1Inst; new ClassFoo1(); + import type { ClassFoo2 } from \"./ExportNamed_Class\"; import { foo2Inst } from \"./ExportNamed_Class\"; var b1: ClassFoo2 = foo2Inst; var b2: number = foo2Inst; new ClassFoo2(); + import type ClassFoo3T from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\"; var c1: ClassFoo3T = new ClassFoo3(); new ClassFoo3T(); + import type { ClassFoo4, ClassFoo5 } from \"./ExportCJSNamed_Class\"; import { foo4Inst, foo5Inst } from \"./ExportCJSNamed_Class\"; var d1: ClassFoo4 = foo4Inst; var d2: number = foo4Inst; new ClassFoo4(); + var d3: typeof ClassFoo5 = foo5Inst; import type { AliasFoo3 } from \"./ExportNamed_Alias\"; import { givesAFoo3Obj } from \"./ExportNamed_Alias\"; diff --git a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap index bc7e96aa..2c9cb8c7 100644 --- a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap @@ -334,12 +334,14 @@ var a1: ClassFoo1T = ClassFoo1; var a2: ClassFoo1T = new ClassFoo1(); new ClassFoo1T(); + import typeof { ClassFoo2 as ClassFoo2T } from \"./ExportNamed_Class\"; import { ClassFoo2 } from \"./ExportNamed_Class\"; var b1: ClassFoo2T = ClassFoo2; var b2: ClassFoo2T = new ClassFoo2(); new ClassFoo2T(); + import typeof ClassFoo3T from \"./ExportCJSDefault_Class\"; import ClassFoo3 from \"./ExportCJSDefault_Class\"; var c1: ClassFoo3T = ClassFoo3; diff --git a/tests/init/__snapshots__/jsfmt.spec.js.snap b/tests/init/__snapshots__/jsfmt.spec.js.snap index 93b9b4ad..ace31a70 100644 --- a/tests/init/__snapshots__/jsfmt.spec.js.snap +++ b/tests/init/__snapshots__/jsfmt.spec.js.snap @@ -60,7 +60,7 @@ function _if(b: () => boolean) { if (b()) { var f = function() {}; } - + f(); } @@ -68,7 +68,7 @@ function _while(b: () => boolean) { while (b()) { var f = function() {}; } - + f(); } @@ -76,7 +76,7 @@ function _do_while(b: () => boolean) { do { var f = function() {}; } while (b()); - + f(); } @@ -84,7 +84,7 @@ function _for(n: number) { for (var i = 0; i < n; i++) { var f = function() {}; } - + f(); } @@ -92,7 +92,7 @@ function _for_in(obj: Object) { for (var p in obj) { var f = function() {}; } - + f(); } @@ -100,7 +100,7 @@ function _for_of(arr: Array) { for (var x of arr) { var f = function() {}; } - + f(); } " @@ -432,8 +432,9 @@ function for_in_post_init() { // error function linear_deferred_init() { var x: number; - + x = 0; + var y: number = x; } @@ -459,7 +460,7 @@ function if_else_partial_init(b) { function if_pre_init(b) { var y: number = x; - + if (b) { var x: number = 0; } @@ -469,6 +470,7 @@ function if_partial_post_init(b) { if (b) { var x: number = 0; } + var y: number = x; } @@ -478,26 +480,29 @@ function if_post_init(b) { } else { var x: number = 1; } + var y: number = x; } function if_partial_post_init(b) { var x: number; - + if (b) { x = 0; } + var y: number = x; } function if_post_init(b) { var x: number; - + if (b) { x = 0; } else { x = 1; } + var y: number = x; } @@ -505,12 +510,14 @@ function switch_partial_post_init(i) { var x: number; switch (i) { case 0: - + x = 0; + break; case 1: - + x = 1; + break; } var y: number = x; @@ -520,16 +527,19 @@ function switch_post_init(i) { var x: number; switch (i) { case 0: - + x = 0; + break; case 1: - + x = 1; + break; default: - + x = 2; + } var y: number = x; } @@ -618,7 +628,7 @@ function for_scoped_init(b) { function for_pre_init(b) { var y: number = x; - + for (; b; ) { var x: number = 0; } @@ -628,6 +638,7 @@ function for_post_init(b) { for (; b; ) { var x: number = 0; } + var y: number = x; } @@ -640,7 +651,7 @@ function for_in_scoped_init() { function for_in_pre_init() { var y: number = x; - + for (var p in { a: 1, b: 2 }) { var x: number = 0; } @@ -650,6 +661,7 @@ function for_in_post_init() { for (var p in { a: 1, b: 2 }) { var x: number = 0; } + var y: number = x; } @@ -662,7 +674,7 @@ function for_of_scoped_init() { function for_in_pre_init() { var y: number = x; - + for (var x of [ 1, 2, 3 ]) { var x: number = 0; } @@ -672,6 +684,7 @@ function for_in_post_init() { for (var x of [ 1, 2, 3 ]) { var x: number = 0; } + var y: number = x; } " @@ -873,8 +886,9 @@ function sub_closure_init_reference() { // TDZ (...even though this is weird...) function linear_deferred_init() { let x: number; - + x = 0; + let y: number = x; } @@ -882,8 +896,9 @@ function linear_pre_init() { let x: number; let y: ?number = x; let z: number = x; - + x = 0; + let w: number = x; } @@ -893,21 +908,23 @@ function self_init() { function if_partial_post_init(b) { let x: number; - + if (b) { x = 0; } + var y: number = x; } function if_post_init(b) { let x: number; - + if (b) { x = 0; } else { x = 1; } + var y: number = x; } @@ -915,12 +932,14 @@ function switch_partial_post_init(i) { let x: number; switch (i) { case 0: - + x = 0; + break; case 1: - + x = 1; + break; } var y: number = x; @@ -930,16 +949,19 @@ function switch_post_init(i) { let x: number; switch (i) { case 0: - + x = 0; + break; case 1: - + x = 1; + break; default: - + x = 2; + } var y: number = x; } @@ -971,19 +993,21 @@ function do_while_post_init(b) { function for_in_post_init() { var x: number; - + for (var p in {}) { x = 0; } + var y: number = x; } function for_of_post_init() { var x: number; - + for (var x of []) { x = 0; } + var y: number = x; } @@ -991,8 +1015,9 @@ function switch_post_init2(i): number { let bar; switch (i) { case 1: - + bar = 3; + break; default: throw new Error(\"Invalid state\"); @@ -1004,8 +1029,9 @@ function switch_post_init2(i): number { let bar; switch (i) { case 1: - + bar = 3; + break; default: throw new Error(\"Invalid state\"); diff --git a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap index 60fee403..3c79fd90 100644 --- a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap @@ -110,7 +110,7 @@ function x(b) { function consumer1(b) { var g = x(b); - + if (g instanceof X2) g.foo = \"1337\"; else @@ -119,10 +119,11 @@ else function consumer2(b) { var g = x(b); - + if (g instanceof X1) g.foo = \"1337\"; } + class Y1 { bar: X1; } @@ -136,7 +137,7 @@ function y(b) { function consumer3(b) { var g = y(b); - + if (g.bar instanceof X2) g.bar.foo = \"1337\"; else @@ -145,10 +146,11 @@ else function consumer4(b) { var g = y(b); - + if (g.bar instanceof X1) g.bar.foo = \"1337\"; } + class Z1 { baz: Y1; } @@ -162,7 +164,7 @@ function z(b) { function consumer5(b) { var g = z(b); - + if (g.baz.bar instanceof X2) g.baz.bar.foo = \"1337\"; else @@ -171,10 +173,11 @@ else function consumer6(b) { var g = z(b); - + if (g.baz.bar instanceof X1) g.baz.bar.foo = \"1337\"; } + class C { m() { if (this instanceof D) @@ -187,7 +190,7 @@ class D extends C { s: string; constructor() { super(); - + this.s = \"yup\"; } } diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap index e81eb6d8..342c28d4 100644 --- a/tests/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap @@ -51,7 +51,7 @@ var i = new I(); function testInterfaceName(o: I) { (o.name: string); - + (o.constructor.name: string); } " @@ -97,6 +97,7 @@ var k: K = { x: \"\", y: \"\" }; (k.x: string); (k.y: string); + declare class C { x: number } declare class D extends C, Other {} interface A { y: Y } @@ -134,18 +135,19 @@ interface L extends J, K { y: string } function foo(l: L) { l.x; - + l.y; - + l.z; } + type M = { y: string } & J & { z: boolean }; function bar(m: M) { m.x; - + m.y; - + m.z; } " @@ -169,7 +171,7 @@ interface K extends I, J { x: string } function foo(k: K) { (k.x: number); - + (k.y: number); } " @@ -191,6 +193,7 @@ new C().bar((x: string) => { }); // error, number ~/~> string interface I { foo(x: number): void } (function foo(x: number) {}: I); + declare class C { bar(i: I): void; bar(f: (x: number) => void): void } new C().bar((x: string) => {}); diff --git a/tests/intersection/__snapshots__/jsfmt.spec.js.snap b/tests/intersection/__snapshots__/jsfmt.spec.js.snap index 4df74080..274c6711 100644 --- a/tests/intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/intersection/__snapshots__/jsfmt.spec.js.snap @@ -150,6 +150,7 @@ type FG = (_: ObjA | ObjB) => void; declare var fun1: F & G; (fun1: FG); + var fun2: FG = fun1; declare var f: ((_: number) => void) & ((_: string) => void); var g: (_: number | string) => void = f; diff --git a/tests/iter/__snapshots__/jsfmt.spec.js.snap b/tests/iter/__snapshots__/jsfmt.spec.js.snap index 577e7f23..d63ca2fc 100644 --- a/tests/iter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iter/__snapshots__/jsfmt.spec.js.snap @@ -54,16 +54,19 @@ for (var i = 0; i < 3; i++) { for (var k in a) { foo(a[k]); } + var b = (null: ?{ [key: string]: string }); for (var j in b) { foo(b[j]); } + var c; for (var m in c = b) { foo(c[m]); } + var d; for (var n in d = a) { diff --git a/tests/iterable/__snapshots__/jsfmt.spec.js.snap b/tests/iterable/__snapshots__/jsfmt.spec.js.snap index 0481cceb..0baa6595 100644 --- a/tests/iterable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iterable/__snapshots__/jsfmt.spec.js.snap @@ -89,6 +89,7 @@ function foo(strs: Iterable): void { console.log(s); } } + var m: Map = new Map(); foo(m.keys()); @@ -137,7 +138,7 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); - + if (!done) { return { done, value: \"still going...\" }; } else { @@ -154,7 +155,7 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); - + if (done) { return { done, value: \"still going...\" }; } else { diff --git a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap index ba4af193..c19c607f 100644 --- a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap @@ -31,6 +31,7 @@ var b: React.Element<{ prop1: string }> = ;
;
; + var c: React.Element<{ id: string }> =
; var d: React.Element<{ id: number }> =
; " diff --git a/tests/keys/__snapshots__/jsfmt.spec.js.snap b/tests/keys/__snapshots__/jsfmt.spec.js.snap index 7044e9f6..0d03db13 100644 --- a/tests/keys/__snapshots__/jsfmt.spec.js.snap +++ b/tests/keys/__snapshots__/jsfmt.spec.js.snap @@ -65,54 +65,57 @@ function testKeysOfOtherObj(str: string, lit: \'hi\') { // Error: number -> keys of ObjLit function testKeysOfObject(str: string, lit: \"hi\") { (str: $Keys); - + if (str) { (str: $Keys); } - + (\"hi\": $Keys); - + (123: $Keys); } + type StrDict = { [key: string]: mixed }; function testKeysOfStrDict(str: string, lit: \"hi\") { (str: $Keys); - + if (str) { (str: $Keys); } - + (\"hi\": $Keys); - + (123: $Keys); } + type StrLitDict = { [key: \"hi\"]: mixed }; function testKeysOfStrLitDict(str: string, lit: \"hi\") { (str: $Keys); - + if (str) { (str: $Keys); } - + (\"hi\": $Keys); - + (\"bye\": $Keys); - + (123: $Keys); } + type ObjLit = { hi: mixed }; function testKeysOfOtherObj(str: string, lit: \"hi\") { (str: $Keys); - + if (str) { (str: $Keys); } - + (\"hi\": $Keys); - + (123: $Keys); } " diff --git a/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap b/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap index f8059f75..30f050e0 100644 --- a/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap @@ -88,6 +88,7 @@ class C { (new C().bar: boolean); (new C().qux: boolean); + const o = { foo(): number { return 0; diff --git a/tests/lib/__snapshots__/jsfmt.spec.js.snap b/tests/lib/__snapshots__/jsfmt.spec.js.snap index 100377f7..e9b923e0 100644 --- a/tests/lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/lib/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,7 @@ var w: string = parseInt(\"...\"); var a = new Map(); a.delete(\"foobar\"); + var b = undefined; if (undefined) diff --git a/tests/literal/__snapshots__/jsfmt.spec.js.snap b/tests/literal/__snapshots__/jsfmt.spec.js.snap index ff9c8ac8..a81ba272 100644 --- a/tests/literal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/literal/__snapshots__/jsfmt.spec.js.snap @@ -56,11 +56,13 @@ function bar(x: $Keys<{ age: number }>) {} bar(APIKeys.AGE); bar(APIKeys.NAME); + var object = {}; object[APIKeys.AGE] = 123; object[APIKeys.NAME] = \"FOO\"; + var age: number = object[APIKeys.AGE]; var name: number = object[APIKeys.NAME]; var indices = { red: 0, green: 1, blue: 2 }; @@ -108,15 +110,17 @@ function test3(x: number, flip_times: number): number { for (var i = 0; i < flip_times; i++) { x = -x; } + return x; } function test4(flip_times: number): number { var x = 1; - + for (var i = 0; i < flip_times; i++) { x = -x; } + return x; } " diff --git a/tests/locals/__snapshots__/jsfmt.spec.js.snap b/tests/locals/__snapshots__/jsfmt.spec.js.snap index a8a33794..f3581136 100644 --- a/tests/locals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/locals/__snapshots__/jsfmt.spec.js.snap @@ -78,14 +78,15 @@ function switch_scope(x: mixed) { switch (x) { case \"foo\": let a; - + a = 0; - + b = 0; + } - + (a: string); - + (b: string); } @@ -94,63 +95,63 @@ function try_scope_finally() { let b; try { a = \"\"; - + b = \"\"; } finally { let a; - + a = 0; - + b = 0; } - + (a: string); - + (b: string); } function for_scope() { let a = \"\"; let b = \"\"; - + for (let a; ; ) { a = 0; - + b = 0; } - + (a: string); - + (b: string); } function for_in_scope(o: Object) { let a = 0; let b = 0; - + for (let a in o) { a = \"\"; - + b = \"\"; } - + (a: number); - + (b: number); } function for_of_scope(xs: number[]) { let a = \"\"; let b = \"\"; - + for (let a of xs) { a = 0; - + b = 0; } - + (a: string); - + (b: string); } " @@ -194,16 +195,17 @@ function sorry(really: boolean) { } else { var x: boolean = true; } - + foo(x); } function foo0(b: boolean): number { var x = 0; - + if (b) { var x = \"\"; } + return x; } " diff --git a/tests/logical/__snapshots__/jsfmt.spec.js.snap b/tests/logical/__snapshots__/jsfmt.spec.js.snap index 0631cdca..9a19d55e 100644 --- a/tests/logical/__snapshots__/jsfmt.spec.js.snap +++ b/tests/logical/__snapshots__/jsfmt.spec.js.snap @@ -920,10 +920,11 @@ function logical10c(x: number, y: string): Array { function logical11a(): number { var y = 1; - + for (var x = 0; x < 5; x++) { y = y || true; } + return y; } @@ -931,18 +932,20 @@ function logical11b(y: number): number { for (var x = 0; x < 5; x++) { y = y || true; } + return y; } function logical12a(): number { var y = 1; var z = true; - + for (var x = 0; x < 5; x++) { y = z && y; - + z = false; } + return y; } @@ -950,6 +953,7 @@ function logical12b(y: number): number { for (var x = 0; x < 5; x++) { y = y && true; } + return y; } diff --git a/tests/loners/__snapshots__/jsfmt.spec.js.snap b/tests/loners/__snapshots__/jsfmt.spec.js.snap index c7f0b0f4..3cbf1f9b 100644 --- a/tests/loners/__snapshots__/jsfmt.spec.js.snap +++ b/tests/loners/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,7 @@ var export_o: { x: number } = o; function f(u, v?): number { return u; } + var export_f: (u: number) => number = f; module.exports = export_f; diff --git a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap index 451d5d5f..1a568132 100644 --- a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap @@ -49,6 +49,7 @@ C.x; new C().foo.x; C.bar.x; + import { Foo } from \"./exports_optional_prop\"; const foo = new Foo(); diff --git a/tests/misc/__snapshots__/jsfmt.spec.js.snap b/tests/misc/__snapshots__/jsfmt.spec.js.snap index 21ed79a3..fe6dc1a0 100644 --- a/tests/misc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,7 @@ f(A.x); // A.x is now a string, by def assign /* @providesModule A */ // A.x is now a string, by def assign module.exports = {}; + var A = { x: true, ...{} }; module.exports.cls = A; @@ -91,11 +92,11 @@ var f = require(\"A\").fn; function C() { var o = new B(); - + f(o.b); - + f(o.s); - + o.fn(); } @@ -125,9 +126,11 @@ var f = require(\"A\").fn; function g(): string { return this.i; } + var o = { fn: g, ...{} }; o.i = true; + var i = o.fn(); f(i); @@ -150,6 +153,7 @@ module.exports = {obj: o}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule E */ function h(x: number) {} + var proto = { fn: h }; var o = Object.create(proto); @@ -193,6 +197,7 @@ var a = { length: \"duck\" }; a.length = 123; a.length(); + var b = [ 123 ]; b.length = \"duck\"; diff --git a/tests/modules/__snapshots__/jsfmt.spec.js.snap b/tests/modules/__snapshots__/jsfmt.spec.js.snap index 4cf8b95c..53e26311 100644 --- a/tests/modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/modules/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,7 @@ function g(x: string) {} function f(x: number): number { g(x); + return x; } diff --git a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap index 009c8722..e6fc6bd9 100644 --- a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,7 @@ function Foo() { } Foo.prototype.m = function() {}; + var o1: { x: number; m(): void } = new Foo(); var o2: Foo = new Foo(); " diff --git a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap index 605334d5..7a280679 100644 --- a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap @@ -27,11 +27,12 @@ class Bar { self: Bar; constructor(y: number) { this.y = y; - + this.self = this; } bar(z: string, u: string): string { new Qux().w = \"?\"; + return z; } } @@ -78,10 +79,12 @@ class Foo extends Qux { } foo(y: string, z): number { this.x = y; + var u = new Foo(\"...\").qux(); var v = new Bar(y); - + v.self = v; + return v.bar(z, u); } fooqux(x: string) { diff --git a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap index c54471c6..7213dac9 100644 --- a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap @@ -45,6 +45,7 @@ var foo1 = function(x: T): T { function foo2(x: T): S { return x; } + var foo3 = function(x: T): T { return foo3(x); }; @@ -52,11 +53,13 @@ var foo3 = function(x: T): T { function foo4(x: T): S { return foo4(x); } + var x = []; function foo5(): Array { return x; } + var foo6 = function(x: R): R { return foo1(x); }; @@ -67,8 +70,9 @@ function foo7(x: R): R { function foo8(x: U, y): U { var z = foo8(x, x); - + y(); + return x; } " diff --git a/tests/more_path/__snapshots__/jsfmt.spec.js.snap b/tests/more_path/__snapshots__/jsfmt.spec.js.snap index 9db808cf..91eb9e50 100644 --- a/tests/more_path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_path/__snapshots__/jsfmt.spec.js.snap @@ -67,6 +67,7 @@ function f(x: number) {} function g() { return 42 || \"hello\"; } + var x = g(); if (typeof x === \"string\") { @@ -74,11 +75,13 @@ if (typeof x === \"string\") { } f(x); + class A {} function h() { return 42 || new A(); } + var y = h(); if (y instanceof A) { @@ -88,15 +91,16 @@ if (y instanceof A) { function bar() { return true; } + class C { qux() {} } function foo() { var c = \"...\"; - + c = new C(); - + if (bar()) { c.qux(); } @@ -104,7 +108,7 @@ function foo() { function goofy() { var x = g(); - + if (typeof x == \"function\") { x(); } else @@ -113,12 +117,13 @@ function goofy() { function goofy2() { var o = { x: 0 }; - + if (typeof o.x == \"function\") { o.x(); } + var y = o.x; - + if (typeof y == \"function\") { y(); } else @@ -148,9 +153,9 @@ function check(x: string) {} function FlowSA() { var x = 0; - + x = \"...\"; - + check(x); } @@ -219,7 +224,7 @@ class C extends B { function bar(x: B) { if (x instanceof A) { x.a(); - + x.c(); } else { x++; @@ -229,18 +234,19 @@ function bar(x: B) { function foo(x: A) { if (x instanceof C) { x.a(); - + x.b(); - + x.c(); - + x.d(); } else { x.a(); - + x.c(); } } + class D { d() {} } @@ -282,6 +288,7 @@ function test(obj: BaseClass): string { if (obj instanceof ChildClass) { return obj.childProp_TYPO; } + return obj.baseProp; } " diff --git a/tests/namespace/__snapshots__/jsfmt.spec.js.snap b/tests/namespace/__snapshots__/jsfmt.spec.js.snap index fe0c0865..0342dae1 100644 --- a/tests/namespace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/namespace/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,7 @@ type Map = (x: X) => Y; function bar(x: U, f: Map): V { return f(x); } + var y: number = bar(0, x => \"\"); type Seq = number | Array; var s1: Seq = [ 0, [ 0 ] ]; diff --git a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap index 777d7f2e..c901a403 100644 --- a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap @@ -84,6 +84,7 @@ buffer[1]; buffer.copyWithin(0, 0); buffer.copyWithin(0, 0, 0); + const it1: Iterator<[number, number]> = buffer.entries(); bool = buffer.every((element: number) => false); @@ -136,6 +137,7 @@ num = buffer.indexOf(3); num = buffer.indexOf(3, 4); buffer = Buffer.from([ 98, 117, 102, 102, 101, 114 ]); + const typedArray = new Uint8Array([ 52 ]); buffer = Buffer.from( diff --git a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap index dbd4386d..18536b3e 100644 --- a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap @@ -213,7 +213,7 @@ ls.on( if (code !== 0) { console.warn(\"\`ls\` exited with code %s\", code); } - + wc.stdin.end(); } ); diff --git a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap index 62830212..339d99c3 100644 --- a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap @@ -52,43 +52,43 @@ const crypto = require(\"crypto\"); let tests = [ function() { const hmac = crypto.createHmac(\"sha256\", \"a secret\"); - + hmac.on( \"readable\", () => { (hmac.read(): ?(string | Buffer)); - + (hmac.read(): number); } ); - + hmac.write(\"some data to hash\"); - + hmac.write(123); - + hmac.end(); }, function(buf: Buffer) { const hmac = crypto.createHmac(\"sha256\", \"a secret\"); - + hmac.update(\"some data to hash\"); - + hmac.update(\"foo\", \"utf8\"); - + hmac.update(\"foo\", \"bogus\"); - + hmac.update(buf); - + hmac.update(buf, \"utf8\"); - + (hmac.update(\"some data to hash\").update(buf).digest(): Buffer); - + (hmac.digest(\"hex\"): string); - + (hmac.digest(): Buffer); - + (hmac.digest(\"hex\"): void); - + (hmac.digest(): void); } ]; diff --git a/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap index 06cb4233..62b8fcae 100644 --- a/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap @@ -43,12 +43,15 @@ let data = require(\"./package/index.json\"); (data.foo.bar: void); (data.abc: boolean); + let data2 = require(\"./package\"); (data2.baz: void); + let data3 = require(\"./package2\"); (data3.foo: void); + let data4 = require(\"./json_array\"); (data4: Array); diff --git a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap index 3c9a4c71..d288f48b 100644 --- a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap @@ -25,11 +25,13 @@ var u1 = os.userInfo(); (u1.username: string); (u1.username: Buffer); + var u2 = os.userInfo({ encoding: \"utf8\" }); (u2.username: string); (u2.username: Buffer); + var u3 = os.userInfo({ encoding: \"buffer\" }); (u3.username: string); diff --git a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap index 0ac5cef2..284c97cd 100644 --- a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap @@ -57,9 +57,11 @@ ls.stdin.end(data, \"utf-8\"); ls.stdin.end(data, () => {}); ls.stdin.end(data, \"utf-8\", () => {}); + var ws = fs.createWriteStream(\"/dev/null\"); ls.stdout.pipe(ws).end(); + class MyReadStream extends stream.Readable {} class MyWriteStream extends stream.Writable {} class MyDuplex extends stream.Duplex {} diff --git a/tests/nullable/__snapshots__/jsfmt.spec.js.snap b/tests/nullable/__snapshots__/jsfmt.spec.js.snap index 18cd15f6..65812309 100644 --- a/tests/nullable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/nullable/__snapshots__/jsfmt.spec.js.snap @@ -49,6 +49,7 @@ function bar(): ?string { function qux(x: string) {} function corge(x: number) {} + var x = bar(); if (x != null) @@ -63,9 +64,10 @@ function grault() { if (x != null) { grault(); - + qux(x); } + var array_of_nullable: Array = [ null, 3 ]; " `; diff --git a/tests/object-method/__snapshots__/jsfmt.spec.js.snap b/tests/object-method/__snapshots__/jsfmt.spec.js.snap index 509cceba..210d91ef 100644 --- a/tests/object-method/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object-method/__snapshots__/jsfmt.spec.js.snap @@ -77,6 +77,7 @@ b.f(); // error, property \`p\` not found function f() { return this.p; } + var a = { p: 0, f }; var b = { f }; @@ -118,7 +119,7 @@ function foo() { function bar(f: () => void) { f(); - + ({ f }).f(); } diff --git a/tests/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/object_api/__snapshots__/jsfmt.spec.js.snap index c4070aab..0cb34ac7 100644 --- a/tests/object_api/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_api/__snapshots__/jsfmt.spec.js.snap @@ -107,6 +107,7 @@ class C { (Object.create(new C()): C); ({ foo: \"foo\" }: C); + type O = { foo: string }; declare var o: O; @@ -133,7 +134,7 @@ class Bar extends Foo {} let tests = [ function() { const x = new Bar(); - + (Object.getPrototypeOf(x): Foo); } ]; @@ -188,6 +189,7 @@ var sealed = { one: \"one\", two: \"two\" }; (Object.keys(sealed): Array<\"one\" | \"two\">); (Object.keys(sealed): void); + var unsealed = {}; Object.keys(unsealed).forEach( @@ -195,6 +197,7 @@ Object.keys(unsealed).forEach( (k: number); } ); + var dict: { [k: number]: string } = {}; Object.keys(dict).forEach( @@ -202,15 +205,18 @@ Object.keys(dict).forEach( (k: number); } ); + var any: Object = {}; (Object.keys(any): Array); + class Foo { prop: string; foo() {} } (Object.keys(new Foo()): Array<\"error\">); + class Bar extends Foo { bar_prop: string; bar() {} @@ -476,6 +482,7 @@ function takesAString(x: string) {} function takesANumber(x: number) {} function takesAnObject(x: Object) {} + class Foo {} var a = { foo: \"bar\" }; var b = { foo: \"bar\", ...{} }; @@ -492,6 +499,7 @@ var y = new Foo(); takesAString(a.toString()); d.toString(); + var aToString: () => string = a.toString; var aToString2 = a.toString; @@ -504,11 +512,13 @@ b.toString = function(): string { c.toString = function(): number { return 123; }; + var cToString: () => number = c.toString; var xToString: number = x.toString; var xToString2: () => number = x.toString; takesAString(x.toString()); + var yToString: number = y.toString; takesAString(y.toString()); @@ -526,6 +536,7 @@ takesAString(y.toString()); (123).toString(null); takesABool(a.hasOwnProperty(\"foo\")); + var aHasOwnProperty: (prop: string) => boolean = a.hasOwnProperty; var aHasOwnProperty2 = a.hasOwnProperty; @@ -534,15 +545,18 @@ takesABool(aHasOwnProperty2(\"bar\")); b.hasOwnProperty = function() { return false; }; + var xHasOwnProperty: number = x.hasOwnProperty; var xHasOwnProperty2: (prop: string) => number = x.hasOwnProperty; takesABool(x.hasOwnProperty(\"foo\")); + var yHasOwnProperty: number = y.hasOwnProperty; takesABool(y.hasOwnProperty(\"foo\")); takesABool(a.propertyIsEnumerable(\"foo\")); + var aPropertyIsEnumerable: (prop: string) => boolean = a.propertyIsEnumerable; var aPropertyIsEnumerable2 = a.propertyIsEnumerable; @@ -551,15 +565,18 @@ takesABool(aPropertyIsEnumerable2(\"bar\")); b.propertyIsEnumerable = function() { return false; }; + var xPropertyIsEnumerable: number = x.propertyIsEnumerable; var xPropertyIsEnumerable2: (prop: string) => number = x.propertyIsEnumerable; takesABool(x.propertyIsEnumerable(\"foo\")); + var yPropertyIsEnumerable: number = y.propertyIsEnumerable; takesABool(y.propertyIsEnumerable(\"foo\")); takesAnObject(a.valueOf()); + var aValueOf: () => Object = a.valueOf; var aValueOf2 = a.valueOf; @@ -568,17 +585,21 @@ takesAnObject(aValueOf2()); b.valueOf = function() { return {}; }; + var xValueOf: number = x.valueOf; takesANumber(x.valueOf()); + var yValueOf: number = y.valueOf; takesAnObject(y.valueOf()); + var strValueOf: string = \"foo\".valueOf(); var numValueOf: number = (123).valueOf(); var boolValueOf: boolean = true.valueOf(); takesAString(a.toLocaleString()); + var aToLocaleString: () => string = a.toLocaleString; var aToLocaleString2 = a.toLocaleString; @@ -587,13 +608,16 @@ takesAString(aToLocaleString2()); b.toLocaleString = function() { return \"derp\"; }; + var xToLocaleString: number = x.toLocaleString; var xToLocaleString2: () => number = x.toLocaleString; takesAString(x.toLocaleString()); + var yToLocaleString: number = y.toLocaleString; takesAString(y.toLocaleString()); + var k: Object = a.constructor; (123).constructor; diff --git a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap index 6a8f83d1..5bf527a3 100644 --- a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,7 @@ var foo = Object.freeze({ bar: \"12345\" }); foo.bar = \"23456\"; Object.assign(foo, { bar: \"12345\" }); + var baz = { baz: 12345 }; var bliffl = Object.freeze({ bar: \"12345\", ...baz }); @@ -47,6 +48,7 @@ bliffl.constructor = baz; bliffl.toString = function() {}; baz.baz = 0; + var x: number = Object.freeze(123); var xx: { x: number } = Object.freeze({ x: \"error\" }); " diff --git a/tests/object_is/__snapshots__/jsfmt.spec.js.snap b/tests/object_is/__snapshots__/jsfmt.spec.js.snap index 35fe0eb7..21d8110f 100644 --- a/tests/object_is/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_is/__snapshots__/jsfmt.spec.js.snap @@ -37,6 +37,7 @@ Object.is(0, -0); Object.is(NaN, NaN); Object.is({}, {}); + var emptyObject = {}; var emptyArray = []; @@ -45,9 +46,11 @@ Object.is(emptyObject, emptyObject); Object.is(emptyArray, emptyArray); Object.is(emptyObject, emptyArray); + var squared = x => x * x; Object.is(squared, squared); + var a: boolean = Object.is(\"a\", \"a\"); var b: string = Object.is(\"a\", \"a\"); var c: boolean = Object.is(\"a\"); diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index 6fc68964..0c1ada48 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -37,12 +37,15 @@ var z = Object(123); // error (next line makes this not match any signatures) (Object(void 0): {}); (Object(undefined): Number); + var x = Object(null); x.foo = \"bar\"; + var y = Object(\"123\"); (y.charAt(0): string); + var z = Object(123); (z.charAt(0): string); @@ -101,6 +104,7 @@ x[123] = false; x[\"foo\" + \"bar\"] = \"derp\"; (x[\`foo\`]: string); + var y: { foo: string } = { foo: \"bar\" }; y[\"foo\"] = 123; @@ -159,17 +163,17 @@ var glob: { x: string } = { x: \"hey\" }; function assign_then_alias() { var obj: { x: string | number }; - + obj = { x: \"hey\" }; - + glob = obj; } function assign_then_widen() { var obj: { x: string | number }; - + obj = { x: \"hey\" }; - + obj.x = 10; } " diff --git a/tests/objmap/__snapshots__/jsfmt.spec.js.snap b/tests/objmap/__snapshots__/jsfmt.spec.js.snap index 9dff0d4d..706431ee 100644 --- a/tests/objmap/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objmap/__snapshots__/jsfmt.spec.js.snap @@ -33,7 +33,7 @@ var o = keyMirror({ FOO: null, BAR: null }); promiseAllByKey({ foo: Promise.resolve(0), bar: \"bar\" }).then( o => { (o.foo: string); - + (o.bar: \"bar\"); } ); diff --git a/tests/optional/__snapshots__/jsfmt.spec.js.snap b/tests/optional/__snapshots__/jsfmt.spec.js.snap index dfdbc2e2..bb7ef332 100644 --- a/tests/optional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional/__snapshots__/jsfmt.spec.js.snap @@ -28,6 +28,7 @@ class C { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function x(x: T = 0) {} + class C { x(x: T = 0) {} } @@ -170,12 +171,14 @@ function bar(x?, y?) { } bar(0); + var foo: (x?: number) => void = bar; foo(); function qux(x = \"hello\", ...y): string { foo(x); + return y[0]; } @@ -229,6 +232,7 @@ function foo(x?: string): string { if (x == null) { return \"foo\"; } + return x; } @@ -236,6 +240,7 @@ function bar(obj: { x?: string }): string { if (obj.x == null) { return \"foo\"; } + return obj.x; } @@ -243,6 +248,7 @@ function baz(bar?) { if (!bar) { return 1; } + return bar.duck; } @@ -250,6 +256,7 @@ function testOptionalNullable(x?: ?string): string { if (x == null) { return \"foo\"; } + return x; } @@ -257,6 +264,7 @@ function testOptionalNullableDefault(x?: ?string = \"hi\"): string { if (x == null) { return \"foo\"; } + return x; } @@ -264,12 +272,13 @@ function testOptionalNullableProperty(obj: { x?: ?string }): string { if (obj.x == null) { return \"foo\"; } + return obj.x; } function testOptionalNullableFlowingToNullable(x?: ?string): ?string { var f = function(y: ?string) {}; - + f(x); } " diff --git a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap index d588ecd2..2d74249a 100644 --- a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap @@ -60,11 +60,13 @@ var a: { foo?: string } = {}; a.foo = undefined; a.foo = null; + var b: { foo?: ?string } = {}; b.foo = undefined; b.foo = null; + var c: { foo?: string } = { foo: undefined }; var d: { foo?: string } = { foo: null }; var e: { foo?: ?string } = { foo: undefined }; @@ -176,11 +178,12 @@ var x: { a: number; b?: number } = { a: 0 }; x = { a: 0 }; x.b = 1; + class A { x: { a: number; b?: string }; foo() { this.x = { a: 123 }; - + this.x.b = \"hello\"; } } @@ -204,7 +207,7 @@ class A { o: O; foo() { this.o.x = { a: 123 }; - + this.o.x.b = \"hello\"; } } diff --git a/tests/overload/__snapshots__/jsfmt.spec.js.snap b/tests/overload/__snapshots__/jsfmt.spec.js.snap index 2ba0f471..ac958103 100644 --- a/tests/overload/__snapshots__/jsfmt.spec.js.snap +++ b/tests/overload/__snapshots__/jsfmt.spec.js.snap @@ -104,6 +104,7 @@ a.bar({ a: 0 }); a.bar({ a: \"hey\" }); a.bar({ a: true }); + declare var x: { a: boolean } & { b: string }; a.bar(x); @@ -119,7 +120,7 @@ exports[`test test.js 1`] = ` // matches one of the overloads of set function foo() { var output = new FakeUint8Array(); - + output.set(new FakeUint8Array(), 0); } " @@ -181,12 +182,14 @@ declare function f(x: number): void; declare var x_f: string | number; f(x_f); + declare function g(x: null): void; declare function g(x: void): void; declare function g(x: string): void; declare var x_g: ?string; g(x_g); + declare function h(x: void): void; declare function h(x: string): void; declare var x_h: { p?: string }; @@ -204,6 +207,7 @@ var x2:string = foo([\"\"])[0]; function foo(x: $Either, U>): Array { return []; } + var x1: number = foo(0)[0]; var x2: string = foo([ \"\" ])[0]; " diff --git a/tests/path/__snapshots__/jsfmt.spec.js.snap b/tests/path/__snapshots__/jsfmt.spec.js.snap index 8c46efe5..7bf50bc1 100644 --- a/tests/path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/path/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,7 @@ var z:number = x; var x = 1; while (typeof x == \"number\" || typeof x == \"string\") { x = x + 1; - + if (true) x = \"\"; } diff --git a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap index 5240481c..c41b3d2a 100644 --- a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap +++ b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ n * s.length; function foo(x) { return [ x, x > 0, \"number \" + x ]; } + var [ n, b, s ] = foo(42); n * s.length; @@ -43,6 +44,7 @@ var r: number = 0; function foo(x: X): X { r = x; + return x; } " @@ -80,6 +82,7 @@ function foo() { function bar(x: ?string): number { if (x == null) x = \"\"; + return x.length; } " @@ -107,6 +110,7 @@ function C() { C.prototype.foo = function() { return this.x; }; + var c = new C(); var x: string = c.foo(); @@ -117,10 +121,12 @@ function foo() { function bar() { return this.foo(); } + var o = { y: \"\", foo: foo, bar: bar }; var o2 = { y: 0, foo: foo, bar: bar }; o.bar(); + var y: number = o2.bar(); " `; diff --git a/tests/poly/__snapshots__/jsfmt.spec.js.snap b/tests/poly/__snapshots__/jsfmt.spec.js.snap index ba671790..0370c2ab 100644 --- a/tests/poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/poly/__snapshots__/jsfmt.spec.js.snap @@ -18,6 +18,7 @@ function bar(): A<*> { // error, * can\'t be {} and {x: string} at the same time class A {} new A(); + class B extends A {} function foo(b): A { @@ -144,6 +145,7 @@ class Foo { function bar(foo: Foo, y: S): Foo { return new Foo(y); } + var P = { bar: bar }; declare var Q: { bar(foo: Foo, y: S): Foo }; var foo = new Foo(0); diff --git a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap index 80e8e4f4..fce50811 100644 --- a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap @@ -139,6 +139,7 @@ declare var a: mixed; var b = refine(a, is_string); (b: string); + declare function refine_fst>(v: T, w: T, cb: P): $Refine; @@ -147,6 +148,7 @@ declare var d: mixed; var e = refine2(c, d, is_string_and_number); (e: string); + declare function refine2>(v: T, w: T, cb: P): $Refine; function is_string(x): boolean %checks { @@ -192,6 +194,7 @@ declare var a: Array; const b = my_filter(a, is_string); (b: Array); + declare var c: Array; const d = my_filter(c, is_string_regular); @@ -305,6 +308,7 @@ declare var a: mixed; var b = refine(a, is_string); (b: string); + declare var c: mixed; declare var d: mixed; declare var e: mixed; @@ -319,6 +323,7 @@ var e = refine3(c, d, e, is_string_and_number); function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } + var e = refine(a, is_string_regular); (e: number); diff --git a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap index ab046733..4a69f082 100644 --- a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap @@ -63,6 +63,7 @@ const o = { a: 1 }; if (m.bind(o)) { o.a; } + class D { m: Function; n() { @@ -106,7 +107,7 @@ declare var cond: boolean; function foo(x: number | string | Array): number { var f = (cond ? f1 : f2); - + if (f(x)) { return x.length; } else { @@ -189,11 +190,13 @@ var s = \"a\"; var n = r(s) || 1; (n: number); + var x = \"\"; if (x = r(s) || 1) { (x: number); } + declare var dollars: mixed; function foo(x: mixed) { @@ -242,9 +245,10 @@ function f(_this: { m: ?Meeting }): string { if (!_this.m) { return \"0\"; } - + if (_this.m.es.some(a => a.fbid === 0)) {} + return \"3\"; } " @@ -302,6 +306,7 @@ function foo(s: Array): string { if (pred(s)) { return \"1\"; } + return 1; } " @@ -337,10 +342,11 @@ function foo(s: Array): string { if (1(s)) { return \"1\"; } - + if ((pred + 1)(\"s\")) { return \"1\"; } + return \"1\"; } " @@ -431,6 +437,7 @@ function foo(x: string | Array): string { if (pred(x)) { return x; } + return \"1\"; } " diff --git a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap index 3f931d10..780e4e56 100644 --- a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,7 @@ function bak(z: string | number): number { function check(y): %checks(typeof y === \"string\") { return typeof y === \"number\"; } + declare var y: number | boolean; if (check(y)) { @@ -119,7 +120,7 @@ function dotAccess(head, create) { const stack = path.split(\".\"); do { const key = stack.shift(); - + head = head[key] || create && (head[key] = {}); } while (stack.length && head); return head; @@ -310,6 +311,7 @@ function foo(a, b) { function two_strings(x, y): %checks { return is_string(x) && is_string(y); } + declare function from_two_strings(x: string, y: string): void; " `; diff --git a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap index 831689cf..1b518ad8 100644 --- a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap @@ -54,6 +54,7 @@ var a2 = (x: mixed): %checks (x !== null) => x !== null; function f5(x: mixed): %checks(x !== null) { return x !== null; } + var a2 = (x: mixed): %checks(x !== null) => x !== null; " `; @@ -95,10 +96,12 @@ declare function f4(x: mixed): boolean %checks(x !== null); function f7(x: mixed): %checks { return x !== null; } + var a0 = (x: mixed) => x !== null; var a1 = (x: mixed): %checks => x !== null; (x): %checks => x !== null; + const insert_a_really_big_predicated_arrow_function_name_here = (x): %checks => x !== null; declare var x; @@ -106,6 +109,7 @@ declare var x; x; checks => 123; + type checks = any; declare function f(x: mixed): checks; diff --git a/tests/private/__snapshots__/jsfmt.spec.js.snap b/tests/private/__snapshots__/jsfmt.spec.js.snap index c3709fef..805c600d 100644 --- a/tests/private/__snapshots__/jsfmt.spec.js.snap +++ b/tests/private/__snapshots__/jsfmt.spec.js.snap @@ -20,9 +20,9 @@ class A { __x: number; constructor() { this.x = 0; - + this._x = \"\"; - + this.__x = 0; } } diff --git a/tests/promises/__snapshots__/jsfmt.spec.js.snap b/tests/promises/__snapshots__/jsfmt.spec.js.snap index ce71426a..e49f966b 100644 --- a/tests/promises/__snapshots__/jsfmt.spec.js.snap +++ b/tests/promises/__snapshots__/jsfmt.spec.js.snap @@ -59,13 +59,13 @@ declare var pnum: Promise; Promise.all([ pstr, pnum, true ]).then( xs => { let [ a, b, c ] = xs; - + (a: number); - + (b: boolean); - + (c: string); - + xs.forEach( x => { (x: void); @@ -501,6 +501,7 @@ new Promise( } else { var b: number = numOrStr; } + var c: string = numOrStr; } ); @@ -548,6 +549,7 @@ new Promise( } else { var b: number = numOrStr; } + var c: string = numOrStr; } ); @@ -744,7 +746,7 @@ async function foo(x: boolean) { async function run() { console.log(await foo(true)); - + console.log(await foo(false)); } diff --git a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap index 20a31780..3eaf4daa 100644 --- a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap @@ -32,6 +32,7 @@ function F(props: { foo: string }) {} function G(props: { foo: string | numner }) {} ; + var Z = 0; ; diff --git a/tests/rec/__snapshots__/jsfmt.spec.js.snap b/tests/rec/__snapshots__/jsfmt.spec.js.snap index c9cc68ed..9cd0adff 100644 --- a/tests/rec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/rec/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,7 @@ function bar1(y: F): F { function bar2(y: F): F { return y; } + type Functor = { map(f: (val: A) => B): Functor }; function identity(val: A): Functor { @@ -104,6 +105,7 @@ type Pstar = X | Pstar>; var p: P = new P(); (p.x: string); + var pstar: Pstar = 0; (pstar: number); @@ -167,6 +169,7 @@ var a = []; function bar() { a = a.concat([]); } + class A { x: A>; } @@ -175,12 +178,14 @@ var a_ = new A(); function foo0() { a_ = a_.x; } + type T = { y: S }; type S = T>; function foo1(b: S<*>) { b = b.y; } + class D {} class B extends D {} class C extends B {} @@ -218,6 +223,7 @@ type J = () => J>; function foo(x: I): J { return x; } + type Q = { x: X }; type P = () => Q>; diff --git a/tests/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/__snapshots__/jsfmt.spec.js.snap index 45011f7d..1011c49c 100644 --- a/tests/recheck/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/__snapshots__/jsfmt.spec.js.snap @@ -87,6 +87,7 @@ function foo() { function bar() { return E; } + let X = foo(); class F extends X {} class D extends F {} diff --git a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap index 9fe20896..68f13041 100644 --- a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,7 @@ function foo() { function bar() { return E; } + let X = bar(); class F extends X {} class D extends F {} diff --git a/tests/record/__snapshots__/jsfmt.spec.js.snap b/tests/record/__snapshots__/jsfmt.spec.js.snap index 0661c99a..7d6d557a 100644 --- a/tests/record/__snapshots__/jsfmt.spec.js.snap +++ b/tests/record/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,7 @@ o1.foo; o1.qux; o1.toString(); + type R = { foo: any; bar: any }; type Key2 = $Keys; var o2: { [key: Key2]: number } = { foo: 0 }; @@ -50,6 +51,7 @@ var o2: { [key: Key2]: number } = { foo: 0 }; o2.bar; o2.qux; + class C { x: $Subtype<{ [key: $Keys]: any }>; } diff --git a/tests/refi/__snapshots__/jsfmt.spec.js.snap b/tests/refi/__snapshots__/jsfmt.spec.js.snap index aa9bb5ce..a5faabef 100644 --- a/tests/refi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refi/__snapshots__/jsfmt.spec.js.snap @@ -104,6 +104,7 @@ else { function() { if (x == null) return; + var y: string = x; }, function() { @@ -116,6 +117,7 @@ else { function() { if (x != null) {} + var y: string = x; }, function() { @@ -415,14 +417,14 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) { var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p == null) {} else { @@ -431,14 +433,15 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p == null) return; + var y: string = x.p; }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (!(x.p != null)) {} else { @@ -447,30 +450,33 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) { alert(\"\"); + var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) { x.p = null; + var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) {} + var y: string = x.p; }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) {} else { @@ -487,7 +493,7 @@ else { }, function() { var x: { p: string | string[] } = { p: [ \"xxx\" ] }; - + if (Array.isArray(x.p)) { var y: string[] = x.p; } else { @@ -496,170 +502,170 @@ else { }, function() { var x: { y: ?string } = { y: null }; - + if (!x.y) { x.y = \"foo\"; } - + (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - + if (x.y) {} else { x.y = \"foo\"; } - + (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - + if (!x.y) { x.y = 123; } - + (x.y: string); }, function() { var x: { y: ?string } = { y: null }; - + if (x.y) { x.y = \"foo\"; } else { x.y = \"bar\"; } - + (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - + if (typeof x.y == \"number\") { x.y = \"foo\"; } - + (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - + if (typeof x.y == \"number\") { x.y = \"foo\"; } else if (typeof x.y == \"boolean\") { x.y = \"bar\"; } - + (x.y: boolean); }, function() { var x: { y: ?string } = { y: null }; - + if (!x.y) { x.y = \"foo\"; } - + if (x.y) { x.y = null; } - + (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - + if (typeof x.y == \"number\") { x.y = \"foo\"; } - + if (typeof x.y == \"string\") { x.y = false; } - + (x.y: string); }, function() { var x: { y: string | number | boolean } = { y: false }; - + if (typeof x.y == \"number\") { x.y = \"foo\"; } - + if (typeof x.y == \"string\") { x.y = 123; } - + (x.y: string); }, function() { var x: { y: ?string } = { y: null }; var z: string = \"foo\"; - + if (x.y) { x.y = z; } else { x.y = z; } - + (x.y: string); }, function(x: string) { if (x === \"a\") {} - + (x: \"b\"); }, function(x: mixed) { if (typeof x.bar === \"string\") {} - + (x: string & number); }, function() { let x: { foo: ?string } = { foo: null }; - + if (!x.foo) { if (false) {} - + x.foo = \"foo\"; } - + (x.foo: string); }, function() { let x: { foo: ?string } = { foo: null }; - + if (!x.foo) { while (false) {} - + x.foo = \"foo\"; } - + (x.foo: string); }, function() { let x: { foo: ?string } = { foo: null }; - + if (!x.foo) { for (var i = 0; i < 0; i++) {} - + x.foo = \"foo\"; } - + (x.foo: string); }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) { var { p } = x; - + (p: string); } } @@ -718,10 +724,10 @@ function try_scope_catch(x: string | number) { function block_scope(x: string | number) { { let x; - + x = \"\"; } - + (x: string); } @@ -729,22 +735,23 @@ function switch_scope(x: string | number) { switch (x) { default: let x; - + x = \"\"; + } - + (x: string); } function try_scope(x: string | number) { try { let x; - + x = \"\"; } catch (e) { x = \"\"; } - + (x: string); } @@ -753,10 +760,10 @@ function try_scope_catch(x: string | number) { x = \"\"; } catch (e) { let x; - + x = \"\"; } - + (x: string); } " @@ -867,14 +874,14 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - + if (x != null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (x == null) {} else { @@ -883,14 +890,15 @@ else { }, function() { var x: ?string = \"xxx\"; - + if (x == null) return; + var y: string = x; }, function() { var x: ?string = \"xxx\"; - + if (!(x != null)) {} else { @@ -899,22 +907,24 @@ else { }, function() { var x: ?string = \"xxx\"; - + if (x != null) { alert(\"\"); + var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (x != null) {} + var y: string = x; }, function() { var x: ?string = \"xxx\"; - + if (x != null) {} else { @@ -931,7 +941,7 @@ else { }, function() { var x: string | string[] = [ \"xxx\" ]; - + if (Array.isArray(x)) { var y: string[] = x; } else { @@ -940,10 +950,11 @@ else { }, function() { var x: ?string = null; - + if (!x) { x = \"xxx\"; } + var y: string = x; } ]; @@ -1129,35 +1140,35 @@ class D extends C { var null_tests = [ function() { var x: ?string = \"xxx\"; - + if (x != null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (null != x) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p != null) { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q != null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (x == null) {} else { @@ -1166,7 +1177,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p == null) {} else { @@ -1175,7 +1186,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q == null) {} else { @@ -1184,28 +1195,28 @@ else { }, function() { var x: ?string = \"xxx\"; - + if (x !== null) { var y: string | void = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p !== null) { var y: string | void = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q !== null) { var y: string | void = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (x === null) {} else { @@ -1214,7 +1225,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p === null) {} else { @@ -1223,7 +1234,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q === null) {} else { @@ -1242,6 +1253,7 @@ else ensure1(): string { if (this.p == null) return \"\"; + return this.p; } ensure2(): string | void { @@ -1253,6 +1265,7 @@ else ensure3(): string | void { if (this.p === null) return \"\"; + return this.p; } } @@ -1272,8 +1285,10 @@ else ensure103(): string { if (super.p != null) { alert(\"\"); + return super.p; } + return \"\"; } } @@ -1379,8 +1394,9 @@ function exhaustion1(x): number { switch (x) { case 0: case 1: - + foo = 3; + break; default: throw new Error(\"Invalid state\"); @@ -1392,13 +1408,15 @@ function exhaustion2(x, y): number { var foo; switch (x) { case 0: - + if (y) { break; } + case 1: - + foo = 3; + break; default: throw new Error(\"Invalid state\"); @@ -1411,8 +1429,9 @@ function exhaustion3(x): number { switch (x) { case 0: case 1: - + foo = 3; + break; default: throw new Error(\"Invalid state\"); @@ -1575,35 +1594,35 @@ class A { var null_tests = [ function() { var x: ?string = \"xxx\"; - + if (typeof x == \"string\") { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (\"string\" == typeof x) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (typeof x.p == \"string\") { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (typeof x.p.q == \"string\") { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (typeof x != \"string\") {} else { @@ -1612,7 +1631,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (typeof x.p != \"string\") {} else { @@ -1621,7 +1640,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (typeof x.p.q != \"string\") {} else { @@ -1630,28 +1649,28 @@ else { }, function() { var x: ?string = \"xxx\"; - + if (typeof x === \"string\") { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (typeof x.p === \"string\") { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (typeof x.p.q === \"string\") { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (typeof x !== \"string\") {} else { @@ -1660,7 +1679,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (typeof x.p !== \"string\") {} else { @@ -1669,7 +1688,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (typeof x.p.q !== \"string\") {} else { @@ -1797,35 +1816,35 @@ class A { var undef_tests = [ function() { var x: ?string = \"xxx\"; - + if (x !== undefined && x !== null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (undefined !== x && x !== null) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p !== undefined && x.p !== null) { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q !== undefined && x.p.q !== null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (x === undefined || x === null) {} else { @@ -1834,7 +1853,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p === undefined || x.p === null) {} else { @@ -1843,7 +1862,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q === undefined || x.p.q === null) {} else { @@ -1959,35 +1978,35 @@ class A { var void_tests = [ function() { var x: ?string = \"xxx\"; - + if (x !== void 0 && x !== null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - + if (void 0 !== x && x !== null) { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p !== void 0 && x.p !== null) { var y: string | void = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q !== void 0 && x.p.q !== null) { var y: string = x.p.q; } }, function() { var x: ?string = \"xxx\"; - + if (x === void 0 || x === null) {} else { @@ -1996,7 +2015,7 @@ else { }, function() { var x: { p: ?string } = { p: \"xxx\" }; - + if (x.p === void 0 || x.p === null) {} else { @@ -2005,7 +2024,7 @@ else { }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - + if (x.p.q === void 0 || x.p.q === null) {} else { diff --git a/tests/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/refinements/__snapshots__/jsfmt.spec.js.snap index ac4d4eb4..707baae4 100644 --- a/tests/refinements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refinements/__snapshots__/jsfmt.spec.js.snap @@ -37,11 +37,12 @@ function bar2(x : Bar) { // x.parent might be null function foo(x: ?number) { var y; - + if (y = x) { var z = y * 1000; } } + type Bar = { parent: ?Bar; doStuff(): void }; function bar0(x: Bar) { @@ -141,11 +142,11 @@ function foo(x: ?boolean) { if (x === false) { return; } - + if (x === true) { return; } - + x[0]; } @@ -161,22 +162,25 @@ function baz(x: ?boolean) { if (100 * false) { return; } - + if (false * 100) { return; } } + let tests = [ function(x: { done: true; result: string } | { done: false }) { if (x.done === true) { return x.result; } + return x.result; }, function(x: { done: true; result: string } | { done: false }) { if (true === x.done) { return x.result; } + return x.result; } ]; @@ -298,24 +302,28 @@ type BadType = {}; function getTypeASTName(typeAST: Type): string { if (!typeAST.type) throw new Error(\"Must be wrapping type\"); + return getTypeASTName(typeAST.type); } + let tests = [ function(x: { done: true; result: string } | { done: false }) { if (x.done) { return x.result; } + return x.result; }, function(x: { done: true; result: string } | { foo: string }) { if (x.done) { return x.result; } + return x.result; }, function() { type T = { foo: Object; bar: string } | { baz: string; quux: string }; - + function testAlwaysTruthyProp(t: T) { if (t.foo) { (t.bar: string); @@ -323,7 +331,7 @@ let tests = [ (t.quux: string); } } - + function testSometimesTruthyProp(t: T) { if (t.bar) { (t.foo: Object); @@ -384,14 +392,14 @@ let tests = [ function(x: string, y: number) { if (x == y) {} - + if (x === y) {} }, function(x: string) { if (x == undefined) {} - + if (x == void 0) {} }, @@ -402,7 +410,7 @@ let tests = [ function(x: { y: \"foo\" } | { y: \"bar\" }) { if (x.y == 123) {} - + if (x.y === 123) {} } @@ -504,11 +512,11 @@ function bar(x:Object) { // also treated as \`any\`, so allowed function foo(x: { y?: () => void }) { x.y(); - + if (x.hasOwnProperty(\"y\")) { x.y(); } - + if (x.hasOwnProperty(\"z\")) { x.z(); } @@ -516,11 +524,11 @@ function foo(x: { y?: () => void }) { function bar(x: Object) { x.y(); - + if (x.hasOwnProperty(\"y\")) { x.y(); } - + if (x.hasOwnProperty(\"z\")) { x.z(); } @@ -655,36 +663,42 @@ function f() {} function def_assign_function_havoc(obj: Obj) { obj.p = 10; - + f(); + var x: number = obj.p; } function def_assign_setprop_havoc(obj: Obj, obj2: Obj) { obj.p = 10; - + obj2.p = \"hey\"; + var x: number = obj.p; } function def_assign_index_havoc(obj: Obj, obj2: Obj) { obj.p = 10; - + obj2[\"p\"] = \"hey\"; + var x: number = obj.p; } function def_assign_within_if(b: boolean, obj: Obj) { if (b) { obj.p = 10; + var x: number = obj.p; } + var y: number = obj.p; } function def_assign_within_while(b: boolean, obj: Obj) { while (b) { obj.p = 10; + var x: number = obj.p; } var y: number = obj.p; @@ -693,6 +707,7 @@ function def_assign_within_while(b: boolean, obj: Obj) { function def_assign_within_do(b: boolean, obj: Obj) { do { obj.p = 10; + var x: number = obj.p; } while (b); var y: number = obj.p; @@ -700,17 +715,18 @@ function def_assign_within_do(b: boolean, obj: Obj) { function def_assign_within_try(b: boolean, obj: Obj) { obj.p = 10; + try { f(); - + obj.p = \"hey\"; } catch (e) { f(); - + obj.p = \"hey\"; } finally { var y: number = obj.p; - + obj.p = 42; } var z: string = obj.p; @@ -719,16 +735,20 @@ function def_assign_within_try(b: boolean, obj: Obj) { function def_assign_within_for(b: boolean, obj: Obj) { for (; b; ) { obj.p = 10; + var x: number = obj.p; } + var z: number = obj.p; } + type Obj2 = { q: number | string }; function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) { obj.p = 10; - + obj2.q = \"hey\"; + var x: number = obj.p; } " @@ -836,13 +856,13 @@ function foo4(o: $Exact<{ x: number }>) { function foo5() { const o = {}; - + _foo5(); - + if (o.p) { o.p(); } - + function _foo5() { o.p = function() {}; } @@ -856,13 +876,13 @@ function foo6(o: mixed) { function foo7(o: mixed) { if (typeof o.bar === \"string\") {} - + if (o && typeof o.bar === \"string\") {} - + if (o != null && typeof o.bar === \"string\") {} - + if (o !== null && o !== undefined && typeof o.bar === \"string\") {} } @@ -870,7 +890,7 @@ function foo7(o: mixed) { function foo8(o: { p: mixed }) { if (o.p && o.p.q) {} - + if (o.p && o.p.q && o.p.q.r) {} } @@ -1030,14 +1050,14 @@ function takesString(x: string) {} function num(x: mixed) { if (typeof x === \"number\") { takesString(x); - + (!x: false); } - + if (typeof x === \"number\" && x) { (!x: false); } - + if (x && typeof x === \"number\") { (!x: false); } @@ -1046,14 +1066,14 @@ function num(x: mixed) { function str(x: mixed) { if (typeof x === \"string\") { takesNumber(x); - + (!x: false); } - + if (typeof x === \"string\" && x) { (!x: false); } - + if (x && typeof x === \"string\") { (!x: false); } @@ -1062,14 +1082,14 @@ function str(x: mixed) { function bool(x: mixed) { if (typeof x === \"boolean\") { takesString(x); - + (x: true); } - + if (typeof x === \"boolean\" && x) { (x: true); } - + if (x && typeof x === \"boolean\") { (x: true); } @@ -1126,7 +1146,7 @@ function false_(x: mixed) { function obj2(x: mixed) { if (typeof x === \"object\") { (x: { [key: string]: mixed } | null); - + if (x !== null) { (x[\"foo\"]: string); } @@ -1137,15 +1157,15 @@ function obj2(x: mixed) { if (typeof x === \"object\" && x) { (x: Object); } - + if (x && typeof x === \"object\") { (x: Object); } - + if (x != null && typeof x === \"object\") { (x: Object); } - + if (x !== null && typeof x === \"object\") { (x: Object); } @@ -1246,11 +1266,12 @@ function baz(x: ?number) { if (x === null || x === undefined) { return; } - + if (!x) { x[0]; } } + class TestClass {} let tests = [ function() { @@ -1298,7 +1319,7 @@ function null_bogus_comparison() { if (100 * null) { return; } - + if (null * 100) { return; } @@ -1449,51 +1470,54 @@ let tests = [ if (x === 0) { (x: void); } - + (x: 0); }, function(x: number) { if (x !== 0) { (x: 0); } - + (x: void); }, function(x: 1): 0 { if (x === 0) { return x; } + return 0; }, function(x: 0): number { if (x === 1) { return x; } + return x; }, function(x: 0) { if (x !== 1) { (x: 0); } - + (x: 0); }, function(x: 0): number { if (x === 0) { return x; } + return x; }, function(x: 0 | 1) { if (x === 0) { (x: 0); - + (x: void); } - + if (x === 1) { (x: 1); - + (x: void); } }, @@ -1501,6 +1525,7 @@ let tests = [ if (x.foo === 0) { return x.foo; } + return x.foo; }, function(x: { kind: 0; foo: number } | { kind: 1; bar: number }): number { @@ -1522,6 +1547,7 @@ let tests = [ if (n !== 0 && n !== 1 && n !== 2) { throw new Error(\"Wrong number passed\"); } + return n; }, function(s: number): ?Mode { @@ -1535,13 +1561,15 @@ let tests = [ function(mode: Mode) { switch (mode) { case 0: - + (mode: 0); + break; case 1: case 2: - + (mode: 1 | 2); + break; } }, @@ -1648,6 +1676,7 @@ function a(x: { [key: string]: ?string }, y: string): string { if (x[y]) { return x[y]; } + return \"\"; } @@ -1655,6 +1684,7 @@ function b(x: { y: { [key: string]: ?string } }, z: string): string { if (x.y[z]) { return x.y[z]; } + return \"\"; } @@ -1662,6 +1692,7 @@ function c(x: { [key: string]: ?string }, y: { z: string }): string { if (x[y.z]) { return x[y.z]; } + return \"\"; } @@ -1669,6 +1700,7 @@ function d(x: { y: { [key: string]: ?string } }, a: { b: string }): string { if (x.y[a.b]) { return x.y[a.b]; } + return \"\"; } @@ -1676,6 +1708,7 @@ function a_array(x: Array, y: number): string { if (x[y]) { return x[y]; } + return \"\"; } @@ -1683,6 +1716,7 @@ function b_array(x: { y: Array }, z: number): string { if (x.y[z]) { return x.y[z]; } + return \"\"; } @@ -1690,6 +1724,7 @@ function c_array(x: Array, y: { z: number }): string { if (x[y.z]) { return x[y.z]; } + return \"\"; } @@ -1697,6 +1732,7 @@ function d_array(x: { y: Array }, a: { b: number }): string { if (x.y[a.b]) { return x.y[a.b]; } + return \"\"; } @@ -1704,14 +1740,17 @@ function e_array(x: Array): string { if (x[0]) { return x[0]; } + return \"\"; } function c2(x: { [key: string]: ?string }, y: { z: string }): string { if (x[y.z]) { y.z = \"HEY\"; + return x[y.z]; } + return \"\"; } @@ -1720,8 +1759,10 @@ function c3( ): string { if (x[y.z]) { y.a = \"HEY\"; + return x[y.z]; } + return \"\"; } " @@ -1825,7 +1866,7 @@ function foo(b) { var x = (b ? 0 : null); while (typeof x == \"string\" || typeof x == \"number\") { var y: string = x; - + x = false; } var z: string = x; @@ -1835,7 +1876,7 @@ function bar(b) { var x = (b ? 0 : null); do { var y: string = x; - + x = false; } while (x === null); var z: string = x; @@ -1847,15 +1888,15 @@ function qux() { var x = 0; try { maybe_throw(); - + x = \"hello\"; } catch (e) { maybe_throw(); - + x = \"hello\"; } finally { var y: number = x; - + x = 42; } var z: string = x; @@ -1869,16 +1910,18 @@ function corge(b) { ) { var y: string = x; } + var z: string = x; } function waldo() { var o = {}; var x = false; - + for (x in o) { x = 0; } + var z: number = x; } @@ -2054,51 +2097,54 @@ let tests = [ if (x === \"foo\") { (x: void); } - + (x: \"foo\"); }, function(x: string) { if (x !== \"foo\") { (x: \"foo\"); } - + (x: void); }, function(x: \"bar\"): \"foo\" { if (x === \"foo\") { return x; } + return \"foo\"; }, function(x: \"foo\"): string { if (x === \"bar\") { return x; } + return x; }, function(x: \"foo\") { if (x !== \"bar\") { (x: \"foo\"); } - + (x: \"foo\"); }, function(x: \"foo\"): string { if (x === \"foo\") { return x; } + return x; }, function(x: \"foo\" | \"bar\") { if (x === \"foo\") { (x: \"foo\"); - + (x: void); } - + if (x === \"bar\") { (x: \"bar\"); - + (x: void); } }, @@ -2106,6 +2152,7 @@ let tests = [ if (x.foo === \"foo\") { return x.foo; } + return x.foo; }, function( @@ -2127,10 +2174,11 @@ let tests = [ }, function(str: string): Mode { var ch = str[0]; - + if (ch !== \"a\" && ch !== \"b\" && ch !== \"c\") { throw new Error(\"Wrong string passed\"); } + return ch; }, function(s: string): ?Mode { @@ -2144,13 +2192,15 @@ let tests = [ function(mode: Mode) { switch (mode) { case \"a\": - + (mode: \"a\"); + break; case \"b\": case \"c\": - + (mode: \"b\" | \"c\"); + break; } }, @@ -2165,10 +2215,11 @@ let tests = [ if (x === \`foo\`) { return x; } - + if (\`foo\` === x) { return x; } + return \"foo\"; } ]; @@ -2218,6 +2269,7 @@ class B { if (super.prop) { return super.prop; } + return \"B\"; } } @@ -2226,6 +2278,7 @@ class C extends A { if (super.prop) { return super.prop; } + return \"C\"; } } @@ -2668,6 +2721,7 @@ function getTypeASTName(typeAST: Type): string { return typeAST.name; } } + import type { ASTNode } from \"./ast_node\"; var Node = require(\"./node1\"); @@ -2675,8 +2729,10 @@ function foo(x: ASTNode) { if (x.kind === Node) { return x.prop1.charAt(0); } + return null; } + type Apple = { kind: \"Fruit\"; taste: \"Bad\" }; type Orange = { kind: \"Fruit\"; taste: \"Good\" }; type Broccoli = { kind: \"Veg\"; taste: \"Bad\"; raw: \"No\" }; @@ -2699,6 +2755,7 @@ function qux(x: Breakfast) { function list(n) { if (n > 0) return { kind: \"cons\", next: list(n - 1) }; + return { kind: \"nil\" }; } @@ -2714,8 +2771,10 @@ function length(l) { function check(n) { if (n >= 0) return n === length(list(n)); + return true; } + var EnumKind = { A: 1, B: 2, C: 3 }; type A = { kind: 1; A: number }; type B = { kind: 2; B: number }; @@ -2733,6 +2792,7 @@ function kind(x: A | B | C): number { } kind({ kind: EnumKind.A, A: 1 }); + type Citizen = { citizen: true }; type NonCitizen = { citizen: false; nationality: string }; @@ -2742,6 +2802,7 @@ function nationality(x: Citizen | NonCitizen) { else return x.nationality; } + let tests = [ function test7(x: A) { if (x.kindTypo === 1) { @@ -2751,14 +2812,14 @@ let tests = [ function test8(x: { foo: { bar: 1 } }) { if (x.foo.bar === 1) {} - + if (x.fooTypo.bar === 1) {} }, function(x: A) { if (x.kind === null.toString()) {} - + if ({ kind: 1 }.kind === null.toString()) {} }, @@ -2773,54 +2834,54 @@ let tests = [ ) { if (x.length === 0) {} - + if (x.legnth === 0) { (x.legnth: number); - + (x.legnth: string); } - + if (y.length === 0) {} - + if (y.legnth === 0) { (y.legnth: number); - + (y.legnth: string); } - + if (z.toString === 0) {} - + if (z.toStirng === 0) { (z.toStirng: number); - + (z.toStirng: string); } - + if (q.valueOf === 0) {} - + if (q.valeuOf === 0) { (q.valeuOf: number); - + (q.valeuOf: string); } - + if (r.toStirng === 0) { (r.toStirng: empty); } - + if (s.call === 0) {} - + if (s.calll === 0) { (t.calll: empty); } - + if (t.call === 0) {} - + if (t.calll === 0) { (t.calll: empty); } @@ -2829,23 +2890,23 @@ let tests = [ if (x.str === \"str\") { (x.str: \"not str\"); } - + if (x.num === 123) { (x.num: 456); } - + if (x.bool === true) { (x.bool: false); } - + if (x.badStr === \"bad\") { (x.badStr: empty); } - + if (x.badNum === 123) { (x.badNum: empty); } - + if (x.badBool === true) { (x.badBool: empty); } @@ -2853,63 +2914,63 @@ let tests = [ function(x: { foo: 123; y: string } | { foo: \"foo\"; z: string }) { if (x.foo === 123) { (x.y: string); - + x.z; } else { (x.z: string); - + x.y; } - + if (x.foo === \"foo\") { (x.z: string); - + x.y; } else { (x.y: string); - + x.z; } }, function(x: { foo: number; y: string } | { foo: \"foo\"; z: string }) { if (x.foo === 123) { (x.y: string); - + x.z; } else { x.y; - + x.z; } - + if (x.foo === \"foo\") { (x.z: string); - + x.y; } else { (x.y: string); - + x.z; } }, function(x: { foo: number; y: string } | { foo: string; z: string }) { if (x.foo === 123) { (x.y: string); - + x.z; } else { x.y; - + x.z; } - + if (x.foo === \"foo\") { (x.z: string); - + x.y; } else { x.y; - + x.z; } }, @@ -2918,7 +2979,7 @@ let tests = [ ) { if (x.foo === num) { x.y; - + x.z; } } @@ -2959,12 +3020,14 @@ type Error = { type: typeof ERROR; error: string }; function handleStatus(status: Success | Error) { switch (status.type) { case SUCCESS: - + console.log(\`Successful: \${status.message}\`); + break; default: - + console.log(\`Errored: \${status.error}\`); + } } " @@ -3056,10 +3119,11 @@ function foo(x: boolean | number) { function bar(): number { var x = null; - + if (typeof x === \"object\") { return x; } + return 0; } @@ -3067,16 +3131,16 @@ function fn0() { if (typeof BAZ !== \"undefined\" && typeof BAZ.stuff === \"function\") { BAZ.stuff(123); } - + BAZ.stuff(123); } function fn1() { BAZ.stuff; - + if (typeof BAZ !== \"undefined\" && typeof BAZ.stuff === \"function\") { BAZ.stuff(123); - + BAZ.stuff(123); } } @@ -3085,6 +3149,7 @@ function anyfun(x: number | Function): number { if (typeof x === \"function\") { return 0; } + return x; } @@ -3092,6 +3157,7 @@ function anyobj(x: number | Object): number { if (typeof x === \"object\") { return 0; } + return x; } @@ -3261,7 +3327,7 @@ function undef_unreachable(x: number) { if (x === undefined) { var y = x * 1000; } - + if (x == undefined) { var z = x * 1000; } @@ -3271,7 +3337,7 @@ function undef_var_nonstrict(x: ?number, y: ?number) { if (x != undefined) { var a = x * 1000; } - + if (y == undefined) { var b = y * 1000; } @@ -3281,7 +3347,7 @@ function undef_bogus_comparison() { if (100 * undefined) { return; } - + if (undefined * 100) { return; } @@ -3524,7 +3590,7 @@ function void_bogus_comparison() { if (100 * void 0) { return; } - + if (void 0 * 100) { return; } @@ -3532,7 +3598,7 @@ function void_bogus_comparison() { function void_redefined_undefined(x: ?number) { var undefined = \"foo\"; - + if (x !== null && x !== void 0) { var y = x * 1000; } diff --git a/tests/require/__snapshots__/jsfmt.spec.js.snap b/tests/require/__snapshots__/jsfmt.spec.js.snap index 38d00b5d..fbda0f7f 100644 --- a/tests/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/require/__snapshots__/jsfmt.spec.js.snap @@ -146,11 +146,13 @@ require.call(null, \"DoesNotExist\"); function takesANumber(num: number): void {} function takesAString(str: string): void {} + var A = require(\"A\"); takesANumber(A.numberValue); takesAString(A.numberValue); + var B = require(\"./B\"); takesANumber(B.numberValue); @@ -160,10 +162,12 @@ takesAString(B.numberValue); require(\"C\"); require(\"./D\"); + var E = require(\"./E\"); var e_1: number = E.numberValue; E.stringValue; + var a = \"./E\"; require(a); diff --git a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap index e1641827..359534ba 100644 --- a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap @@ -83,6 +83,7 @@ requireLazy( var str4: string = B.numberValueB; } ); + var notA: Object = A; var notB: Object = B; diff --git a/tests/return/__snapshots__/jsfmt.spec.js.snap b/tests/return/__snapshots__/jsfmt.spec.js.snap index b0305283..aad213d6 100644 --- a/tests/return/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return/__snapshots__/jsfmt.spec.js.snap @@ -64,6 +64,7 @@ function h(x): number { if (x > 1) { return 42; } + return; } @@ -71,6 +72,7 @@ function i(x): ?number { if (x > 1) { return 42; } + return; } diff --git a/tests/return_new/__snapshots__/jsfmt.spec.js.snap b/tests/return_new/__snapshots__/jsfmt.spec.js.snap index 7b09eb9d..50171a4e 100644 --- a/tests/return_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return_new/__snapshots__/jsfmt.spec.js.snap @@ -19,20 +19,24 @@ var a: A = new B(); // OK (returns new A) function Foo() { return {}; } + var foo: number = new Foo(); function Bar() { return 0; } + var bar: number = new Bar(); function Qux() {} + var qux: number = new Qux(); class A {} function B() { return new A(); } + var a: A = new B(); " `; diff --git a/tests/sealed/__snapshots__/jsfmt.spec.js.snap b/tests/sealed/__snapshots__/jsfmt.spec.js.snap index 3ef70937..01fd8af1 100644 --- a/tests/sealed/__snapshots__/jsfmt.spec.js.snap +++ b/tests/sealed/__snapshots__/jsfmt.spec.js.snap @@ -44,12 +44,14 @@ module.exports = export_o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // awkward type cast function Foo() {} + var o = new Foo(); var x: number = o.x; Foo.prototype.m = function() { return this.x; }; + var y: number = o.m(); o.x = \"...\"; @@ -59,6 +61,7 @@ Foo.prototype = { return false; } }; + var export_o: { x: any } = o; module.exports = export_o; @@ -82,6 +85,7 @@ a.y = \'abc\'; // error, needs to be declared in Bar\'s constructor var o = require(\"./proto\"); o.z = 0; + var x: string = o.x; var Bar = require(\"./function\"); var a = new Bar(234); diff --git a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap index d9463026..a96fc1ee 100644 --- a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,7 @@ for (var i = 0; i < 10; ++i) { } else { a[i] = \"\"; } + } function foo(i): string { @@ -73,6 +74,7 @@ for (var i = 0; i < 10; ++i) { } else { a[i] = \"\"; } + } function foo(i: number): string { diff --git a/tests/singleton/__snapshots__/jsfmt.spec.js.snap b/tests/singleton/__snapshots__/jsfmt.spec.js.snap index d56cd7d7..7007bccd 100644 --- a/tests/singleton/__snapshots__/jsfmt.spec.js.snap +++ b/tests/singleton/__snapshots__/jsfmt.spec.js.snap @@ -45,12 +45,14 @@ function alwaysFalsy(x: boolean): false { function veryOptimistic(isThisAwesome: true): boolean { return isThisAwesome; } + var x: boolean = veryOptimistic(true); var y: boolean = veryOptimistic(false); function veryPessimistic(isThisAwesome: true): boolean { return !isThisAwesome; } + var x: boolean = veryPessimistic(true); var y: boolean = veryPessimistic(false); type MyOwnBooleanLOL = true | false; @@ -115,6 +117,7 @@ function highlander(howMany: 1): number { highlander(1); highlander(2); + type Foo = 1 | 2; function bar(num: Foo): number { @@ -126,6 +129,7 @@ bar(1); bar(2); bar(3); + type ComparatorResult = -1 | 0 | 1; function sort(fn: (x: any, y: any) => ComparatorResult) {} @@ -147,6 +151,7 @@ type HasSpaces = \"foo bar\" type NoSpaces = \"foobar\"; (\"foobar\": NoSpaces); + type HasSpaces = \"foo bar\"; (\"foo bar\": HasSpaces); diff --git a/tests/spread/__snapshots__/jsfmt.spec.js.snap b/tests/spread/__snapshots__/jsfmt.spec.js.snap index 4b09355d..d1dd4830 100644 --- a/tests/spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/spread/__snapshots__/jsfmt.spec.js.snap @@ -173,6 +173,7 @@ function test(x: { kind: ?string }, kinds: { [key: string]: string }): Array<{ kinds, value => { (value: string); + return { ...x, kind: value }; } ); @@ -208,6 +209,7 @@ var o = { foo: \"bar\" }; o = { ...o }; (o: { foo: string }); + var p = { foo: \"bar\" }; (p: { foo: string; abc: string }); @@ -215,6 +217,7 @@ var p = { foo: \"bar\" }; p = { ...p, abc: \"def\" }; (p: { foo: string; abc: string }); + var q = { foo: \"bar\" }; for (var i = 0; i < 10; i++) { @@ -240,7 +243,7 @@ let tests = [ let tests = [ function(x: Object) { ({ ...x }: Object); - + ({ ...x }: void); } ]; diff --git a/tests/statics/__snapshots__/jsfmt.spec.js.snap b/tests/statics/__snapshots__/jsfmt.spec.js.snap index c4d9eccf..a6dfaaf9 100644 --- a/tests/statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/statics/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,7 @@ C.g = function(x: string) { }; C.g(0); + var x: number = C.x; C.x = 0; @@ -41,6 +42,7 @@ C.prototype.f = function() { C.g = function(x) { return x; }; + var x: string = new C().f(); " `; diff --git a/tests/strict/__snapshots__/jsfmt.spec.js.snap b/tests/strict/__snapshots__/jsfmt.spec.js.snap index a789f71a..b17d52e3 100644 --- a/tests/strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strict/__snapshots__/jsfmt.spec.js.snap @@ -48,6 +48,7 @@ module.exports = f; function f(x: number) { return x; } + var x: string = f(0); module.exports = f; diff --git a/tests/suggest/__snapshots__/jsfmt.spec.js.snap b/tests/suggest/__snapshots__/jsfmt.spec.js.snap index 198c96a6..8fd14ea7 100644 --- a/tests/suggest/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suggest/__snapshots__/jsfmt.spec.js.snap @@ -32,6 +32,7 @@ var bar = require(\"./lib\"); function foo(z: number) { return bar(z); } + var array = [ \"foo\", \"bar\" ]; array; diff --git a/tests/super/__snapshots__/jsfmt.spec.js.snap b/tests/super/__snapshots__/jsfmt.spec.js.snap index 53caf108..40f05d18 100644 --- a/tests/super/__snapshots__/jsfmt.spec.js.snap +++ b/tests/super/__snapshots__/jsfmt.spec.js.snap @@ -195,7 +195,7 @@ class D extends A { y: number; constructor() { this.y; - + this.x; } } @@ -203,27 +203,28 @@ class E extends A { y: number; constructor() { super(); - + this.y; - + this.x; } } function leak(f) { f.y; - + f.x; } + class F extends A { y: number; constructor() { leak(this); - + super(); - + this.y; - + this.x; } } @@ -239,9 +240,9 @@ class H extends A { super(); else super(); - + this.y; - + this.x; } } @@ -260,7 +261,7 @@ class J__ {} class J_ extends J__ { constructor(closure_leaking_this) { closure_leaking_this(); - + super(); } foo() {} @@ -285,8 +286,9 @@ class K extends K_ { _this.foo(); } ); + var _this = this; - + this.closure_leaking_this(); } } @@ -305,6 +307,7 @@ class L extends L_ { (new L_(): L_); (new L(): L); + class M_ { constructor() { return { foo: \"foo\" }; @@ -319,6 +322,7 @@ class M extends M_ { (new M_(): { foo: string }); (new M(): { foo: string }); + class N_ { constructor(): this { let x = this; @@ -392,11 +396,12 @@ class B extends A { } static anotherStatic() { (super.staticMethod(\"foo\"): number); - + super.doesntExist(); } g() { super.f(0); + return super.g; } } diff --git a/tests/suppress/__snapshots__/jsfmt.spec.js.snap b/tests/suppress/__snapshots__/jsfmt.spec.js.snap index 9cd8fcb7..e8493fb7 100644 --- a/tests/suppress/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,7 @@ var test2: string = 123; function getNum() { return 123; } + var test3: string = getNum(); var test4: string = 123; var test5: string = 123; diff --git a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap index c4dc8b56..656cc2c1 100644 --- a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap @@ -30,6 +30,7 @@ function bar(): number { function foo(x: string) { return bar(); } + var a: string = foo(\"hi\"); " `; diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index c76be626..394df6d9 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -44,7 +44,7 @@ function bar(x) { default: return; } - + 1; } @@ -118,11 +118,13 @@ function qux(b) { var x = (b ? 0 : \"\"); switch (\"qux\") { case \"\": - + x = 0; + case \"qux\": - + x = x * x; + } } " @@ -198,18 +200,21 @@ function foo(x: mixed): string { var b = \"\"; switch (x) { case \"foo\": - + a = 0; + default: - + b = 0; + } - + (a: string); - + (a: number); - + (b: number); + return b; } @@ -218,24 +223,28 @@ function baz(x: mixed): number { var b = \"\"; switch (x) { case \"baz\": - + a = 0; + break; case \"bar\": - + a = \"\"; + default: - + b = 0; + } - + (a: string); - + (a: number); - + (b: string); - + (b: number); + return a + b; } " @@ -336,20 +345,24 @@ function f1(i) { var x; switch (i) { case 0: - + x = 0; + break; case 1: - + x = 1; + break; default: - + x = -1; + break; case 2: - + x = \"2\"; + break; } var y: number = x; @@ -361,8 +374,9 @@ function f2(i) { case 0: case 1: default: - + x = 1; + break; case 2: } @@ -376,8 +390,9 @@ function f3(i) { case 1: default: case 2: - + x = 1; + } var y: number = x; } @@ -399,7 +414,7 @@ function bar(x) { case 0: break; } - + 1; } diff --git a/tests/taint/__snapshots__/jsfmt.spec.js.snap b/tests/taint/__snapshots__/jsfmt.spec.js.snap index 8d302de9..ce9c0f86 100644 --- a/tests/taint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/taint/__snapshots__/jsfmt.spec.js.snap @@ -110,22 +110,23 @@ let tests = [ let tests = [ function(x: $Tainted, y: string) { let obj: Object = {}; - + obj.foo = x; - + obj[y] = x; }, function() { let obj: Object = { foo: \"foo\" }; - + (obj.foo: $Tainted); }, function(x: $Tainted) { let obj: Object = {}; - + obj.foo(x); + let foo = obj.foo; - + foo(x); } ]; @@ -262,7 +263,7 @@ let tests = [ }, function(x: any, y: $Tainted) { let z = x(); - + z(y); } ]; @@ -290,7 +291,7 @@ class A { class A { f(x: $Tainted) { fakeDocument.location = x; - + doStuff(x); } f1(x: $Tainted) { diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index 286eb2c5..1068458d 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -58,33 +58,34 @@ let tests = [ \`foo \${123} bar\`; \`foo \${{ bar: 123 }} baz\`; + let tests = [ function(x: string) { \`foo \${x}\`; - + \`\${x} bar\`; - + \`foo \${\"bar\"} \${x}\`; }, function(x: number) { \`foo \${x}\`; - + \`\${x} bar\`; - + \`foo \${\"bar\"} \${x}\`; }, function(x: boolean) { \`foo \${x}\`; - + \`\${x} bar\`; - + \`foo \${\"bar\"} \${x}\`; }, function(x: mixed) { \`foo \${x}\`; - + \`\${x} bar\`; - + \`foo \${\"bar\"} \${x}\`; } ]; diff --git a/tests/this/__snapshots__/jsfmt.spec.js.snap b/tests/this/__snapshots__/jsfmt.spec.js.snap index ae577dc9..72a20a46 100644 --- a/tests/this/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this/__snapshots__/jsfmt.spec.js.snap @@ -94,11 +94,13 @@ F.prototype.m = function() { }; function foo(p: string) {} + var o1 = new F(); o1.x = \"\"; foo(o1.x); + var o2 = new F(); o1.y = 0; @@ -106,6 +108,7 @@ o1.y = 0; o2.y = \"\"; foo(o2.y); + var o3 = new F(); o3.m(); @@ -119,6 +122,7 @@ foo(o2.y); function f1(): number { return this.x; } + var f1_1 = f1.bind({ x: 0 })(); var f1_2: string = f1.bind({ x: 0 })(); var f1_3 = f1.bind({ x: \"\" })(); @@ -134,6 +138,7 @@ function f2(): number { }; return a2(); } + var f2_1 = f2.bind({ x: 0 })(); var f2_2: string = f2.bind({ x: 0 })(); var f2_3 = f2.bind({ x: \"\" })(); @@ -197,12 +202,14 @@ var f = c.foo(); var i = f(); (i: C); + class D extends C {} var d = new D(); var g = d.foo(); var j = g(); (j: D); + class E { foo(x: number) {} } diff --git a/tests/this_type/__snapshots__/jsfmt.spec.js.snap b/tests/this_type/__snapshots__/jsfmt.spec.js.snap index 4326dd51..50458b18 100644 --- a/tests/this_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this_type/__snapshots__/jsfmt.spec.js.snap @@ -95,6 +95,7 @@ var d = new D(); (d: C).next = new C(); (d.next: D); + class A { foo(that: X) {} } @@ -126,6 +127,7 @@ class Misc { inout_promise: Promise; *out_generator(): Generator { yield this; + return this; } in_generator(_: Generator) {} @@ -242,6 +244,7 @@ class B1 extends A1 { } (new B1().bar(): B1); + class B3 extends A3 { foo(): B3 { return new B3(); @@ -304,6 +307,7 @@ class C { (new DoublyLinkedList().prev(): DoublyLinkedList); (new DoublyLinkedList().next(): DoublyLinkedList); + var MiniImmutable = require(\"mini-immutable\"); class C { map: MiniImmutable.OrderedMap; @@ -521,6 +525,7 @@ class InheritOverride extends Override {} ((new Override(): Base).foo(): Base); (new InheritOverride().bar_caller(): InheritOverride); + class Base2 { foo(): this { return this; diff --git a/tests/throw/__snapshots__/jsfmt.spec.js.snap b/tests/throw/__snapshots__/jsfmt.spec.js.snap index 705459e0..24a8561a 100644 --- a/tests/throw/__snapshots__/jsfmt.spec.js.snap +++ b/tests/throw/__snapshots__/jsfmt.spec.js.snap @@ -35,6 +35,7 @@ function g(a: ?string) { if (a == null) { throw new Error(); } + return a * 1; } diff --git a/tests/try/__snapshots__/jsfmt.spec.js.snap b/tests/try/__snapshots__/jsfmt.spec.js.snap index 5682b24a..fdf0be4e 100644 --- a/tests/try/__snapshots__/jsfmt.spec.js.snap +++ b/tests/try/__snapshots__/jsfmt.spec.js.snap @@ -238,6 +238,7 @@ function f() { function f() { try { might_throw(); + var x: number = 0; } catch (e) { var y: number = x; @@ -247,6 +248,7 @@ function f() { function f() { try { might_throw(); + var x: number = 0; } finally { var y: number = x; @@ -266,6 +268,7 @@ function f() { var x: number = 0; } catch (e) { might_throw(); + var x: number = 0; } finally { var y: number = x; @@ -277,6 +280,7 @@ function f() { var x: number = 0; } catch (e) { might_throw(); + var x: number = 0; } var y: number = x; @@ -285,6 +289,7 @@ function f() { function f() { try {} catch (e) {} finally { might_throw(); + var x: number = 0; } var y: number = x; @@ -295,7 +300,7 @@ function f() { var x: number; } catch (e) {} finally { might_throw(); - + x = 0; } var y: number = x; @@ -306,7 +311,7 @@ function f() { var x: number; } finally { might_throw(); - + x = 0; } var y: number = x; @@ -336,11 +341,11 @@ function f() { function f(b) { try { var x: number; - + if (b) { throw new Error(); } - + x = 0; } catch (e) {} var y: number = x; @@ -424,8 +429,9 @@ function foo(x: ?number): string { try {} catch (e) { return \"bar\"; } - + console.log(); + return \"foo\"; } @@ -450,8 +456,9 @@ function qux(): string { try { throw new Error(\"foo\"); } catch (e) {} - + console.log(); + return \"bar\"; } @@ -478,7 +485,7 @@ function corge(): string { } catch (e) { throw new Error(\"bar\"); } - + bar(); } " @@ -546,13 +553,14 @@ function foo() { x = \"\"; } catch (e) { x = false; + throw -1; } finally { y = {}; } - + x(); - + y(); } @@ -563,7 +571,7 @@ function bar(response) { } catch (e) { throw new Error(\"...\"); } - + if (payload.error) {} } @@ -573,7 +581,7 @@ function qux() { try { throw -1; } finally {} - + x(); } " diff --git a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap index fc3fc02f..e5ecc4a2 100644 --- a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap @@ -97,22 +97,27 @@ cn; function foo() { return C; } + var D = foo(); var dn: D = new C(); dn; + type E = C; var en: E = new C(); en; + type F = C; var fn: F = new C(); fn; + type O = { x: X }; var on: O = { x: 0 }; on; + type Mono = C; var mn: Mono = new C(); @@ -152,7 +157,7 @@ let tests = [ let tests = [ function() { let x = {}; - + Object.defineProperty(x, \"foo\", { value: \"\" }); } ]; @@ -258,6 +263,7 @@ function foo() {} foo(); str; + type Point = [number, string]; const x: Point = [ 1, \"foo\" ]; type MyStr = \"cool\"; diff --git a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap index 9491a465..0b05393b 100644 --- a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,7 @@ module.exports = printBinaryExpression; * the root directory of this source tree. */ \"use babel\"; + import type { BinaryExpression } from \"./types\"; function printBinaryExpression(node: BinaryExpression) { @@ -5113,6 +5114,7 @@ export type JSXSpreadAttribute = { // TODO: Make this correct. // TODO: Make this correct. \"use strict\"; + export type Comment = { type: \"CommentLine\"; _CommentLine: void; diff --git a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap index 9da07f02..7d03d261 100644 --- a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap @@ -109,7 +109,7 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; - + this.y = y; } } @@ -129,6 +129,7 @@ class MySubclass extends MyClass { function singleton(x: T): Array { return [ x ]; } + var num_array: Array = singleton(0); " `; diff --git a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap index a1eabb34..f02094f2 100644 --- a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap @@ -107,7 +107,7 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; - + this.y = y; } } @@ -127,6 +127,7 @@ class MySubclass extends MyClass { function singleton(x: T): Array { return [ x ]; } + var num_array: Array = singleton(0); " `; diff --git a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap index eb1593aa..6f485b21 100644 --- a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap @@ -106,6 +106,7 @@ var b_star: B<*> = new B(123); (b_default.p: boolean); (b_star.p: boolean); + class C extends A {} var c_number: C = new C(123); var c_void: C = new C(); @@ -117,6 +118,7 @@ var c_star: C<*> = new C(\"hello\"); (c_default.p: boolean); (c_star.p: boolean); + class D extends A {} var d_number: D = new D(123); var d_void: D = new D(); @@ -132,12 +134,14 @@ var d_star: D<*> = new D(10); (d_default.p: boolean); (d_star.p: boolean); + class E {} class F {} class G extends A {} var g_default: G = new G(\"hello\"); (g_default.p: boolean); + class H {} class I extends A {} var i_number: I = new I(123); diff --git a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap index 25e4e6a7..56ca7f23 100644 --- a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap @@ -13,7 +13,7 @@ exports[`test class.js 1`] = ` class C { a(x: T, a: A) { this.b(x); - + this.b(a); } b(x: T) {} @@ -45,18 +45,18 @@ f(0); // ok function f(a: T) { function g(b: U, c: T = a) { function h(d: U = b) {} - + h(); - + h(b); - + h(c); } - + g(0); - + g(0, a); - + g(0, 0); } @@ -163,6 +163,7 @@ g.m(0); g.m(true); (g.m(\"\"): G); + class H { x: T; m(x: T) { diff --git a/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap index 7d9462fc..b76e51ad 100644 --- a/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap @@ -50,7 +50,7 @@ async function foo(x: boolean): Promise { async function run() { console.log(await foo(true)); - + console.log(await foo(false)); } diff --git a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap index 82d1db30..85c01473 100644 --- a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap @@ -44,7 +44,7 @@ async function foo(x: boolean): Promise { async function run() { console.log(await foo(true)); - + console.log(await foo(false)); } diff --git a/tests/unary/__snapshots__/jsfmt.spec.js.snap b/tests/unary/__snapshots__/jsfmt.spec.js.snap index 868c8c67..a268caf4 100644 --- a/tests/unary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary/__snapshots__/jsfmt.spec.js.snap @@ -98,18 +98,18 @@ let tests = [ let tests = [ function(y: number) { y++; - + y--; - + ++y; - + --y; }, function(y: string) { y++; - + (y: number); - + y++; }, function(y: string) { @@ -123,9 +123,9 @@ let tests = [ }, function() { const y = 123; - + y++; - + y--; }, function(y: any) { diff --git a/tests/undefined/__snapshots__/jsfmt.spec.js.snap b/tests/undefined/__snapshots__/jsfmt.spec.js.snap index d1ae3105..d354760d 100644 --- a/tests/undefined/__snapshots__/jsfmt.spec.js.snap +++ b/tests/undefined/__snapshots__/jsfmt.spec.js.snap @@ -18,8 +18,9 @@ function doSomethingAsync(): Promise { return new Promise( (resolve, reject) => { resolve(); + var anotherVoidPromise: Promise = Promise.resolve(); - + resolve(anotherVoidPromise); } ); @@ -46,13 +47,13 @@ function qux(x?: number, y:string = \"\", z) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo() { var x; - + x.foo(); } function bar() { var x: ?{ bar(): void }; - + if (x) x.bar(); } @@ -104,23 +105,26 @@ let tests = [ function(x: number) { var id; var name = (id ? \"John\" : undefined); - + (name: boolean); + const bar = [ undefined, \"bar\" ]; - + (bar[x]: boolean); }, function(x: number) { var undefined = \"foo\"; - + (undefined: string); + var x; - + if (x !== undefined) { x[0]; } + const bar = [ undefined, \"bar\" ]; - + (bar[x]: boolean); } ]; diff --git a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap index 09dea7d4..b8ab6b12 100644 --- a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap @@ -5036,16 +5036,19 @@ type T1 = (A | B) & C; function f1(x: T1): T1 { return x; } + type T2 = (A & B) | C; function f2(x: T2): T2 { return x; } + type T3 = (A & C) | (B & C); function f3(x: T3): T3 { return x; } + type T4 = (A | C) & (B | C); function f4(x: T4): T4 { diff --git a/tests/union/__snapshots__/jsfmt.spec.js.snap b/tests/union/__snapshots__/jsfmt.spec.js.snap index f877dc10..a90fecc2 100644 --- a/tests/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union/__snapshots__/jsfmt.spec.js.snap @@ -31,6 +31,7 @@ class D { content: string | C; copyContent(content: C): string | C { this.content = content; + return this.content; } } @@ -323,6 +324,7 @@ function foo(x: Foo) {} foo(x); foo(y); + type Bar = () => C | string; function f() { @@ -407,24 +409,26 @@ function corge(b) { function bar(x: Document | string): void {} bar(0); + class C {} class D {} function CD(b) { var E = (b ? C : D); var c: C = new E(); - + function qux(e: E) {} - + function qux2(e: C | D) {} - + qux2(new C()); } + declare class F { foo(x: number): void; foo(x: string): void } function corge(b) { var x = (b ? \"\" : 0); - + new F().foo(x); } " @@ -5477,6 +5481,7 @@ type Data = { // but not sure it\'s worth doing that before the real solution. // also, error pos omits this line completely \"use strict\"; + class SecurityCheckupTypedLogger { _data: Data; setError(value: ErrorCode) { diff --git a/tests/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/union_new/__snapshots__/jsfmt.spec.js.snap index e91e6baf..847e438f 100644 --- a/tests/union_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union_new/__snapshots__/jsfmt.spec.js.snap @@ -27,6 +27,7 @@ class U {} declare var children: U; (children: T | U); + class A {} class B {} type VirtualElement = Thunk | VirtualNode; @@ -444,6 +445,7 @@ type A6 = B6[]; function obj(a: A1 | A2) { return a.x; } + const obj_result = obj({ x: \"\" }); type A1 = { x: B1 }; type A2 = { x: B2 }; @@ -455,6 +457,7 @@ type B2 = string; function fun(a: A3 | A4) { return a(); } + const fun_result = fun(() => \"\"); type A3 = () => B3; type A4 = () => B4; @@ -464,10 +467,12 @@ type B4 = string; (fun_result: B3 | B4); function inst(a: A5 | A6) {} + class B5 {} class B6 {} inst([ new B6() ]); + type A5 = B5[]; type A6 = B6[]; " @@ -573,12 +578,14 @@ type B6 = string; function obj(a: { x: number } | { x: string }) {} obj(({ x: \"\" }: A1)); + type A1 = { x: B1 }; type B1 = string; function fun(a: (() => number) | (() => string)) {} fun((() => \"\": A2)); + type A2 = () => B2; type B2 = string; class C {} @@ -586,28 +593,33 @@ class C {} function inst(a: C | C) {} inst((new C(): A3)); + type A3 = C; type B3 = string; function alias(a: T | T) {} alias({ x: (x: V) => {} }); + type T = { x: U }; type U = (x: V) => void; type V = X; type B4 = string; function stat(a: { x: number } | { x: string }) {} + class D { static x: B5; } stat(D); + type B5 = string; function tup(a: [number, boolean] | [string, boolean]) {} tup(([ \"\", false ]: A6)); + type A6 = [B6, boolean]; type B6 = string; " @@ -657,12 +669,14 @@ type B2 = string; function fun(a: ((x: number) => void) | ((x: string) => void)) {} fun((x => {}: A1)); + type A1 = (x: B1) => void; type B1 = string; function arr(a: number[] | string[]) {} arr(([]: A2)); + type A2 = B2[]; type B2 = string; " @@ -717,6 +731,7 @@ type B2 = string; // example with array types //////////////////////////// function fun(a: ((x: number) => void) | ((x: string) => void)) {} + const a1 = (x => {}: A1); fun(a1); @@ -724,10 +739,12 @@ fun(a1); function fun_call(x: string) { a1(x); } + type A1 = (x: B1) => void; type B1 = string; function arr(a: number[] | string[]) {} + const a2 = ([]: A2); arr(a2); @@ -739,6 +756,7 @@ function arr_set(x: string, i: number) { function arr_get(i: number): string { return a2[i]; } + type A2 = B2[]; type B2 = string; " @@ -796,6 +814,7 @@ function fun_call(x: string): string { } function arr(a: number[] | string[]) {} + var a2 = []; arr(a2); @@ -843,6 +862,7 @@ class C { } function inst(a: E): C | C { return a; } + const mk_C = () => C; const mk_D = () => D; const mk_E = () => E; @@ -899,6 +919,7 @@ type PG = { x: X, y?: PG }; function rec(x: F1 | F2) {} rec({ x: 0 }); + type F1 = G1; type F2 = G2; type G1 = { x: H1; y?: G1 }; @@ -909,6 +930,7 @@ type H2 = number; function polyrec(x: PF | PF) {} rec({ x: 0 }); + type PF = PG; type PG = { x: X; y?: PG }; " @@ -949,6 +971,7 @@ type H2_ = number; function rec(x: F1 | F2) {} rec({ x: 0 }); + type F1 = G1 | G1_; type F2 = G2 | G2_; type G1 = { x: H1 }; @@ -1109,6 +1132,7 @@ function check_prim(_: number | string) {} check_prim(\"\"); check_prim(id(\"\")); + class C {} class D {} @@ -1133,6 +1157,7 @@ function check_arr(_: number[] | string[]) {} check_arr([ \"\" ]); check_arr([ id(\"\") ]); + class P {} function check_poly_inst(_: P | P) {} @@ -1179,6 +1204,7 @@ length({ kind: \"cons\" }); length({ kind: \"cons\", next: { kind: \"nil\" } }); length({ kind: \"empty\" }); + type List = Nil | Cons; type Nil = { kind: \"nil\" }; type Cons = { kind: \"cons\"; next: List }; @@ -1289,6 +1315,7 @@ bar(() => { }); function foo(target: EventTarget) { target.addEventListener(\"click\", e => {}); } + declare class EventTarget { addEventListener(type: \"foo\", listener: KeyboardEventHandler): void; addEventListener(type: string, listener: EventHandler): void @@ -1337,6 +1364,7 @@ foo(() => qux()); function bar(x: Bar) {} bar(() => qux()); + var x = false; function qux() { @@ -1409,6 +1437,7 @@ declare class D { function m() { return new D(); } + declare class D { constructor(_: void): void; constructor(_: null): void } " `; @@ -1549,7 +1578,7 @@ type Obj = NestedObj & { x: string }; function foo(obj: Obj) { obj.x; - + obj.x; } " @@ -1674,10 +1703,12 @@ declare function foo(x: string): string; declare var x: number | string; (foo(x): number | string); + type T = number | string; declare var y: T; (foo(y): T); + declare class Record { set(x: \"foo\", y: number): void; set(x: \"bar\", y: string): void @@ -1871,8 +1902,9 @@ declare function convert(iter: SomeIterable<[K, V]>): ImmutableMap; function foo(): ImmutableMap { const countersGlobalMap = new SomeMap(); - + countersGlobalMap.set(\"\", false); + return convert(countersGlobalMap); } " diff --git a/tests/unreachable/__snapshots__/jsfmt.spec.js.snap b/tests/unreachable/__snapshots__/jsfmt.spec.js.snap index cfaabf80..90ffeeb5 100644 --- a/tests/unreachable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unreachable/__snapshots__/jsfmt.spec.js.snap @@ -30,7 +30,7 @@ function test2() { // error, n is number (EmptyT would work) function test1(): string { return bar(); - + function bar() { return 0; } @@ -39,7 +39,7 @@ function test1(): string { function test2() { const n = 0; return; - + function f() { var x: typeof n = 0; var y: string = n; @@ -84,11 +84,13 @@ foo(1, 2); // assignments are not hoisted, should generate 2 warnings function foo(x, y) { \"use strict\"; + return bar(x) + baz(y); - + function bar(ecks) { return x + ecks; } + var baz = function(why) { return y + why; }; diff --git a/tests/value/__snapshots__/jsfmt.spec.js.snap b/tests/value/__snapshots__/jsfmt.spec.js.snap index 8641e95d..e7d87b35 100644 --- a/tests/value/__snapshots__/jsfmt.spec.js.snap +++ b/tests/value/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,7 @@ table[\"x\"] = \"hello\"; var o = {}; o[\"x\"] = 4; + var y: string = o[\"x\"]; var table: { [_: string]: number } = {}; diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap index 9717ddc1..bbb9bc10 100644 --- a/tests/while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/while/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,7 @@ function foo(x: boolean) { if (x) { continue; } + return; } } @@ -62,13 +63,14 @@ class C { } function blah() {} + var node: ?C = new C(); while (node) { var parent = node.m(); var cloneable: C = node; - + blah(); - + node = parent.m(); } "