diff --git a/bin/jscodefmt b/bin/jscodefmt index 0f171c39..8b66a9d5 100755 --- a/bin/jscodefmt +++ b/bin/jscodefmt @@ -1,16 +1,28 @@ #!/usr/bin/env node const fs = require("fs"); -const argv = require("minimist")(process.argv.slice(2)); +const minimist = require("minimist"); const jscodefmt = require("../index"); +const argv = minimist(process.argv.slice(2), { + boolean: ["write", "useFlowParser"] +}); + const filename = argv["_"][0]; const printWidth = argv['print-width'] || 80; const tabWidth = argv['tab-width'] || 2; const useFlowParser = argv['flow-parser']; +const write = argv['write']; -console.log(jscodefmt.format(fs.readFileSync(filename, "utf8"), { +const output = jscodefmt.format(fs.readFileSync(filename, "utf8"), { printWidth, tabWidth, useFlowParser -})); +}); + +if(write) { + fs.writeFileSync(filename, output, "utf8"); +} +else { + console.log(output); +} diff --git a/index.js b/index.js index 52152b4a..6330f7c3 100644 --- a/index.js +++ b/index.js @@ -50,6 +50,8 @@ module.exports = { }); } + ast.tokens = []; + const printer = new Printer({ tabWidth, wrapColumn: printWidth }); return printer.printGenerically(ast).code; } diff --git a/src/pp.js b/src/pp.js index af4a5fcc..b2ee3bfb 100644 --- a/src/pp.js +++ b/src/pp.js @@ -59,9 +59,6 @@ function iterDoc(topDoc, func) { } } else if(doc.type !== "line") { - if(doc.contents == null) { - console.log("JWL", doc); - } docs.push(doc.contents); } } diff --git a/src/printer.js b/src/printer.js index d127fdba..c36d4787 100644 --- a/src/printer.js +++ b/src/printer.js @@ -233,7 +233,7 @@ function genericPrintNoParens(path, options, print) { // Babel 6 if (n.directives) { path.each(function(childPath) { - parts.push(print(childPath), ";", line); + parts.push(print(childPath), ";", hardline); }, "directives"); } @@ -566,6 +566,11 @@ function genericPrintNoParens(path, options, print) { return printStatementSequence(bodyPath, options, print); }, "body"); + // If there are no contents, return a simple block + if(!getFirstString(naked)) { + return "{}"; + } + parts.push("{"); // Babel 6 if (n.directives) { @@ -700,17 +705,22 @@ function genericPrintNoParens(path, options, print) { case "ArrayExpression": case "ArrayPattern": - parts.push(multilineGroup(concat([ - "[", - indent(options.tabWidth, - concat([ - line, - join(concat([",", line]), - path.map(print, "elements")) - ])), - line, - "]" - ]))); + if(n.elements.length === 0) { + parts.push("[]"); + } + else { + parts.push(multilineGroup(concat([ + "[", + indent(options.tabWidth, + concat([ + line, + join(concat([",", line]), + path.map(print, "elements")) + ])), + line, + "]" + ]))); + } if (n.typeAnnotation) parts.push(path.call(print, "typeAnnotation")); @@ -835,8 +845,9 @@ function genericPrintNoParens(path, options, print) { ]); case "IfStatement": - var con = adjustClause(path.call(print, "consequent"), options); - var parts = [ + const con = adjustClause(path.call(print, "consequent"), options); + + parts = [ "if (", group(concat([ indent(options.tabWidth, concat([ @@ -976,7 +987,8 @@ function genericPrintNoParens(path, options, print) { case "LabeledStatement": return concat([ path.call(print, "label"), - ":\n", + ":", + hardline, path.call(print, "body") ]); @@ -1617,7 +1629,7 @@ function printStatementSequence(path, options, print) { var printed = []; - path.map(function(stmtPath) { + path.map(function(stmtPath, i) { var stmt = stmtPath.getValue(); // Just in case the AST has been modified to contain falsy @@ -1632,35 +1644,26 @@ function printStatementSequence(path, options, print) { return; } - printed.push(print(stmtPath)); + const addSpacing = shouldAddSpacing(stmt) + const stmtPrinted = print(stmtPath); + const parts = []; + + if (addSpacing && !isFirstStatement(stmtPath)) { + parts.push(hardline); + } + + parts.push(stmtPrinted); + + if (addSpacing && !isLastStatement) { + parts.push(literalline); + } + + printed.push(concat(parts)); }); return join(hardline, printed); } -function maxSpace(s1, s2) { - if (!s1 && !s2) { - return fromString(""); - } - - if (!s1) { - return fromString(s2); - } - - if (!s2) { - return fromString(s1); - } - - var spaceLines1 = fromString(s1); - var spaceLines2 = fromString(s2); - - if (spaceLines2.length > spaceLines1.length) { - return spaceLines2; - } - - return spaceLines1; -} - function printMethod(path, options, print) { var node = path.getNode(); var kind = node.kind; @@ -1935,3 +1938,26 @@ function nodeStr(str, options) { return JSON.stringify(str); } } + +function shouldAddSpacing(node) { + return node.type === "IfStatement" || + node.type === "ForStatement" || + node.type === "ForInStatement" || + node.type === "ForOfStatement" || + node.type === "ExpressionStatement" || + node.type === "FunctionDeclaration"; +} + +function isFirstStatement(path) { + const parent = path.getParentNode(); + const node = path.getValue(); + const body = parent.body; + return body && body[0] === node; +} + +function isLastStatement(path) { + const parent = path.getParentNode(); + const node = path.getValue(); + const body = parent.body; + return body && body[body.length - 1] === node; +} diff --git a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap index 133a3914..bf79f80d 100644 --- a/tests/abnormal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/abnormal/__snapshots__/jsfmt.spec.js.snap @@ -12,9 +12,10 @@ function foo() { break; } } + function bar() { L: -do { + do { continue L; } while (false); } @@ -29,13 +30,14 @@ function foo() { bar(x); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function bar(x: number) { - -} +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 61942311..a75960e3 100644 --- a/tests/annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/annot/__snapshots__/jsfmt.spec.js.snap @@ -93,9 +93,11 @@ var array_of_tuple: [number, string][] = [ [ 0, \"foo\" ], [ 1, \"bar\" ] ]; var array_of_tuple_parens: [number, string][] = array_of_tuple; type ObjType = { \"bar-foo\": string; \"foo-bar\": number }; var test_obj: ObjType = { \"bar-foo\": \"23\" }; + function param_anno(n: number): void { n = \"hey\"; } + function param_anno2( batchRequests: Array<{ method: string; path: string; params: ?Object }> ): void { @@ -111,9 +113,11 @@ function param_anno2( } var toz: null = 3; var zer: null = null; + function foobar(n: ?number): number | null | void { return n; } + function barfoo(n: number | null | void): ?number { return n; } @@ -142,12 +146,15 @@ function foo() { // ok (no confusion across scopes) // looked up above let myClassInstance: MyClass = null; + function bar(): MyClass { return null; } class MyClass {} + function foo() { let myClassInstance: MyClass = mk(); + function mk() { return new MyClass(); } @@ -161,9 +168,8 @@ exports[`test issue-530.js 1`] = ` module.exports = foo; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function foo(...args: any) { - -} +function foo(...args: any) {} + module.exports = foo; " `; @@ -204,9 +210,11 @@ function bar(y: MyObj): string { * leading to an error. */ type MyObj = Object; + function foo(x: { [key: string]: mixed }) { bar(x); } + function bar(y: MyObj): string { return y.foo; } @@ -218,6 +226,7 @@ exports[`test other.js 1`] = ` module.exports = (C: any); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C {} + module.exports = (C: any); " `; @@ -255,6 +264,7 @@ declare class Map { insertWith(fn: Merge, k: K, v: V): Map } declare function foldr(fn: (a: A, b: B) => B, b: B, as: A[]): B; + function insertMany( merge: Merge, vs: [K, V][], m: Map ): Map { @@ -278,6 +288,7 @@ exports[`test test.js 1`] = ` ((0: C): string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var C = require(\"./other\"); + ((0: C): string); " `; diff --git a/tests/any/__snapshots__/jsfmt.spec.js.snap b/tests/any/__snapshots__/jsfmt.spec.js.snap index f412756f..454a59b0 100644 --- a/tests/any/__snapshots__/jsfmt.spec.js.snap +++ b/tests/any/__snapshots__/jsfmt.spec.js.snap @@ -13,9 +13,11 @@ var z:string = qux(0); function foo(x: any): any { return x; } + function bar(x: any): mixed { return x; } + function qux(x: mixed): any { return x; } @@ -68,12 +70,15 @@ var w:string = baz(0); function foo(x: $FlowFixMe): $FlowFixMe { return x; } + function bar(x: $FlowFixMe): mixed { return x; } + function qux(x: $FlowFixMe): $FlowFixMe { return x; } + function baz(x: $FlowFixMe): $FlowFixMe { return x; } @@ -117,12 +122,15 @@ var w:string = baz(0); function foo(x: $FlowIssue): $FlowIssue { return x; } + function bar(x: $FlowIssue): mixed { return x; } + function qux(x: $FlowIssue): $FlowIssue { return x; } + function baz(x: $FlowIssue): $FlowIssue { return x; } @@ -176,17 +184,20 @@ declare class C { bar(n1: number, n2: number): number; bar(s1: string, s2: string): string } + 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) { if (any_fun1(x)) { (x: boolean); } } var any_fun2 = require(\"./anyexportflowfile\"); + function bar2(x: mixed) { if (any_fun2(x)) { (x: boolean); @@ -216,6 +227,7 @@ function foo(o: ?AsyncRequest) { * annotation - without it, the body of the if will be unreachable */ type AsyncRequest = any; + function foo(o: ?AsyncRequest) { if (o) { var n: number = o; diff --git a/tests/arith/__snapshots__/jsfmt.spec.js.snap b/tests/arith/__snapshots__/jsfmt.spec.js.snap index dd51b527..9bcbcd2a 100644 --- a/tests/arith/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arith/__snapshots__/jsfmt.spec.js.snap @@ -132,76 +132,113 @@ let tests = [ // ok // error, string ~> empty // error, string ~> empty -function num(x: number) { - -} -function str(x: string) { - -} +function num(x: number) {} + +function str(x: string) {} + function foo() { var x = 0; var y = \"...\"; var z = {}; + num(x + x); + num(x + y); + str(x + y); + str(x + x); + str(z + y); } + function bar0(x: ?number, y: number) { num(x + y); } + function bar1(x: number, y: ?number) { num(x + y); } + function bar2(x?: number, y: number) { num(x + y); } + function bar3(x: number, y?: number) { num(x + y); } + function bar4(x?: ?number, y: number) { num(x + y); } + function bar5(x: number, y?: ?number) { num(x + y); } + num(null + null); + num(undefined + undefined); + num(null + 1); + num(1 + null); + num(undefined + 1); + num(1 + undefined); + num(null + true); + num(true + null); + num(undefined + true); + num(true + undefined); + str(\"foo\" + true); + str(true + \"foo\"); + str(\"foo\" + null); + 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); } ]; @@ -224,11 +261,16 @@ y **= 2; // error /* @flow */ // error let x: number = 2 ** 3; + x **= 4; let y: string = \"123\"; + y **= 2; + 1 + 2 ** 3 + 4; + 2 ** 2; + (-2) ** 2; " `; @@ -251,15 +293,19 @@ function f(a: A, b: B): B {return b + a; } // error function f(a: A): A { return a + a; } + function f(a: A, b: B): A { return a + b; } + function f(a: A, b: B): A { return b + a; } + function f(a: A, b: B): B { return a + b; } + function f(a: A, b: B): B { return b + a; } @@ -282,14 +328,16 @@ y *= 2; // error ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ // error -function num(x: number) { - -} +function num(x: number) {} + num(null * 1); + num(1 * null); let x: number = 2 * 3; + x *= 4; let y: string = \"123\"; + y *= 2; " `; @@ -341,27 +389,45 @@ let tests = [ // error // error 1 < 2; + 1 < \"foo\"; + \"foo\" < 1; + \"foo\" < \"bar\"; + 1 < { foo: 1 }; + ({ foo: 1 }) < 1; + ({ foo: 1 }) < { foo: 1 }; + \"foo\" < { foo: 1 }; + ({ foo: 1 }) < \"foo\"; var x = (null: ?number); + 1 < x; + x < 1; + null < null; + undefined < null; + null < undefined; + undefined < undefined; + 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 7a576578..e26b48bf 100644 --- a/tests/array-filter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array-filter/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,7 @@ function filterOutSmall (arr: Array): Array { function filterOutVoids(arr: Array): Array { return arr.filter(Boolean); } + function filterOutSmall(arr: Array): Array { return arr.filter(num => num && num > 10); } @@ -49,6 +50,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 c902ddba..f4dc70ce 100644 --- a/tests/array_spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/array_spread/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,9 @@ var y: Array = [\'3\', ...x]; var A = [ 1, 2, 3 ]; var B = [ ...A ]; 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 317c40ec..4a531058 100644 --- a/tests/arraylib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arraylib/__snapshots__/jsfmt.spec.js.snap @@ -66,9 +66,7 @@ function from_test() { // acc is element type of array when no init is provided // error, string ~> number // error, string ~> number -function foo(x: string) { - -} +function foo(x: string) {} var a = [ 0 ]; var b = a.map( function(x) { @@ -92,12 +90,14 @@ var k: Array = h.concat(h); var l: Array = h.concat(1, 2, 3); var m: Array = h.concat(\"a\", \"b\", \"c\"); var n: Array = h.concat(\"a\", \"b\", \"c\"); + function reduce_test() { [ 0, 1, 2, 3, 4 ].reduce( function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; } ); + [ 0, 1, 2, 3, 4 ].reduce( function(previousValue, currentValue, index, array) { return previousValue + currentValue + array[index]; @@ -114,9 +114,12 @@ function reduce_test() { return a.concat(b); } ); + [ \"\" ].reduce((acc, str) => acc * str.length); + [ \"\" ].reduceRight((acc, str) => acc * str.length); } + function from_test() { var a: Array = Array.from( [ 1, 2, 3 ], diff --git a/tests/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/arrays/__snapshots__/jsfmt.spec.js.snap index a81448d3..4c470695 100644 --- a/tests/arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrays/__snapshots__/jsfmt.spec.js.snap @@ -42,14 +42,16 @@ module.exports = \"arrays\"; /* @providesModule 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 = [ ]; +function foo(x: string) {} +var a = []; + 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 ]; @@ -72,6 +74,7 @@ var abig2: Array<{ x: number; y: number }> = [ { x: 0, y: 0, c: 1 }, { x: 0, y: 0, c: \"hey\" } ]; + module.exports = \"arrays\"; " `; @@ -88,9 +91,11 @@ arr[day] = 0; // Date instances are numeric (see Flow_js.numeric) and thus can index into // arrays. // error: number ~> string -var arr = [ ]; +var arr = []; var day = new Date(); + arr[day] = 0; + (arr[day]: string); " `; diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 471ce527..07a5e9bc 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,9 @@ var ident = (x: T): T => x; var add = (x: number, y: number): number => x + y; var bad = (x: number): string => x; var ident = (x: T): T => x; + (ident(1): number); + (ident(\"hi\"): number); " `; @@ -41,6 +43,7 @@ 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 a3866730..e0d923f5 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -71,17 +71,21 @@ var objf : () => Promise = obj.f; async function f0(): Promise { return 1; } + async function f1(): Promise { return 1; } + async function f2(p: Promise): Promise { var x: number = await p; var y: number = await 1; return x + y; } + async function f3(p: Promise): Promise { return await p; } + async function f4(p: Promise): Promise { return await p; } @@ -131,6 +135,7 @@ var P: Promise> = new Promise( resolve(C); } ); + async function foo() { class Bar extends (await P) {} return Bar; @@ -164,51 +169,23 @@ console.log(x.async); var async = 3; var y = { async }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -async function f() { - -} -async function ft(a: T) { - -} +async function f() {} + +async function ft(a: T) {} class C { - async m() { - - } - async mt(a: T) { - - } - static async m(a) { - - } - static async mt(a: T) { - - } + async m() {} + async mt(a: T) {} + static async m(a) {} + static async mt(a: T) {} } -var e = async function() { - -}; -var et = async function(a: T) { - -}; -var n = new async function() { - -}(); -var o = { - async m() { - - } -}; -var ot = { - async m(a: T) { - - } -}; -var oz = { - async async() { - - } -}; +var e = async function() {}; +var et = async function(a: T) {}; +var n = new async function() {}(); +var o = { async m() {} }; +var ot = { async m(a: T) {} }; +var oz = { async async() {} }; var x = { async: 5 }; + console.log(x.async); var async = 3; var y = { async }; @@ -246,13 +223,13 @@ async function foo3(): Promise { async function foo1(): Promise { return; } + async function foo2(): Promise { return undefined; } + async function foo3(): Promise { - function bar() { - - } + function bar() {} return bar(); } " @@ -345,12 +322,14 @@ function test1() { async function foo() { return 42; } + async function bar() { var a = await foo(); var b: number = a; var c: string = a; } } + function test2() { async function voidoid1() { console.log(\"HEY\"); @@ -358,16 +337,19 @@ function test2() { var voidoid2: () => Promise = voidoid1; var voidoid3: () => void = voidoid1; } + function test3() { async function voidoid4(): Promise { console.log(\"HEY\"); } } + function test4() { async function voidoid5(): void { console.log(\"HEY\"); } } + function test5() { async function voidoid6(): Promise { console.log(\"HEY\"); @@ -427,9 +409,11 @@ async function baz() { async function foo() { return 42; } + async function bar() { return foo(); } + async function baz() { var a = await bar(); var b: number = a; @@ -467,6 +451,7 @@ var y = { await }; async function f() { await 1; } + async function ft(a: T) { await 1; } @@ -509,6 +494,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 f2f9d49a..014a53e8 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -33,20 +33,26 @@ async function* delegate_next() { async function* inner() { var x: void = yield; } + yield* inner(); } + delegate_next().next(0); + async function* delegate_yield() { async function* inner() { yield 0; } + yield* inner(); } + async () => { for await (const x of delegate_yield()) { (x: void); } }; + async function* delegate_return() { async function* inner() { return 0; @@ -86,6 +92,7 @@ async function f() { // error: string ~> void interface File { readLine(): Promise; close(): void; EOF: boolean } declare function fileOpen(path: string): Promise; + async function* readLines(path) { let file: File = await fileOpen(path); try { @@ -96,6 +103,7 @@ async function* readLines(path) { file.close(); } } + async function f() { for await (const line of readLines(\"/path/to/file\")) { (line: void); @@ -135,11 +143,13 @@ refuse_return().return(\"string\").then(result => { // yielding or returning internally. // error: number | void ~> string declare var gen: AsyncGenerator; + gen.return(0).then( result => { (result.value: void); } ); + async function* refuse_return() { try { yield 1; @@ -147,6 +157,7 @@ async function* refuse_return() { return 0; } } + refuse_return().return(\"string\").then( result => { if (result.done) { @@ -200,6 +211,7 @@ async function* catch_return() { return e; } } + async () => { catch_return().throw(\"\").then( ({ value }) => { @@ -209,6 +221,7 @@ async () => { } ); }; + async function* yield_return() { try { yield 0; @@ -217,6 +230,7 @@ async function* yield_return() { yield e; } } + async () => { yield_return().throw(\"\").then( ({ value }) => { diff --git a/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap b/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap index c39735c8..c78433ce 100644 --- a/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap +++ b/tests/autocomplete/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,7 @@ declare var mergeInto: $Facebookism$MergeInto; declare var mixin: $Facebookism$Mixin; declare var objectGetPrototypeOf: Object$GetPrototypeOf; declare var objectAssign: Object$Assign; + m; " `; diff --git a/tests/binary/__snapshots__/jsfmt.spec.js.snap b/tests/binary/__snapshots__/jsfmt.spec.js.snap index 419e0de1..44033c7e 100644 --- a/tests/binary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binary/__snapshots__/jsfmt.spec.js.snap @@ -78,45 +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 [ ]; + \"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 [ ]; + + [] in {}; + + false in []; }, function() { - if (\"foo\" in 123) { - - } - if (!\"foo\" in {}) { - - } - if (!(\"foo\" in {})) { - - } + 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 f66ac434..2c9fa916 100644 --- a/tests/binding/__snapshots__/jsfmt.spec.js.snap +++ b/tests/binding/__snapshots__/jsfmt.spec.js.snap @@ -33,23 +33,38 @@ for (const { baz } of bazzes) { // error: string ~> number // error: string ~> number const x = 0; + x++; + x--; + x += 0; + x -= 0; + x /= 0; + x %= 0; + x <<= 0; + x >>= 0; + x >>>= 0; + 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) { (baz: number); } @@ -311,128 +326,153 @@ function type_type() { type A = number; type A = number; } + function type_class() { type A = number; class A {} } + function type_let() { type A = number; let A = 0; } + function type_const() { type A = number; const A = 0; } + function type_var() { type A = number; var A = 0; } + function type_reassign() { type A = number; + A = 42; } + function class_type() { class A {} type A = number; } + function class_class() { class A {} class A {} } + function class_let() { class A {} let A = 0; } + function class_const() { class A {} const A = 0; } + function class_var() { class A {} var A = 0; } + function let_type() { let A = 0; type A = number; } + function let_class() { let A = 0; class A {} } + function let_let() { let A = 0; let A = 0; } + function let_const() { let A = 0; const A = 0; } + function let_var() { let A = 0; var A = 0; } + function const_type() { const A = 0; type A = number; } + function const_class() { const A = 0; class A {} } + function const_let() { const A = 0; let A = 0; } + function const_const() { const A = 0; const A = 0; } + function const_var() { const A = 0; var A = 0; } + function const_reassign() { const A = 0; + A = 42; } + function var_type() { var A = 0; type A = number; } + function var_class() { var A = 0; class A {} } + function var_let() { var A = 0; let A = 0; } + function var_const() { var A = 0; const A = 0; } + function var_var() { var A = 0; var A = 0; } + function function_toplevel() { - function a() { - - } - function a() { - - } + function a() {} + + function a() {} } + function function_block() { { - function a() { - - } - function a() { - - } + function a() {} + + function a() {} } } + function var_shadow_nested_scope() { { let x = 0; @@ -441,6 +481,7 @@ function var_shadow_nested_scope() { } } } + function type_shadow_nested_scope() { { let x = 0; @@ -449,9 +490,9 @@ function type_shadow_nested_scope() { } } } -function fn_params_name_clash(x, x) { - -} + +function fn_params_name_clash(x, x) {} + function fn_params_clash_fn_binding(x, y) { let x = 0; var y = 0; @@ -605,6 +646,7 @@ function block_scope() { var b = \"\"; } } + function switch_scope(x: string) { let a: number = 0; var b: number = 0; @@ -618,9 +660,11 @@ function switch_scope(x: string) { break; } } + function switch_scope2(x: number) { switch (x) { case 0: + a = \"\"; break; case 1: @@ -630,14 +674,17 @@ function switch_scope2(x: number) { let a = \"\"; break; case 3: + a = \"\"; break; case 4: var c: string = a; break; } + a = \"\"; } + function try_scope() { let a: number = 0; try { @@ -648,53 +695,63 @@ function try_scope() { let a = \"\"; } } + function for_scope_let() { let a: number = 0; - for (let a = \"\"; ; ) { - - } + + for (let a = \"\"; ; ) + {} } + function for_scope_var() { var a: number = 0; - for (var a = \"\"; ; ) { - - } + + for (var a = \"\"; ; ) + {} } + function for_in_scope_let(o: Object) { let a: number = 0; - for (let a in o) { - - } + + for (let a in o) + {} } + function for_in_scope_var(o: Object) { var a: number = 0; - for (var a in o) { - - } + + for (var a in o) + {} } + function for_of_scope_let(xs: string[]) { let a: number = 0; - for (let a of xs) { - - } + + for (let a of xs) + {} } + function for_of_scope_var(xs: string[]) { var a: number = 0; - for (var a of xs) { - - } + + for (var a of xs) + {} } + function default_param_1() { function f(x: () => string = f): number { return 0; } } + 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; @@ -849,19 +906,23 @@ f(a); // ok, a: number (not ?number) // ok, a: number (not ?number) type T1 = T2; type T2 = number; + function f0() { var v = x * c; let x = 0; const c = 0; } + function f1(b) { x = 10; let x = 0; + if (b) { y = 10; let y = 0; } } + function f2() { { var v = x * c; @@ -869,19 +930,23 @@ function f2() { let x = 0; const c = 0; } + function f3() { var s: string = foo(); { var n: number = foo(); + function foo() { return 0; } } var s2: string = foo(); + function foo() { return \"\"; } } + function f4() { function g() { return x + c; @@ -889,10 +954,12 @@ function f4() { let x = 0; const c = 0; } + function f5() { function g() { return x; } + g(); let x = 0; const c = 0; @@ -902,11 +969,15 @@ var y = new C(); class C {} var z: C = new C(); var a: number; + function f(n: number) { return n; } + f(a); + a = 10; + f(a); " `; diff --git a/tests/bom/__snapshots__/jsfmt.spec.js.snap b/tests/bom/__snapshots__/jsfmt.spec.js.snap index c677fadc..42d33ea1 100644 --- a/tests/bom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bom/__snapshots__/jsfmt.spec.js.snap @@ -125,69 +125,97 @@ for (let [x, y]: [number, number] of a.entries()) {} // incorrect // incorrect // incorrect const a: FormData = new FormData(); + 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\"); 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\"); + a.getAll(23); + a.set(\"foo\", \"bar\"); + a.set(\"foo\", {}); + a.set(2, \"bar\"); + a.set(\"foo\", \"bar\", \"baz\"); -a.set(\"bar\", new File([ ], \"q\")); -a.set(\"bar\", new File([ ], \"q\"), \"x\"); -a.set(\"bar\", new File([ ], \"q\"), 2); + +a.set(\"bar\", new File([], \"q\")); + +a.set(\"bar\", new File([], \"q\"), \"x\"); + +a.set(\"bar\", new File([], \"q\"), 2); + a.set(\"bar\", new Blob()); + a.set(\"bar\", new Blob(), \"x\"); + a.set(\"bar\", new Blob(), 2); + a.append(\"foo\", \"bar\"); + a.append(\"foo\", {}); + a.append(2, \"bar\"); + a.append(\"foo\", \"bar\", \"baz\"); + a.append(\"foo\", \"bar\"); -a.append(\"bar\", new File([ ], \"q\")); -a.append(\"bar\", new File([ ], \"q\"), \"x\"); -a.append(\"bar\", new File([ ], \"q\"), 2); + +a.append(\"bar\", new File([], \"q\")); + +a.append(\"bar\", new File([], \"q\"), \"x\"); + +a.append(\"bar\", new File([], \"q\"), 2); + a.append(\"bar\", new Blob()); + a.append(\"bar\", new Blob(), \"x\"); + a.append(\"bar\", new Blob(), 2); + a.delete(\"xx\"); + a.delete(3); -for (let x: string of a.keys()) { - -} -for (let x: number of a.keys()) { - -} -for (let x: string | File of a.values()) { - -} -for (let x: string | File | Blob of a.values()) { - -} -for (let [ x, y ]: [string, string | File] of a.entries()) { - -} -for (let [ x, y ]: [string, string | File | Blob] of a.entries()) { - -} -for (let [ x, y ]: [number, string] of a.entries()) { - -} -for (let [ x, y ]: [string, number] of a.entries()) { - -} -for (let [ x, y ]: [number, number] of a.entries()) { - -} + +for (let x: string of a.keys()) + {} + +for (let x: number of a.keys()) + {} + +for (let x: string | File of a.values()) + {} + +for (let x: string | File | Blob of a.values()) + {} + +for (let [ x, y ]: [string, string | File] of a.entries()) + {} + +for (let [ x, y ]: [string, string | File | Blob] of a.entries()) + {} + +for (let [ x, y ]: [number, string] of a.entries()) + {} + +for (let [ x, y ]: [string, number] of a.entries()) + {} + +for (let [ x, y ]: [number, number] of a.entries()) + {} " `; @@ -249,29 +277,36 @@ function callback( return; } const o: MutationObserver = new MutationObserver(callback); + new MutationObserver((arr: Array) => true); -new MutationObserver( - () => { - - } -); + +new MutationObserver(() => {}); + new MutationObserver(); + new MutationObserver(42); -new MutationObserver( - (n: number) => { - - } -); + +new MutationObserver((n: number) => {}); const div = document.createElement(\"div\"); + o.observe(div, { attributes: true, attributeFilter: [ \"style\" ] }); + o.observe(div, { characterData: true, invalid: true }); + o.observe(); + o.observe(\"invalid\"); + o.observe(div); + o.observe(div, {}); + o.observe(div, { subtree: true }); + o.observe(div, { attributes: true, attributeFilter: true }); + o.takeRecords(); + o.disconnect(); " `; diff --git a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap index a918790e..0739497c 100644 --- a/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/bounded_poly/__snapshots__/jsfmt.spec.js.snap @@ -4,10 +4,10 @@ foo(0, \"\"); function bar(x:X, y:Y): number { return y*0; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function foo(x: X, y: Y): void { - -} +function foo(x: X, y: Y): void {} + foo(0, \"\"); + function bar(x: X, y: Y): number { return y * 0; } @@ -66,6 +66,7 @@ class C { return x; } } + function example(o: T): T { o.x = 0; return o; diff --git a/tests/break/__snapshots__/jsfmt.spec.js.snap b/tests/break/__snapshots__/jsfmt.spec.js.snap index 2822ad3a..39604d62 100644 --- a/tests/break/__snapshots__/jsfmt.spec.js.snap +++ b/tests/break/__snapshots__/jsfmt.spec.js.snap @@ -93,13 +93,16 @@ function foo(b) { } var w: number = z; } + 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; @@ -108,14 +111,17 @@ function bar(b) { } var w: number = x; } + function bar2(b) { var x = (b ? null : false); + if (x == null) return; switch (\"\") { case 0: { let y: number = x; + x = \"\"; } case 1: @@ -127,25 +133,32 @@ function bar2(b) { } var w: number = x; } + function qux(b) { var z = 0; while (b) { var y: number = z; + if (b) { z = \"\"; continue; } + z = 0; } var w: number = z; } + 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/builtin_uses/__snapshots__/jsfmt.spec.js.snap b/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap index fead4428..a6ab2556 100644 --- a/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtin_uses/__snapshots__/jsfmt.spec.js.snap @@ -4,7 +4,9 @@ exports[`test test.js 1`] = ` module.exports = o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = Object.freeze({ foo: 0 }); + (o.foo: string); + module.exports = o; " `; @@ -14,6 +16,7 @@ exports[`test test2.js 1`] = ` (o.foo: string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = require(\"./test\"); + (o.foo: string); " `; diff --git a/tests/builtins/__snapshots__/jsfmt.spec.js.snap b/tests/builtins/__snapshots__/jsfmt.spec.js.snap index 06f930fb..e725d4b6 100644 --- a/tests/builtins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/builtins/__snapshots__/jsfmt.spec.js.snap @@ -27,7 +27,8 @@ var b = a.map( } ); var c: string = b[0]; -var array = [ ]; +var array = []; + function f() { array = array.map( function() { @@ -38,6 +39,7 @@ function f() { } var Foo = require(\"./genericfoo\"); var foo = new Foo(); + function g() { var foo1 = foo.map( function() { @@ -45,6 +47,7 @@ function g() { } ); var x: number = foo1.get(); + foo = foo1; } " @@ -69,13 +72,12 @@ class Foo { map(callbackfn: () => U): Foo { return new Foo(); } - set(x: T): void { - - } + set(x: T): void {} get(): T { return this.x; } } + module.exports = Foo; " `; diff --git a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap index e7380765..e9048a5c 100644 --- a/tests/call_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/call_properties/__snapshots__/jsfmt.spec.js.snap @@ -39,18 +39,23 @@ function f(): number { function a(f: { (): string }, g: { (x: number): string }): string { return f() + g(123); } + function b(f: { (): string }): number { return f(); } + function c(f: { (x: number): number }): number { return f(\"hello\"); } + function d(f: { (x: number): number }): number { return f(); } + function e(f: {}): number { return f(); } + function f(): number { var x = {}; return x(); @@ -101,15 +106,11 @@ var c: { (x: string): string } = function(x: number): string { var d: { (): string } = function(x: number): string { return \"hi\"; }; -var e: { (x: any): void } = function() { - -}; +var e: { (x: any): void } = function() {}; var f: { (): mixed } = function(): string { return \"hi\"; }; -var g: { (x: string): void } = function(x: mixed) { - -}; +var g: { (x: string): void } = function(x: mixed) {}; var y: {} = function(x: number): string { return \"hi\"; }; @@ -166,21 +167,27 @@ function g(x: {}): Function { function a(x: { (z: number): string }): (z: number) => string { return x; } + function b(x: { (z: number): string }): (z: number) => number { return x; } + function c(x: { (z: number): string }): (z: string) => string { return x; } + function d(x: { (z: number): string }): () => string { return x; } + function e(x: {}): () => string { return x; } + function f(x: { (z: number): string }): Function { return x; } + function g(x: {}): Function { return x; } @@ -225,9 +232,11 @@ var b: { (): string; (x: number): string } = function(x?: number): string { var c: { (): string; (x: number): string } = function(x: number): string { return \"hi\"; }; + function d(x: { (): string; (x: number): string }): () => string { return x; } + function e(x: { (): string; (x: number): string }): () => number { return x; } @@ -249,15 +258,10 @@ var c : { myProp: number } = f; // Expecting properties that don\'t exist should be an error // Expecting properties that do exist should be fine // Expecting properties in the functions statics should be fine -var a: { someProp: number } = function() { - -}; -var b: { apply: Function } = function() { - -}; -var f = function() { - -}; +var a: { someProp: number } = function() {}; +var b: { apply: Function } = function() {}; +var f = function() {}; + f.myProp = 123; var c: { myProp: number } = f; " @@ -299,9 +303,7 @@ var a: { (x: number): string } = x => x.toString(); var b: { (x: number): number } = x => \"hi\"; var c: { (x: string): string } = x => x.toFixed(); var d: { (): string } = x => \"hi\"; -var e: { (x: any): void } = () => { - -}; +var e: { (x: any): void } = () => {}; var f: { (): mixed } = () => \"hi\"; var g: { (x: Date): void } = x => { x * 2; diff --git a/tests/callable/__snapshots__/jsfmt.spec.js.snap b/tests/callable/__snapshots__/jsfmt.spec.js.snap index 3dce571a..51a757bb 100644 --- a/tests/callable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/callable/__snapshots__/jsfmt.spec.js.snap @@ -11,9 +11,11 @@ function f(x) { (f: F); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ type F = { (x: string): number; p?: string }; + function f(x) { return x.length; } + (f: F); " `; @@ -47,19 +49,24 @@ callable.call(null, 0); // error, number ~> string // error, number ~> string // error, number ~> string var x = Boolean(4); -function foo(fn: (value: any) => boolean) { - -} + +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; + callable(0); + callable.call(null, 0); " `; diff --git a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap index b495141d..50285692 100644 --- a/tests/class_statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_statics/__snapshots__/jsfmt.spec.js.snap @@ -77,28 +77,27 @@ module.exports = { class A { static x: number; static y: string; - static foo(x: number) { - - } - static bar(y: string) { - - } + static foo(x: number) {} + static bar(y: string) {} } -A.qux = function(x: string) { - -}; + +A.qux = function(x: string) {}; class B extends A { static x: string; - static foo(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 { @@ -110,9 +109,7 @@ class B extends A { } class C { static x: X; - static bar(x: X) { - - } + static bar(x: X) {} static create(): C<*> { return new this(); } @@ -120,11 +117,14 @@ class C { class D extends C { static main() { D.foo(0); + D.bar(0); } } var d: C<*> = D.create(); + (new A(): typeof A); + (B: typeof A); class E { static x: number; @@ -133,6 +133,7 @@ class E { return this.x; } } + module.exports = { A: A, B: B, C: C, D: D, E: E }; " `; diff --git a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap index 960c0bc4..0f0d790d 100644 --- a/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_subtyping/__snapshots__/jsfmt.spec.js.snap @@ -8,6 +8,7 @@ module.exports = { A, B }; /* @flow */ class A {} class B {} + module.exports = { A, B }; " `; @@ -65,16 +66,17 @@ foo(new D, { f_: 0 }); class C { x: X; } -function foo(c: C, x: X) { - -} + +function foo(c: C, x: X) {} type O = { f: number }; + foo((new C(): C), { f_: 0 }); class D extends C { bar() { this.x; } } + foo(new D(), { f_: 0 }); " `; diff --git a/tests/class_type/__snapshots__/jsfmt.spec.js.snap b/tests/class_type/__snapshots__/jsfmt.spec.js.snap index 2b60ee25..82b645d8 100644 --- a/tests/class_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/class_type/__snapshots__/jsfmt.spec.js.snap @@ -14,14 +14,14 @@ function bar(x: Class): B { // OK // error (too few args) class A {} + function foo(x: Class): A { return new x(); } class B { - constructor(_: any) { - - } + constructor(_: any) {} } + function bar(x: Class): B { return new x(); } @@ -51,10 +51,15 @@ declare function check(cls: $Type, inst: X): void; class A {} class B extends A {} class C {} + check(B, new A()); + check(A, new B()); + check(C, new A()); + check(C, new B()); + check(B, new C()); " `; diff --git a/tests/classes/__snapshots__/jsfmt.spec.js.snap b/tests/classes/__snapshots__/jsfmt.spec.js.snap index b13f487e..c1393bd2 100644 --- a/tests/classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/classes/__snapshots__/jsfmt.spec.js.snap @@ -6,10 +6,9 @@ exports[`test A.js 1`] = ` module.exports = A; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class A { - foo(x: number): void { - - } + foo(x: number): void {} } + module.exports = A; " `; @@ -28,7 +27,9 @@ module.exports = B; var A = require(\"./A\"); class B extends A {} let b = new B(); + (b.foo: number); + module.exports = B; " `; @@ -48,12 +49,12 @@ module.exports = C; // error, number !~> function var B = require(\"./B\"); class C extends B { - foo(x: string): void { - - } + foo(x: string): void {} } let c = new C(); + (c.foo: number); + module.exports = C; " `; @@ -65,6 +66,7 @@ new E().x ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class D {} class E {} + new E().x; " `; @@ -126,12 +128,18 @@ class TestClass { c: ?string; } var x = new TestClass(); + x.a; + x.b; + x.c; + x.d; var y: Foo = x; + y.b; + y.d; class Test2Superclass { a: number; @@ -249,10 +257,14 @@ declare var o: {p:number}; class C { static p: string; } + 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 98c43ce8..07178866 100644 --- a/tests/closure/__snapshots__/jsfmt.spec.js.snap +++ b/tests/closure/__snapshots__/jsfmt.spec.js.snap @@ -104,63 +104,79 @@ function local_meth() { // ok // error // shouldn\'t pollute linear refinement -function takes_string(_: string) { - -} +function takes_string(_: string) {} var global_x = \"hello\"; -function global_f() { - -} + +function global_f() {} + function global_g() { global_x = 42; } + global_f(); + takes_string(global_x); + global_g(); + takes_string(global_x); + global_x = 42; + function local_func() { var local_x = \"hello\"; - function local_f() { - - } + + 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() { - - }, + f: function() {}, g: function() { global_y = 42; } }; + global_o.f(); + takes_string(global_y); + global_o.g(); + takes_string(global_y); + global_y = 42; + function local_meth() { var local_y = \"hello\"; var local_o = { - f: function() { - - }, + f: function() {}, g: function() { local_y = 42; } }; + local_o.f(); + takes_string(local_y); + local_o.g(); + takes_string(local_y); + local_y = 42; } " @@ -188,9 +204,11 @@ 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(); } @@ -263,26 +281,30 @@ call_me(); // error // error // in a galaxy far far away -var call_me: () => void = () => { - -}; +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; @@ -299,6 +321,7 @@ function h(x: number | string | boolean) { }; } var var_x = x; + if (typeof var_x == \"number\") { call_me = () => { var y: number = var_x; @@ -315,6 +338,7 @@ function h(x: number | string | boolean) { }; } } + call_me(); " `; diff --git a/tests/commonjs/__snapshots__/jsfmt.spec.js.snap b/tests/commonjs/__snapshots__/jsfmt.spec.js.snap index 4f261d58..671e7cb5 100644 --- a/tests/commonjs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/commonjs/__snapshots__/jsfmt.spec.js.snap @@ -4,9 +4,8 @@ function f(x:string) { } module.exports = f; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function f(x: string) { - -} +function f(x: string) {} + module.exports = f; " `; @@ -18,6 +17,7 @@ var f = require(\'./Abs\'); f(0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var f = require(\"./Abs\"); + f(0); " `; diff --git a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap index ce1cfa12..615127ba 100644 --- a/tests/computed_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/computed_props/__snapshots__/jsfmt.spec.js.snap @@ -32,8 +32,11 @@ var ColorIdToNumber = { [ColorId.GREEN]: ColorNumber.GREEN, [ColorId.BLUE]: ColorNumber.BLUE }; + (ColorIdToNumber[ColorId.RED]: \"ffffff\"); + ColorIdToNumber.XXX; + module.exports = { ColorId, ColorNumber }; " `; @@ -57,7 +60,9 @@ var ColorIdToNumber = { [ColorId.GREEN]: ColorNumber.GREEN, [ColorId.BLUE]: ColorNumber.BLUE }; + (ColorIdToNumber[ColorId.GREEN]: \"ffffff\"); + module.exports = ColorIdToNumber; " `; @@ -71,6 +76,7 @@ var ColorIdToNumber = require(\'./test2\'); // oops var { ColorId } = require(\"./test\"); var ColorIdToNumber = require(\"./test2\"); + (ColorIdToNumber[ColorId.BLUE]: \"ffffff\"); " `; @@ -93,6 +99,7 @@ module.exports = { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var hello = require(\"./test4\"); var dummy = require(\"./test\"); + module.exports = { ...dummy, [hello]: \"world\", ...dummy }; " `; @@ -103,6 +110,7 @@ exports[`test test6.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // oops var o = require(\"./test5\"); + (o.hello: \"nothing\"); " `; diff --git a/tests/conditional/__snapshots__/jsfmt.spec.js.snap b/tests/conditional/__snapshots__/jsfmt.spec.js.snap index d3249de9..ac15d5a5 100644 --- a/tests/conditional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/conditional/__snapshots__/jsfmt.spec.js.snap @@ -32,15 +32,18 @@ function a(): number { var x: ?string = null; return (x ? 1 : 0); } + function b(): number { var x: ?number = null; return (x != null ? x : 0); } + function c(): number { var x = false; var temp = (x ? 1 : x); return (temp ? temp : 0); } + function d(): string { var x: ?number = null; return (x != null ? x : x != null); diff --git a/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap b/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap index 67a13971..1fba561f 100644 --- a/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_all_weak/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ exports[`test no_at_flow.js 1`] = ` x.length; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; + x.length; " `; diff --git a/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap b/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap index f0084118..9c34a8d4 100644 --- a/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_file_extensions/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,7 @@ function foo(x) { var a: number = \"asdf\"; return x * 10; } + foo(\"Hello, world!\"); " `; diff --git a/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap b/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap index bcd8db5a..7ddc509b 100644 --- a/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_module_system_node_resolve_dirname/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,9 @@ import {name} from \"testproj\"; // @flow // Error: Resolve from node_modules first! import { name } from \"testproj\"; + (name: \"node_modules/testproj\"); + (name: \"custom_resolve_dir/testproj\"); " `; diff --git a/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap b/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap index 6787dbb7..62c262d8 100644 --- a/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_module_system_node_resolve_dirname/subdir/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,9 @@ import {name} from \"testproj2\"; // @flow // Error: Resolve from sibling \'custom_resolve_dir\' first! import { name } from \"testproj2\"; + (name: \"node_modules/testproj2\"); + (name: \"subdir/custom_resolve_dir/testproj2\"); " `; diff --git a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap index 6476b1b3..0a1f59cb 100644 --- a/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores/__snapshots__/jsfmt.spec.js.snap @@ -48,12 +48,14 @@ class A { return \"some string\"; } } + A._sProperty = 48; class B extends A { _property1: string; static _sProperty: string; constructor() { super(); + this._property1 = \"another string\"; } _method1(): string { @@ -63,6 +65,7 @@ class B extends A { return 23; } } + B._sProperty = \"B._sProperty string\"; " `; @@ -80,6 +83,7 @@ module.exports = new C; class C { _p: string; } + module.exports = new C(); " `; diff --git a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap index 69d00c9c..21652ccc 100644 --- a/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/config_munging_underscores2/__snapshots__/jsfmt.spec.js.snap @@ -48,12 +48,14 @@ class A { return \"some string\"; } } + A._sProperty = 48; class B extends A { _property1: string; static _sProperty: string; constructor() { super(); + this._property1 = \"another string\"; } _method1(): string { @@ -63,6 +65,7 @@ class B extends A { return 23; } } + B._sProperty = \"B._sProperty string\"; " `; diff --git a/tests/const_params/__snapshots__/jsfmt.spec.js.snap b/tests/const_params/__snapshots__/jsfmt.spec.js.snap index 24fef60f..036e585a 100644 --- a/tests/const_params/__snapshots__/jsfmt.spec.js.snap +++ b/tests/const_params/__snapshots__/jsfmt.spec.js.snap @@ -52,6 +52,7 @@ function durable_refi(x: ?number) { function cannot_reassign(x: string) { x = \"hey\"; } + function durable_refi(x: ?number) { if (x) { return () => { diff --git a/tests/constructor/__snapshots__/jsfmt.spec.js.snap b/tests/constructor/__snapshots__/jsfmt.spec.js.snap index f178daac..21cf3452 100644 --- a/tests/constructor/__snapshots__/jsfmt.spec.js.snap +++ b/tests/constructor/__snapshots__/jsfmt.spec.js.snap @@ -10,15 +10,12 @@ class D { module.exports = C; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C { - constructor() { - - } + constructor() {} } class D { - constructor(): number { - - } + constructor(): number {} } + module.exports = C; " `; diff --git a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap index 8b20712f..6603a0e4 100644 --- a/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap +++ b/tests/constructor_annots/__snapshots__/jsfmt.spec.js.snap @@ -32,12 +32,15 @@ exports.Foo2 = (Foo: Class); function Foo() { this.x = 0; } + Foo.y = 0; + Foo.prototype = { m() { return 0; } }; + exports.Foo = Foo; interface IFooPrototype { m(): number } interface IFoo extends IFooPrototype { @@ -45,6 +48,7 @@ interface IFoo extends IFooPrototype { x: boolean; static y: boolean } + exports.Foo2 = (Foo: Class); " `; diff --git a/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap b/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap index 19942181..0e94999f 100644 --- a/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap +++ b/tests/contents/ignore/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ xxx ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./dummy\"); var xxx = 0; + xxx; " `; diff --git a/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap b/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap index 19942181..0e94999f 100644 --- a/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/contents/no_flow/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ xxx ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./dummy\"); var xxx = 0; + xxx; " `; diff --git a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap index 7b43343f..0a245301 100644 --- a/tests/core_tests/__snapshots__/jsfmt.spec.js.snap +++ b/tests/core_tests/__snapshots__/jsfmt.spec.js.snap @@ -51,18 +51,27 @@ 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() { @@ -70,12 +79,19 @@ let tests = [ }, function() { Boolean(); + Boolean(0); + Boolean(-0); + Boolean(null); + Boolean(false); + Boolean(NaN); + Boolean(undefined); + Boolean(\"\"); } ]; @@ -145,6 +161,7 @@ let tests = [ }, function(x: Map) { (x.get(\"foo\"): boolean); + x.get(123); } ]; @@ -195,22 +212,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\"); } ]; @@ -261,23 +289,34 @@ let ws5 = new WeakSet(numbers()); // error, must be objects let ws = new WeakSet(); let obj: Object = {}; let dict: { foo: string } = { foo: \"bar\" }; + ws.add(window); + ws.add(obj); + ws.add(dict); + ws.has(window); + ws.has(obj); + ws.has(dict); + ws.delete(window); + ws.delete(obj); + ws.delete(dict); let ws2 = new WeakSet([ obj, dict ]); let ws3 = new WeakSet([ 1, 2, 3 ]); + function* generator(): Iterable<{ foo: string }> { while (true) { yield { foo: \"bar\" }; } } let ws4 = new WeakSet(generator()); + function* numbers(): Iterable { let i = 0; while (true) { diff --git a/tests/covariance/__snapshots__/jsfmt.spec.js.snap b/tests/covariance/__snapshots__/jsfmt.spec.js.snap index 64e1dc5b..c241a615 100644 --- a/tests/covariance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/covariance/__snapshots__/jsfmt.spec.js.snap @@ -87,8 +87,9 @@ n.x = [0]; */ type CovArrayVerbose = Array; -var b: CovArrayVerbose = [ ]; +var b: CovArrayVerbose = []; var y: CovArrayVerbose = b; + y[0] = \"\"; class NVerbose { x: CovArrayVerbose; @@ -97,8 +98,11 @@ class NVerbose { } } var nv: NVerbose = new NVerbose(); + nv.x = [ 0 ]; + (nv.x[0]: string); + (nv.foo()[0]: string); " `; diff --git a/tests/coverage/__snapshots__/jsfmt.spec.js.snap b/tests/coverage/__snapshots__/jsfmt.spec.js.snap index dbd0e831..9ec8e4b3 100644 --- a/tests/coverage/__snapshots__/jsfmt.spec.js.snap +++ b/tests/coverage/__snapshots__/jsfmt.spec.js.snap @@ -15,12 +15,8 @@ declare module bar { // that we implicitly assume in type-at-pos and coverage implementations. In // particular, when unchecked it causes a crash with coverage --color. // TODO -declare module foo { - -} -declare module bar { - -} +declare module foo {} +declare module bar {} " `; @@ -31,9 +27,7 @@ declare module foo { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // check coverage of declare module -declare module foo { - -} +declare module foo {} " `; @@ -42,6 +36,7 @@ exports[`test no_pragma.js 1`] = ` (x: string); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ let x = 0; + (x: string); " `; @@ -66,12 +61,8 @@ declare class qux { // that we implicitly assume in type-at-pos and coverage implementations. In // particular, when unchecked it causes non-termination with coverage --color. // TODO -declare module foo { - -} -declare module bar { - -} +declare module foo {} +declare module bar {} declare class qux {} " `; diff --git a/tests/cycle/__snapshots__/jsfmt.spec.js.snap b/tests/cycle/__snapshots__/jsfmt.spec.js.snap index f652eb51..bd0d5c48 100644 --- a/tests/cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/cycle/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ module.exports = A; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var B = require(\"./B\"); class A extends B {} + module.exports = A; " `; @@ -20,6 +21,7 @@ module.exports = B; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //class B extends A { } var A = require(\"./A\"); + module.exports = B; " `; diff --git a/tests/date/__snapshots__/jsfmt.spec.js.snap b/tests/date/__snapshots__/jsfmt.spec.js.snap index e4ac978b..9421de8c 100644 --- a/tests/date/__snapshots__/jsfmt.spec.js.snap +++ b/tests/date/__snapshots__/jsfmt.spec.js.snap @@ -34,23 +34,41 @@ new Date(2015, 6, 18, 11, 55, 42, 999, \'hahaha\'); var d = new Date(0); var x: string = d.getTime(); var y: number = d; + new Date(); + new Date(1234567890); + new Date(\"2015/06/18\"); + new Date(2015, 6); + new Date(2015, 6, 18); + new Date(2015, 6, 18, 11); + new Date(2015, 6, 18, 11, 55); + new Date(2015, 6, 18, 11, 55, 42); + new Date(2015, 6, 18, 11, 55, 42, 999); + new Date({}); + new Date(2015, \"6\"); + new Date(2015, 6, \"18\"); + new Date(2015, 6, 18, \"11\"); + new Date(2015, 6, 18, 11, \"55\"); + new Date(2015, 6, 18, 11, 55, \"42\"); + new Date(2015, 6, 18, 11, 55, 42, \"999\"); + new Date(\"2015\", 6); + new Date(2015, 6, 18, 11, 55, 42, 999, \"hahaha\"); " `; diff --git a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap index 284cf97a..3eaee5bc 100644 --- a/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_haste/__snapshots__/jsfmt.spec.js.snap @@ -68,10 +68,13 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ 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_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap index 43a7dfa3..39dd1e86 100644 --- a/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap @@ -20,8 +20,11 @@ var docblock = require(\"qux/docblock\"); var min = require(\"d3/min.js\"); var corge = require(\"qux/corge\"); var unreachable = require(\"annotation\"); + (docblock.fun(): string); + (min.fun(): string); + (corge.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 0a3ea919..552fd2b1 100644 --- a/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/__snapshots__/jsfmt.spec.js.snap @@ -25,6 +25,7 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} + module.exports.fun = (): Implementation => new Implementation(); " `; @@ -43,6 +44,7 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} + module.exports.fun = (): Implementation => new Implementation(); " `; @@ -61,6 +63,7 @@ module.exports.fun = (): Implementation => new Implementation; * @flow */ class Implementation {} + module.exports.fun = (): Implementation => new Implementation(); " `; @@ -90,10 +93,13 @@ var ExplicitDifferentName = require(\'ExplicitProvidesModuleDifferentName\'); // Error: Either Implementation ~> boolean or Declaration ~> boolean // Error: Either Implementation ~> boolean or Declaration ~> boolean 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_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap index 02bbf30a..6556366e 100644 --- a/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/external/_d3/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test min.js 1`] = ` module.exports.fun = (): Implementation => new Implementation; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Implementation {} + module.exports.fun = (): Implementation => new Implementation(); " `; diff --git a/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap index 1642bb7e..1a9f2a6e 100644 --- a/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_haste/foo/bar/__snapshots__/jsfmt.spec.js.snap @@ -16,8 +16,11 @@ var corge = require(\'qux/corge\'); var docblock = require(\"qux/docblock\"); var min = require(\"d3/min.js\"); var corge = require(\"qux/corge\"); + (docblock.fun(): boolean); + (min.fun(): boolean); + (corge.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 4ad8d746..a468d3d0 100644 --- a/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_incremental_node/__snapshots__/jsfmt.spec.js.snap @@ -70,28 +70,40 @@ var F = require(\'package_with_dir_main\'); // Error either Implementation ~> boolean or Declaration ~> boolean // Error either Implementation ~> boolean or Declaration ~> 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); 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); " `; @@ -103,6 +115,7 @@ exports[`test test_relative.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Error: either Implementation ~> boolean or Definition ~> boolean import { foo } from \"./A\"; + (foo(): boolean); " `; diff --git a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap index 777cf1f1..6d7aa63e 100644 --- a/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declaration_files_node/__snapshots__/jsfmt.spec.js.snap @@ -50,16 +50,22 @@ var F = require(\'package_with_dir_main\'); // Error number ~> string // Error number ~> string 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); " `; @@ -86,11 +92,15 @@ var CJS = require(\'./CJS.js\'); // Error number ~> string // Error: string ~> number var A1 = require(\"./A\"); + (A1.fun(): string); var A2 = require(\"./A.js\"); + (A2.fun(): string); var CJS = require(\"./CJS.js\"); + (CJS: string); + (CJS: number); " `; diff --git a/tests/declare_class/__snapshots__/jsfmt.spec.js.snap b/tests/declare_class/__snapshots__/jsfmt.spec.js.snap index 25f33b6c..558e1048 100644 --- a/tests/declare_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_class/__snapshots__/jsfmt.spec.js.snap @@ -12,9 +12,13 @@ C.foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, it\'s a string declare class C { static x: number; static foo(x: number): void } + C.x = \"\"; + C.foo(\"\"); + (C.name: string); + (C.name: number); " `; diff --git a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap index b110d7cc..03c17847 100644 --- a/tests/declare_export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_export/__snapshots__/jsfmt.spec.js.snap @@ -64,6 +64,7 @@ class Test extends Base { return 2; } } + module.exports = Test; " `; @@ -113,9 +114,13 @@ exports.numberValue5 = 5; * @flow */ exports.numberValue1 = 1; + exports.numberValue2 = 2; + exports.numberValue3 = 3; + exports.numberValue4 = 4; + exports.numberValue5 = 5; " `; @@ -488,9 +493,13 @@ exports.stringValue = \"str\"; * @flow */ exports.numberValue1 = 42; + exports.numberValue2 = 42; + exports.numberValue3 = 42; + exports.numberValue4 = 42; + exports.stringValue = \"str\"; " `; @@ -981,23 +990,28 @@ var d2: string = numVal1; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; 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\"; import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\"; 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(); 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(); @@ -1012,6 +1026,7 @@ var k2: string = numVal3; import * as CJS_Named from \"CommonJS_Named\"; 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; @@ -1062,6 +1077,7 @@ var ab2: string = numberValue2_renamed; import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\"; 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(); diff --git a/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap b/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap index b43e39d7..f9611c54 100644 --- a/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_fun/__snapshots__/jsfmt.spec.js.snap @@ -13,8 +13,11 @@ declare function foo(x: X): X; declare function foo(x: number): string; declare function foo(x: string): number; declare function foo(x: X): X; + (foo(0): string); + (foo(\"hello\"): number); + (foo(false): void); " `; diff --git a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap index 8bb999e6..b74156ce 100644 --- a/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_module_exports/__snapshots__/jsfmt.spec.js.snap @@ -36,17 +36,25 @@ import declare_m_e_with_declare_var_e from \"declare_m_e_with_declare_var_e\"; // Error: number ~> string // Error: number ~> string 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); + (declare_m_e_with_declare_var_e: string); " `; diff --git a/tests/declare_type/__snapshots__/jsfmt.spec.js.snap b/tests/declare_type/__snapshots__/jsfmt.spec.js.snap index 299932ee..8fee2746 100644 --- a/tests/declare_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/declare_type/__snapshots__/jsfmt.spec.js.snap @@ -54,9 +54,13 @@ import type { toz } from \"ModuleAliasFoo\"; var k4: toz = foo(k1); import blah from \"foo\"; import type { Foo, Bar, Id } from \"foo\"; + blah(0, 0); + ({ toz: 3 }: Foo); + (3: Bar); + (\"lol\": Id); " `; diff --git a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap index e2983148..ff4b3943 100644 --- a/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/def_site_variance/__snapshots__/jsfmt.spec.js.snap @@ -55,8 +55,10 @@ class Variance<+Out, -In> { } class A {} class B extends A {} + function subtyping(v1: Variance, v2: Variance) { (v1: Variance); + (v2: Variance); } class PropVariance<+Out, -In> { diff --git a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap index eaf0b237..c053c77b 100644 --- a/tests/demo/1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/1/__snapshots__/jsfmt.spec.js.snap @@ -14,6 +14,7 @@ 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 d62a8fbb..bb139e95 100644 --- a/tests/demo/2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/demo/2/__snapshots__/jsfmt.spec.js.snap @@ -33,11 +33,14 @@ class A { return callback(this.getX()); } } + function callback(x: string) { return x.length; } var a = new A(42); + a.onLoad(callback); + module.exports = A; " `; diff --git a/tests/deps/__snapshots__/jsfmt.spec.js.snap b/tests/deps/__snapshots__/jsfmt.spec.js.snap index 70f5644e..42e4f837 100644 --- a/tests/deps/__snapshots__/jsfmt.spec.js.snap +++ b/tests/deps/__snapshots__/jsfmt.spec.js.snap @@ -19,8 +19,11 @@ require(\'./F\'); require(\'./G\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ require(\"./D\"); + require(\"./E\"); + require(\"./F\"); + require(\"./G\"); " `; diff --git a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap index dcba7329..58122218 100644 --- a/tests/destructuring/__snapshots__/jsfmt.spec.js.snap +++ b/tests/destructuring/__snapshots__/jsfmt.spec.js.snap @@ -23,9 +23,13 @@ let [ a, ...ys ] = xs; let [ b, ...zs ] = ys; let c = zs[0]; let d = zs[1]; + (a: void); + (b: void); + (c: void); + (d: void); let [ ...e ] = 0; " @@ -46,11 +50,14 @@ var { [\"key\"]: val3, ...spread } = { key: \"val\" }; // ok (gasp!) by existing StrT -> ElemT rule // error (gasp!) in general we don\'t know if a computed prop should be excluded from spread 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); " `; @@ -183,64 +190,75 @@ function default_expr_scope({a, b = a}) {} function obj_prop_fun({ p: { q = 0 } = { q: true } } = { p: { q: \"\" } }) { (q: void); } + obj_prop_fun(); + obj_prop_fun({}); + obj_prop_fun({ p: {} }); + obj_prop_fun({ p: { q: null } }); + function obj_prop_var(o = { p: { q: \"\" } }) { var { p: { q = 0 } = { q: true } } = o; + (q: void); } + obj_prop_var(); + obj_prop_var({}); + obj_prop_var({ p: {} }); + obj_prop_var({ p: { q: null } }); + function obj_rest( { p: { q, ...o } = { q: 0, r: 0 } } = { p: { q: 0, r: \"\" } } ) { (o.r: void); } + obj_rest(); + obj_rest({}); + obj_rest({ p: {} }); + 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); -function obj_prop_err({ x: { y } } = null) { - -} -function obj_rest_err({ ...o } = 0) { - -} -function arr_elem_err([ x ] = null) { - -} -function arr_rest_err([ ...a ] = null) { - -} + +function obj_prop_err({ x: { y } } = null) {} + +function obj_rest_err({ ...o } = 0) {} + +function arr_elem_err([ x ] = null) {} + +function arr_rest_err([ ...a ] = null) {} + function gen(x: T, { p = x }: { p: T }): T { return p; } + obj_prop_fun(({}: { p?: { q?: null } })); + obj_prop_var(({}: { p?: { q?: null } })); -function obj_prop_opt({ p }: { p?: string } = { p: 0 }) { - -} -function obj_prop_maybe({ p }: { p: ?string } = { p: 0 }) { - -} -function obj_prop_union({ p }: { p: number | string } = { p: true }) { - -} -function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) { - -} -function default_expr_scope({ a, b = a }) { - -} + +function obj_prop_opt({ p }: { p?: string } = { p: 0 }) {} + +function obj_prop_maybe({ p }: { p: ?string } = { p: 0 }) {} + +function obj_prop_union({ p }: { p: number | string } = { p: true }) {} + +function obj_prop_union2({ p }: { p: number } | { p: string } = { p: true }) {} + +function default_expr_scope({ a, b = a }) {} " `; @@ -328,44 +346,60 @@ var cp2_err: string = others.childprop2; // Error: number ~> string declare var a: string; 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 }); + [ obj.x ] = [ \"foo\" ]; + function foo({ p, z: [ r ] }) { a = p; + b = z; + c = r; } + foo({ p: 0, z: [ 1, 2 ] }); + [ a, , b, ...c ] = [ 0, 1, true, 3 ]; + function bar({ x, ...z }) { var o: { x: string; y: number } = z; } + bar({ x: \"\", y: 0 }); var spread = { y: \"\" }; var extend: { x: number; y: string; z: boolean } = { x: 0, ...spread }; -function qux(_: { a: number }) { - -} + +function qux(_: { a: number }) {} + qux({ a: \"\" }); -function corge({ b }: { b: string }) { - -} + +function corge({ b }: { b: string }) {} + corge({ b: 0 }); var { n }: { n: number } = { n: \"\" }; + function test() { var { foo } = { bar: 123 }; var { bar, baz } = { bar: 123 }; } + 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; @@ -420,6 +454,7 @@ exports[`test eager.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, property \`x\` can not be accessed on \`null\` var x; + ({ x } = null); " `; @@ -471,44 +506,39 @@ function arr_rest_pattern([ _, ...a ] : ArrRest) { // a: [X] // o: { x: X } // a: [X] // a: [X] -function obj_pattern({ prop }: { prop: X }) { - -} +function obj_pattern({ prop }: { prop: X }) {} type Prop = { prop: X }; -function obj_pattern2({ prop }: Prop) { - -} -function arr_pattern([ elem ]: X[]) { - -} + +function obj_pattern2({ prop }: Prop) {} + +function arr_pattern([ elem ]: X[]) {} type Elem = X[]; -function arr_pattern2([ elem ]: Elem) { - -} -function tup_pattern([ proj ]: [X]) { - -} + +function arr_pattern2([ elem ]: Elem) {} + +function tup_pattern([ proj ]: [X]) {} type Proj = [X]; -function tup_pattern2([ proj ]: Proj) { - -} -function rest_antipattern(...t: T) { - -} -function rest_pattern(...r: X[]) { - -} + +function tup_pattern2([ proj ]: Proj) {} + +function rest_antipattern(...t: T) {} + +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) { o.x; } + function arr_rest_pattern([ _, ...a ]: [any, X]) { a[0]; } type ArrRest = [any, X]; + function arr_rest_pattern([ _, ...a ]: ArrRest) { a[0]; } @@ -546,6 +576,7 @@ const bar = (i: number) => { [ i ] = foo(i); return [ i ]; }; + foo = (i: number) => { return bar(i); }; @@ -564,8 +595,10 @@ var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; // error: string ~> void // ok var { \"key\": val } = { key: \"val\" }; + (val: void); var { \"with-dash\": with_dash } = { \"with-dash\": \"motivating example\" }; + (with_dash: \"motivating example\"); " `; @@ -583,6 +616,7 @@ function bar() { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var { x } = { x: { foo: \"foo\" } }; + function bar() { x.bar; } diff --git a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap index 55b42a91..97598de5 100644 --- a/tests/dictionary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dictionary/__snapshots__/jsfmt.spec.js.snap @@ -40,6 +40,7 @@ function foo0(x: Array<{ [key: string]: mixed }>): Array<{ x[0].fooBar = \"foobar\"; return x; } + function foo2(x: { [key: string]: number }): { [key: string]: number; +toString: () => string @@ -503,35 +504,51 @@ class B extends A {} class C extends B {} class X {} class Y {} + function set_prop_to_string_key(o: { [k: string]: any }) { o.prop = \"ok\"; } + 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); } + function add_prop_to_nonstring_key_dot(o: { [k: number]: any }) { o.prop = \"err\"; } + function add_prop_to_nonstring_key_bracket(o: { [k: number]: any }) { o[0] = \"ok\"; } + 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; } + function object_prototype(o: { [k: string]: number }): { [k: string]: number; +toString: () => string @@ -539,132 +556,171 @@ function object_prototype(o: { [k: string]: number }): { (o.toString(): boolean); return o; } + function unsound_string_conversion_alias_declared_prop( o: { [k: number]: any; \"0\": X } ) { o[0] = \"not-x\"; } + 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); } + function subtype_dict_values_fresh_exception() { let a: { [k: string]: A } = { a: new A(), b: new B(), c: new C() }; let b: { [k: string]: B } = { a: new A(), b: new B(), c: new C() }; let c: { [k: string]: C } = { a: new A(), b: new B(), c: new C() }; } + function unification_dict_keys_invariant(x: Array<{ [k: B]: any }>) { let a: Array<{ [k: A]: any }> = x; let b: Array<{ [k: B]: any }> = x; let c: Array<{ [k: C]: any }> = x; } + function subtype_dict_keys_invariant(x: { [k: B]: any }) { let a: { [k: A]: any } = x; let b: { [k: B]: any } = x; let c: { [k: C]: any } = x; } + 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); } + function unification_mix_with_declared_props_invariant_r( xa: Array<{ [k: string]: A; p: B }>, xb: Array<{ [k: string]: B; p: B }>, 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); } + function subtype_mix_with_declared_props_invariant_r( xa: { [k: string]: A; p: B }, xb: { [k: string]: B; p: B }, 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); } + function unification_dict_to_obj(x: Array<{ [k: string]: X }>): Array<{ p: X }> { return x; } + function unification_obj_to_dict(x: Array<{ p: X }>): Array<{ [k: string]: X }> { return x; } + 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); } + function subtype_obj_to_mixed(x: { p: B; x: X }) { let a: { [k: string]: A; x: X } = x; let b: { [k: string]: B; x: X } = x; let c: { [k: string]: C; x: X } = x; } + function unification_dict_to_mixed(x: Array<{ [k: string]: B }>) { let a: Array<{ [k: string]: B; p: A }> = x; let b: Array<{ [k: string]: B; p: B }> = x; let c: Array<{ [k: string]: B; p: C }> = x; } + function subtype_dict_to_mixed(x: { [k: string]: B }) { let a: { [k: string]: B; p: A } = x; let b: { [k: string]: B; p: B } = x; let c: { [k: string]: B; p: C } = x; } + function subtype_dict_to_optional_a(x: { [k: string]: B }) { let a: { p?: A } = x; } + function subtype_dict_to_optional_b(x: { [k: string]: B }) { let b: { p?: B } = x; } + function subtype_dict_to_optional_c(x: { [k: string]: B }) { let c: { p?: C } = x; } + function subtype_optional_a_to_dict(x: { p?: A }): { [k: string]: B } { return x; } + function subtype_optional_b_to_dict(x: { p?: B }): { [k: string]: B } { return x; } + function subtype_optional_c_to_dict(x: { p?: C }): { [k: string]: B } { return x; } @@ -750,17 +806,20 @@ var z: { [key: number]: string } = x; var a: { [key: string]: ?string } = {}; var b: { [key: string]: string } = a; var c: { [key: string]: ?string } = b; + function foo0(x: Array<{ [key: string]: number }>): Array<{ [key: string]: string }> { return x; } + function foo1(x: Array<{ [key: string]: number }>): Array<{ [key: string]: number; fooBar: string }> { return x; } + function foo2(x: Array<{ [key: string]: mixed }>): Array<{ [key: string]: mixed; fooBar: string @@ -768,26 +827,33 @@ function foo2(x: Array<{ [key: string]: mixed }>): Array<{ x[0].fooBar = 123; return x; } + function foo3(x: { [key: string]: number }): { foo: number } { return x; } + function foo4(x: { [key: string]: number }): { [key: string]: number; foo: string } { return x; } + function foo5(x: Array<{ [key: string]: number }>): Array<{ foo: number }> { return x; } + function foo6(x: Array<{ foo: number }>): Array<{ [key: string]: number }> { return x; } + function foo7(x: { [key: string]: number; bar: string }) { (x.bar: string); } + function foo8(x: { [key: string]: number }) { (x.foo: string); + (x.foo: number); } " @@ -866,6 +932,7 @@ var o: { foo: QueryFunction } = { return params.count; } }; + module.exports = o; " `; @@ -879,6 +946,7 @@ o.foo = function (params) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, number ~/~ string var o = require(\"./test\"); + o.foo = function(params) { return params.count; }; diff --git a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap index 84a5806f..422389c1 100644 --- a/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/disjoint-union-perf/__snapshots__/jsfmt.spec.js.snap @@ -213,6 +213,7 @@ export function emitExpression(node: TypedNode) : t.Expression { import * as t from \"./jsAst\"; const b = t.builders; import type { TypedNode } from \"./ast\"; + function getBinaryOp( op: \"plus\" | \"minus\" | \"divide\" | \"multiply\" ): \"+\" | \"-\" | \"*\" | \"/\" { diff --git a/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap b/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap index 205f3c27..72a3f339 100644 --- a/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/docblock_flow/__snapshots__/jsfmt.spec.js.snap @@ -102,6 +102,7 @@ exports[`test use_strict_with_flow.js 1`] = ` /* @flow */ // error \"use strict\"; + (\"\": void); " `; diff --git a/tests/dom/__snapshots__/jsfmt.spec.js.snap b/tests/dom/__snapshots__/jsfmt.spec.js.snap index f62e8cbb..0b1180a5 100644 --- a/tests/dom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dom/__snapshots__/jsfmt.spec.js.snap @@ -44,6 +44,7 @@ let tests = [ let tests = [ function(document: Document) { const event = document.createEvent(\"CustomEvent\"); + event.initCustomEvent(\"butts\", true, false, { nice: 42 }); } ]; @@ -68,8 +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); } ]; @@ -102,13 +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); } ]; @@ -161,13 +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); } ]; @@ -195,9 +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\"); } ]; @@ -298,18 +322,20 @@ let tests = [ // detachEvent // invalid, may be undefined // valid -let listener: EventListener = function(event: Event): void { - -}; +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() { @@ -342,8 +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); } ]; @@ -424,30 +453,16 @@ let tests = [ prototype: Object.create( HTMLElement.prototype, { - createdCallback: { - value: function createdCallback() { - - } - }, - attachedCallback: { - value: function attachedCallback() { - - } - }, - detachedCallback: { - value: function detachedCallback() { - - } - }, + createdCallback: { value: function createdCallback() {} }, + attachedCallback: { value: function attachedCallback() {} }, + detachedCallback: { value: function detachedCallback() {} }, attributeChangedCallback: { value: function attributeChangedCallback( attributeLocalName, oldAttributeValue, newAttributeValue, attributeNamespace - ) { - - } + ) {} } } ) @@ -461,21 +476,13 @@ let tests = [ prototype: Object.assign( Object.create(HTMLElement.prototype), { - createdCallback() { - - }, - attachedCallback() { - - }, - detachedCallback() { - - }, + createdCallback() {}, + attachedCallback() {}, + detachedCallback() {}, attributeChangedCallback(attributeLocalName, oldAttributeValue, newAttributeValue, - attributeNamespace) { - - } + attributeNamespace) {} } ) } @@ -489,9 +496,7 @@ let tests = [ attributeChangedCallback(localName: string, oldVal: string, newVal: string, - namespace: string) { - - } + namespace: string) {} } } ); @@ -732,10 +737,12 @@ let tests = [ }, function() { document.createNodeIterator(document.body); + document.createNodeIterator({}); }, function() { document.createTreeWalker(document.body); + document.createTreeWalker({}); }, function() { @@ -897,17 +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() { @@ -916,13 +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 089688f9..572f4fc2 100644 --- a/tests/dump-types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/dump-types/__snapshots__/jsfmt.spec.js.snap @@ -7,10 +7,11 @@ module.exports = num; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var num = 42; -function bar() { - -} + +function bar() {} + bar(); + module.exports = num; " `; @@ -41,24 +42,29 @@ const idxResult = idx(obj, obj => obj.a.b.c.d); // @flow // test deduping of inferred types var num = require(\"./import\"); -function foo(x) { - -} + +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) { return nullToUndefined(x); } + function f1(x: ?Object) { return nullToUndefined(x); } + function f2(x: ?string) { return nullToUndefined(x); } + function f3(x: ?string) { return nullToUndefined(x); } diff --git a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap index 4277458c..824f0064 100644 --- a/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap +++ b/tests/duplicate_methods/__snapshots__/jsfmt.spec.js.snap @@ -36,52 +36,41 @@ class C5 { new C5().m = new C5().m - 42; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C1 { - m() { - - } - m() { - - } + m() {} + m() {} } + new C1().m(); class C2 { get m() { return 42; } - m() { - - } + m() {} } + new C2().m(); class C3 { - set m(x) { - - } - m() { - - } + set m(x) {} + m() {} } + new C3().m(); class C4 { get m() { return 42; } - set m(x: number) { - - } + set m(x: number) {} } + new C4().m = new C4().m - 42; class C5 { - m() { - - } + m() {} get m() { return 42; } - set m(x: number) { - - } + set m(x: number) {} } + new C5().m = new C5().m - 42; " `; diff --git a/tests/encaps/__snapshots__/jsfmt.spec.js.snap b/tests/encaps/__snapshots__/jsfmt.spec.js.snap index 425186a3..2af69fbe 100644 --- a/tests/encaps/__snapshots__/jsfmt.spec.js.snap +++ b/tests/encaps/__snapshots__/jsfmt.spec.js.snap @@ -23,15 +23,18 @@ var s3 = tag2 \`la la la\`; class A {} var a = new A(); var s1 = \`l\${a.x}r\`; + 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 182ea2b4..5eccbf4b 100644 --- a/tests/enumerror/__snapshots__/jsfmt.spec.js.snap +++ b/tests/enumerror/__snapshots__/jsfmt.spec.js.snap @@ -34,17 +34,22 @@ function isActive( ): boolean { return ad.state === \"ACTIVE\"; } + isActive({ state: \"PAUSE\" }); var MyStates = { PAUSED: \"PAUSED\", ACTIVE: \"ACTIVE\", DELETED: \"DELETED\" }; + function isActive2(ad: { state: $Keys }): boolean { return ad.state === MyStates.ACTIVE; } + isActive2({ state: \"PAUSE\" }); type Keys = $Keys<{ x: any; y: any }>; type Union = \"x\" | \"y\"; + function keys2union(s: Keys): Union { return s; } + function union2keys(s: Union): Keys { return s; } diff --git a/tests/equals/__snapshots__/jsfmt.spec.js.snap b/tests/equals/__snapshots__/jsfmt.spec.js.snap index 8830a42a..a5cde890 100644 --- a/tests/equals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/equals/__snapshots__/jsfmt.spec.js.snap @@ -16,13 +16,20 @@ var x = (null : ?number); // error // error 1 == 1; + \"foo\" == \"bar\"; + 1 == null; + null == 1; + 1 == \"\"; + \"\" == 1; var x = (null: ?number); + x == 1; + 1 == x; " `; diff --git a/tests/error_messages/__snapshots__/jsfmt.spec.js.snap b/tests/error_messages/__snapshots__/jsfmt.spec.js.snap index a2250ec3..a50af65d 100644 --- a/tests/error_messages/__snapshots__/jsfmt.spec.js.snap +++ b/tests/error_messages/__snapshots__/jsfmt.spec.js.snap @@ -1,8 +1,7 @@ exports[`test errors.js 1`] = ` "if (typeof define === \'function\' && define.amd) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -if (typeof define === \"function\" && define.amd) { - -} +if (typeof define === \"function\" && define.amd) + {} " `; diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap index 403fc131..6a23fea2 100644 --- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap @@ -64,6 +64,7 @@ class Test extends Base { return 2; } } + module.exports = Test; " `; @@ -131,9 +132,13 @@ exports.numberValue5 = 5; * @flow */ exports.numberValue1 = 1; + exports.numberValue2 = 2; + exports.numberValue3 = 3; + exports.numberValue4 = 4; + exports.numberValue5 = 5; " `; @@ -239,6 +244,7 @@ export default class Foo { return 42; } } + new Foo(); " `; @@ -582,9 +588,13 @@ exports.stringValue = \"str\"; * @flow */ exports.numberValue1 = 42; + exports.numberValue2 = 42; + exports.numberValue3 = 42; + exports.numberValue4 = 42; + exports.stringValue = \"str\"; " `; @@ -1090,23 +1100,28 @@ var d2: string = numVal1; import CJS_Clobb_Lit from \"CommonJS_Clobbering_Lit\"; 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\"; import { staticNumber1, baseProp, childProp } from \"CommonJS_Clobbering_Class\"; 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(); 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(); @@ -1121,6 +1136,7 @@ var k2: string = numVal3; import * as CJS_Named from \"CommonJS_Named\"; 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; @@ -1180,6 +1196,7 @@ var ab2: string = numberValue2_renamed; import { numberValue1 as numberValue5 } from \"ES6_ExportAllFrom_Intermediary1\"; 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(); @@ -1333,27 +1350,40 @@ function testRequires() { // CommonJS module that clobbers module.exports with a frozen object // Error: frozen 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 ce91e694..6c18783e 100644 --- a/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es_declare_module/__snapshots__/jsfmt.spec.js.snap @@ -58,35 +58,55 @@ import {exports as nope} from \"ES\"; // Error: Not an export // Error: Not an export import { num1, str1 } from \"CJS_Named\"; import CJS_Named from \"CJS_Named\"; + (num1: number); + (num1: string); + (str1: string); + (str1: number); + (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\"; + (new C(): C); + (42: C); + (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 2ca98135..8509e6a7 100644 --- a/tests/export_default/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_default/__snapshots__/jsfmt.spec.js.snap @@ -18,10 +18,13 @@ N.z = Q(N.z); // declaration of Q redirects to module M 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/export_type/__snapshots__/jsfmt.spec.js.snap b/tests/export_type/__snapshots__/jsfmt.spec.js.snap index 3b639fa9..d2f4b424 100644 --- a/tests/export_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_type/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,7 @@ module.exports = {} /* @flow */ export type talias4 = number; export interface IFoo { prop: number } + module.exports = {}; " `; diff --git a/tests/extensions/__snapshots__/jsfmt.spec.js.snap b/tests/extensions/__snapshots__/jsfmt.spec.js.snap index 524d171e..74ca1755 100644 --- a/tests/extensions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/extensions/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` imp(1337); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var imp = require(\"./bar\"); + imp(1337); " `; diff --git a/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap b/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap index 8b22529f..7259d28d 100644 --- a/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebook_fbt_none/__snapshots__/jsfmt.spec.js.snap @@ -7,7 +7,9 @@ var React = require(\'react\'); // @flow // Error: ReactElement ~> number var React = require(\"react\"); + (: React.Element<*>); + (: number); " `; diff --git a/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap b/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap index 01fa23f9..6986e7b2 100644 --- a/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebook_fbt_some/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ exports[`test main.js 1`] = ` // @flow // Error (the libdef in this test marks fbt as number) (: number); + (: string); " `; diff --git a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap index 59729c9d..a9e945a1 100644 --- a/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap +++ b/tests/facebookisms/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test Bar.js 1`] = ` module.exports = Bar; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var Bar = { x: 0 }; + module.exports = Bar; " `; @@ -62,7 +63,9 @@ let tests = [ }, function(copyProperties: Object$Assign) { let result = {}; + result.baz = false; + (copyProperties(result, { foo: \"a\" }, { bar: 123 }): { foo: string; bar: number; @@ -73,16 +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) { - - } + function x(cb: Function) {} + x(copyProperties); } ]; @@ -110,11 +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); } ]; @@ -195,22 +202,25 @@ 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) { mergeInto(); }, function(mergeInto: $Facebookism$MergeInto) { - function x(cb: Function) { - - } + function x(cb: Function) {} + x(mergeInto); } ]; @@ -233,6 +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 ba33da5e..c32c6e63 100644 --- a/tests/fetch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fetch/__snapshots__/jsfmt.spec.js.snap @@ -98,26 +98,31 @@ const b = new Headers([ \"Content-Type\", \"image/jpeg\" ]); const c = new Headers({ \"Content-Type\", \"image/jpeg\" }); const d = new Headers(c); const e: Headers = new Headers(); + e.append(\"Content-Type\", \"image/jpeg\"); + e.append(\"Content-Type\"); + e.append({ \"Content-Type\", \"image/jpeg\" }); + 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\"); + for (let v of e) { const [ i, j ]: [string, string] = v; } + for (let v of e.entries()) { const [ i, j ]: [string, string] = v; } -e.getAll(\"content-type\").forEach( - (v: string) => { - - } -); + +e.getAll(\"content-type\").forEach((v: string) => {}); " `; @@ -235,9 +240,13 @@ const k: Request = new Request( } ); var l: boolean = h.bodyUsed; + h.text().then((t: string) => t); + h.text().then((t: Buffer) => t); + h.arrayBuffer().then((ab: ArrayBuffer) => ab); + h.arrayBuffer().then((ab: Buffer) => ab); " `; @@ -327,9 +336,13 @@ const i: Response = new Response({ }); const ok: boolean = h.ok; const status: number = h.status; + h.text().then((t: string) => t); + h.text().then((t: Buffer) => t); + h.arrayBuffer().then((ab: ArrayBuffer) => ab); + h.arrayBuffer().then((ab: Buffer) => ab); " `; @@ -387,25 +400,30 @@ const b = new URLSearchParams([ \"key1\", \"value1\" ]); const c = new URLSearchParams({ \"key1\", \"value1\" }); const d = new URLSearchParams(c); const e: URLSearchParams = new URLSearchParams(); + e.append(\"key1\", \"value1\"); + e.append(\"key1\"); + e.append({ \"key1\", \"value1\" }); + 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\"); + for (let v of e) { const [ i, j ]: [string, string] = v; } + for (let v of e.entries()) { const [ i, j ]: [string, string] = v; } -e.getAll(\"key1\").forEach( - (v: string) => { - - } -); + +e.getAll(\"key1\").forEach((v: string) => {}); " `; diff --git a/tests/find-module/__snapshots__/jsfmt.spec.js.snap b/tests/find-module/__snapshots__/jsfmt.spec.js.snap index 3a5cd026..697b1ef8 100644 --- a/tests/find-module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/find-module/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,7 @@ exports[`test test.js 1`] = ` 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 ce3d432b..0e02c629 100644 --- a/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/fixpoint/__snapshots__/jsfmt.spec.js.snap @@ -34,12 +34,15 @@ module.exports = {fn: fix}; function eq(x: number, y: number) { return true; } + function sub(x: number, y: number) { return 0; } + function mul(x: number, y: number) { return 0; } + function fix(fold) { var delta = function(delta) { return fold( @@ -51,6 +54,7 @@ function fix(fold) { }; return delta(delta); } + function mk_factorial() { return fix( function(factorial) { @@ -64,7 +68,9 @@ function mk_factorial() { ); } var factorial = mk_factorial(); + factorial(\"...\"); + module.exports = { fn: fix }; " `; @@ -97,22 +103,28 @@ function Y(f) { function g(x) { return f(x(x)); } + g(g); } + function func1(f) { function fix_f(x: number): number { return f(x); } return fix_f; } + function func2(f) { function fix_f(x: string): string { return f(x); } return fix_f; } + Y(func1); + Y(func2); + module.exports = Y; " `; diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 71d3dcdd..074fab5f 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -50,45 +50,59 @@ 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\"); } + function bliffl(x: boolean) { var max = 10; loop1: -for (var ii = 0; ii < max; ii++) { + for (var ii = 0; ii < max; ii++) { loop2: -for (var jj = 0; jj < max; jj++) { + 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\"); } " @@ -140,42 +154,53 @@ 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\"); } + function bar(x: boolean) { for (var prop in {}) { return; } + console.log(\"this is still reachable\"); } + function baz(x: boolean) { for (var prop in {}) { continue; } + console.log(\"this is still reachable\"); } + function bliffl(x: boolean) { var obj = { a: 1, b: 2 }; loop1: -for (var prop1 in obj) { + for (var prop1 in obj) { loop2: -for (var prop2 in obj) { + for (var prop2 in obj) { break loop1; } + console.log(\"this is still reachable\"); } + console.log(\"this is still reachable\"); } + function corge(x: boolean) { for (var prop in {}) { break; } + console.log(\"this is still reachable\"); } " @@ -227,42 +252,53 @@ 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\"); } + function bar(x: boolean) { - for (var elem of [ ]) { + for (var elem of []) { return; } + console.log(\"this is still reachable\"); } + function baz(x: boolean) { - for (var elem of [ ]) { + for (var elem of []) { continue; } + console.log(\"this is still reachable\"); } + function bliffl(x: boolean) { var arr = [ 1, 2, 3 ]; loop1: -for (var elem of arr) { + for (var elem of arr) { loop2: -for (var elem of arr) { + for (var elem of arr) { break loop1; } + console.log(\"this is still reachable\"); } + console.log(\"this is still reachable\"); } + function corge(x: boolean) { - for (var elem of [ ]) { + 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 0652bf64..66b73fce 100644 --- a/tests/forof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/forof/__snapshots__/jsfmt.spec.js.snap @@ -69,38 +69,47 @@ function testArray(arr: Array): void { (x: string); } } + function testIterable1(iterable: Iterable): void { for (var x of iterable) { (x: string); } } + function testIterable2(iterable: Iterable<*>): void { for (var x of iterable) { (x: string); } } + function testString(str: string): void { for (var x of str) { (x: number); } } + function testMap1(map: Map): void { for (var elem of map) { (elem: [string, number]); + (elem: number); } } + function testMap2(map: Map<*, *>): void { for (var elem of map) { (elem: [number, string]); + (elem: number); } } + function testSet1(set: Set): void { for (var x of set) { (x: number); } } + function testSet2(set: Set<*>): void { for (var x of set) { (x: number); diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index 46e6c0ed..287d9de5 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -69,24 +69,39 @@ function test2(): number { return 0; } function test(a: string, b: number): number { return this.length; } + test.apply(\"\", [ \"\", 0 ]); + test.apply(0, [ \"\", 0 ]); + test.apply(\"\", [ \"\" ]); + test.apply(\"\", [ \"\", \"\" ]); + test.apply(\"\", [ 0, 0 ]); + function f(args) { test.apply(\"\", args); } + f([ \"\", 0 ]); + f([ \"\", \"\" ]); + f([ 0, 0 ]); + test.apply(\"\", \"not array\"); + (test.call.apply(test, [ 0, 123, \"foo\" ]): void); + (test.bind.apply(test, [ 0, 123 ]): (b: number) => number); + function test2(): number { return 0; } + (test2.apply(): number); + (test2.apply(\"\"): number); " `; @@ -108,7 +123,9 @@ let tests = [ let tests = [ function(x: (a: string, b: string) => void) { let y = x.bind(x, \"foo\"); + y(\"bar\"); + y(123); } ]; @@ -174,22 +191,35 @@ function test2(): number { return 0; } function test(a: string, b: number): number { return this.length; } + test.call(\"\", \"\", 0); + test.call(0, \"\", 0); + test.call(\"\", \"\"); + test.call(\"\", \"\", \"\"); + test.call(\"\", 0, 0); + function f(args) { test.call(\"\", args[0], args[1]); } + f([ \"\", 0 ]); + f([ \"\", \"\" ]); + f([ 0, 0 ]); + (test.apply.call(test, 0, [ 0, \"foo\" ]): number); + function test2(): number { return 0; } + (test2.call(): number); + (test2.call(\"\"): number); " `; @@ -292,17 +322,25 @@ var b: Function = function(a: number, b: number): number { }; class C {} 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(); } + function bad(x: Function, y: Object): void { var a: number = x; var b: string = x; @@ -310,33 +348,45 @@ function bad(x: Function, y: Object): void { } let tests = [ function(y: () => void, z: Function) { - function x() { - - } + 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() { - - } + 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); } ]; var d: Function = () => 1; var e = (d.bind(1): Function)(); + (e: number); + (e: string); " `; @@ -368,12 +418,15 @@ function rest_t>(...xs: T): U { function rest_array(...xs: Array): T { return xs[0]; } + function rest_tuple(...xs: [T]): T { return xs[0]; } + function rest_any(...xs: any): any { return xs[0]; } + function rest_t>(...xs: T): U { return xs[0]; } diff --git a/tests/funrec/__snapshots__/jsfmt.spec.js.snap b/tests/funrec/__snapshots__/jsfmt.spec.js.snap index 575d958b..1399f943 100644 --- a/tests/funrec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/funrec/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,7 @@ function foo() { function bar(x) { return x; } + function foo() { return function bound() { return bar(bound); diff --git a/tests/generators/__snapshots__/jsfmt.spec.js.snap b/tests/generators/__snapshots__/jsfmt.spec.js.snap index cd6b604c..1ae917a6 100644 --- a/tests/generators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generators/__snapshots__/jsfmt.spec.js.snap @@ -151,14 +151,17 @@ 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); } @@ -175,30 +178,35 @@ class GeneratorExamples { } *widen_next() { var x = yield 0; - if (typeof x === \"number\") { - - } else - if (typeof x === \"boolean\") { - - } else { + + if (typeof x === \"number\") + {} +else + if (typeof x === \"boolean\") + {} +else { (x: string); } } *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() { @@ -227,37 +235,47 @@ class GeneratorExamples { } } 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\") { - -} else - if (typeof infer_stmt_next === \"number\") { - - } else { + +if (typeof infer_stmt_next === \"undefined\") + {} +else + if (typeof infer_stmt_next === \"number\") + {} +else { (infer_stmt_next: boolean); } + examples.widen_next().next(0); + examples.widen_next().next(\"\"); + examples.widen_next().next(true); + for (var x of examples.widen_yield()) { - if (typeof x === \"number\") { - - } else - if (typeof x === \"boolean\") { - - } else { + if (typeof x === \"number\") + {} +else + if (typeof x === \"boolean\") + {} +else { (x: string); } } + examples.delegate_next_generator().next(\"\"); + for (var x of examples.delegate_yield_generator()) { (x: number); } -examples.delegate_next_iterable([ ]).next(\"\"); -for (var x of examples.delegate_yield_iterable([ ])) { + +examples.delegate_next_iterable([]).next(\"\"); + +for (var x of examples.delegate_yield_iterable([])) { (x: string); } " @@ -297,16 +315,18 @@ class GeneratorExamples { } } 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\") { - -} else - if (typeof infer_stmt_next === \"number\") { - - } else { + +if (typeof infer_stmt_next === \"undefined\") + {} +else + if (typeof infer_stmt_next === \"number\") + {} +else { (infer_stmt_next: boolean); } " @@ -464,113 +484,147 @@ 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); } } + function* stmt_return_ok(): Generator { return 0; } + function* stmt_return_err(): Generator { return \"\"; } + function* infer_stmt() { var x: boolean = yield 0; return \"\"; } + for (var x of infer_stmt()) { (x: string); } var infer_stmt_next = infer_stmt().next(0).value; -if (typeof infer_stmt_next === \"undefined\") { - -} else - if (typeof infer_stmt_next === \"number\") { - - } else { + +if (typeof infer_stmt_next === \"undefined\") + {} +else + if (typeof infer_stmt_next === \"number\") + {} +else { (infer_stmt_next: boolean); } + function* widen_next() { var x = yield 0; - if (typeof x === \"number\") { - - } else - if (typeof x === \"boolean\") { - - } else { + + if (typeof x === \"number\") + {} +else + if (typeof x === \"boolean\") + {} +else { (x: string); } } + widen_next().next(0); + widen_next().next(\"\"); + widen_next().next(true); + function* widen_yield() { yield 0; + yield \"\"; + yield true; } + for (var x of widen_yield()) { - if (typeof x === \"number\") { - - } else - if (typeof x === \"boolean\") { - - } else { + if (typeof x === \"number\") + {} +else + if (typeof x === \"boolean\") + {} +else { (x: string); } } + function* delegate_next_generator() { function* inner() { var x: number = yield; } + yield* inner(); } + delegate_next_generator().next(\"\"); + function* delegate_yield_generator() { function* inner() { yield \"\"; } + yield* inner(); } + for (var x of delegate_yield_generator()) { (x: number); } + function* delegate_return_generator() { function* inner() { return \"\"; } var x: number = yield* inner(); } + function* delegate_next_iterable(xs: Array) { yield* xs; } -delegate_next_iterable([ ]).next(\"\"); + +delegate_next_iterable([]).next(\"\"); + function* delegate_yield_iterable(xs: Array) { yield* xs; } -for (var x of delegate_yield_iterable([ ])) { + +for (var x of delegate_yield_iterable([])) { (x: string); } + function* delegate_return_iterable(xs: Array) { var x: void = yield* xs; } + function* generic_yield(y: Y): Generator { yield y; } + function* generic_return(r: R): Generator { return r; } + function* generic_next(): Generator { return yield undefined; } + function* multiple_return(b) { if (b) { return 0; @@ -579,6 +633,7 @@ function* multiple_return(b) { } } let multiple_return_result = multiple_return().next(); + if (multiple_return_result.done) { (multiple_return_result.value: void); } @@ -616,8 +671,10 @@ if (refuse_return_result.done) { // error: number | void ~> string function test1(gen: Generator) { var ret = gen.return(0); + (ret.value: void); } + function* refuse_return() { try { yield 1; @@ -627,6 +684,7 @@ function* refuse_return() { } var refuse_return_gen = refuse_return(); var refuse_return_result = refuse_return_gen.return(\"string\"); + if (refuse_return_result.done) { (refuse_return_result.value: string); } @@ -670,9 +728,11 @@ function* catch_return() { } } var catch_return_value = catch_return().throw(\"\").value; + if (catch_return_value !== undefined) { (catch_return_value: string); } + function* yield_return() { try { yield 0; @@ -682,6 +742,7 @@ function* yield_return() { } } var yield_return_value = yield_return().throw(\"\").value; + if (yield_return_value !== undefined) { (yield_return_value: string); } diff --git a/tests/generics/__snapshots__/jsfmt.spec.js.snap b/tests/generics/__snapshots__/jsfmt.spec.js.snap index d9d39010..b62dfa86 100644 --- a/tests/generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/generics/__snapshots__/jsfmt.spec.js.snap @@ -63,6 +63,7 @@ class D { x: T; m(z: S, u: T, v): S { this.x = u; + v.u = u; return z; } @@ -89,6 +90,7 @@ class H extends G> { } } var h1 = new H(); + h1.foo([ \"...\" ]); var h2: F>>> = h1; var obj: Object = {}; diff --git a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap index aec7076c..2be6e37c 100644 --- a/tests/geolocation/__snapshots__/jsfmt.spec.js.snap +++ b/tests/geolocation/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,7 @@ var id = geolocation.watchPosition( } } ); + geolocation.clearWatch(id); " `; diff --git a/tests/get-def/__snapshots__/jsfmt.spec.js.snap b/tests/get-def/__snapshots__/jsfmt.spec.js.snap index 71a3899a..94e8a498 100644 --- a/tests/get-def/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def/__snapshots__/jsfmt.spec.js.snap @@ -19,11 +19,14 @@ lib.bar(); // t123456 // D123456 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); + lib.bar(); " `; @@ -43,11 +46,15 @@ things; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow 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 a8b69d5e..b64d3503 100644 --- a/tests/get-def2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-def2/__snapshots__/jsfmt.spec.js.snap @@ -6,6 +6,7 @@ module.exports = {ParentFoo}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var ParentFoo = { foo: \"bar\" }; + module.exports = { ParentFoo }; " `; @@ -45,14 +46,20 @@ import type {Foo} from \'./types\'; // Follows non-destructured property access of \`require(\'Parent\')\` var Parent = require(\"./Parent\"); 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\"; " @@ -73,9 +80,7 @@ class D extends C { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow class C { - override() { - - } + override() {} } class D extends C { foo() { @@ -84,9 +89,7 @@ class D extends C { bar() { this.override; } - override() { - - } + override() {} } " `; @@ -109,7 +112,9 @@ class C extends React.Component { props: { x: string }; } let msg = \"hello\"; + ; +
; " `; diff --git a/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap b/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap index 2a1fec9b..d74194a8 100644 --- a/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap +++ b/tests/get-imports-and-importers/__snapshots__/jsfmt.spec.js.snap @@ -28,6 +28,7 @@ require(\'b\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow require(\"./a.js\"); + require(\"b\"); " `; 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 b41bd88e..52ef4f0b 100644 --- a/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap +++ b/tests/getters_and_setters_enabled/__snapshots__/jsfmt.spec.js.snap @@ -88,47 +88,42 @@ class Foo { get propWithMatchingGetterAndSetter(): number { return 4; } - set propWithMatchingGetterAndSetter(x: number) { - - } + set propWithMatchingGetterAndSetter(x: number) {} get propWithSubtypingGetterAndSetter(): ?number { return 4; } - set propWithSubtypingGetterAndSetter(x: number) { - - } - set propWithSubtypingGetterAndSetterReordered(x: number) { - - } + set propWithSubtypingGetterAndSetter(x: number) {} + set propWithSubtypingGetterAndSetterReordered(x: number) {} get propWithSubtypingGetterAndSetterReordered(): ?number { return 4; } get propWithMismatchingGetterAndSetter(): number { return 4; } - set propWithMismatchingGetterAndSetter(x: string) { - - } + set propWithMismatchingGetterAndSetter(x: string) {} propOverriddenWithGetter: number; get propOverriddenWithGetter() { return \"hello\"; } propOverriddenWithSetter: number; - set propOverriddenWithSetter(x: string) { - - } + set propOverriddenWithSetter(x: string) {} } var foo = new Foo(); var testGetterNoError1: number = foo.goodGetterNoAnnotation; var testGetterNoError2: number = foo.goodGetterWithAnnotation; var testGetterWithError1: string = foo.goodGetterNoAnnotation; var testGetterWithError2: string = foo.goodGetterWithAnnotation; + foo.goodSetterNoAnnotation = 123; + foo.goodSetterWithAnnotation = 123; + foo.goodSetterNoAnnotation = \"hello\"; + foo.goodSetterWithAnnotation = \"hello\"; var testSubtypingGetterAndSetter: number = foo.propWithSubtypingGetterAndSetter; var testPropOverridenWithGetter: number = foo.propOverriddenWithGetter; + foo.propOverriddenWithSetter = 123; " `; @@ -234,30 +229,20 @@ var obj = { get propWithMatchingGetterAndSetter(): number { return 4; }, - set propWithMatchingGetterAndSetter(x: number) { - - }, + set propWithMatchingGetterAndSetter(x: number) {}, get propWithSubtypingGetterAndSetter(): ?number { return 4; }, - set propWithSubtypingGetterAndSetter(x: number) { - - }, - set propWithSubtypingGetterAndSetterReordered(x: number) { - - }, + set propWithSubtypingGetterAndSetter(x: number) {}, + set propWithSubtypingGetterAndSetterReordered(x: number) {}, get propWithSubtypingGetterAndSetterReordered(): ?number { return 4; }, get exampleOfOrderOfGetterAndSetter(): A { return new A(); }, - set exampleOfOrderOfGetterAndSetter(x: B) { - - }, - set exampleOfOrderOfGetterAndSetterReordered(x: B) { - - }, + set exampleOfOrderOfGetterAndSetter(x: B) {}, + set exampleOfOrderOfGetterAndSetterReordered(x: B) {}, get exampleOfOrderOfGetterAndSetterReordered(): A { return new A(); } @@ -266,11 +251,16 @@ var testGetterNoError1: number = obj.goodGetterNoAnnotation; var testGetterNoError2: number = obj.goodGetterWithAnnotation; var testGetterWithError1: string = obj.goodGetterNoAnnotation; var testGetterWithError2: string = obj.goodGetterWithAnnotation; + obj.goodSetterNoAnnotation = 123; + obj.goodSetterWithAnnotation = 123; + obj.goodSetterNoAnnotation = \"hello\"; + obj.goodSetterWithAnnotation = \"hello\"; var testSubtypingGetterAndSetter: number = obj.propWithSubtypingGetterAndSetter; + obj.exampleOfOrderOfGetterAndSetter = new C(); var testExampleOrOrderOfGetterAndSetterReordered: number = obj.exampleOfOrderOfGetterAndSetterReordered; " @@ -412,50 +402,52 @@ class Base { this.x = value; } } + (class extends Base { get x(): B { return b; } }); + (class extends Base { - set x(value: B): void { - - } + set x(value: B): void {} }); + (class extends Base { get x(): C { return c; } - set x(value: A): void { - - } + set x(value: A): void {} }); + (class extends Base { - set pos(value: B): void { - - } + set pos(value: B): void {} }); + (class extends Base { get pos(): C { return c; } }); + (class extends Base { get neg(): B { return b; } }); + (class extends Base { - set neg(value: A): void { - - } + set neg(value: A): void {} }); + (class extends Base { get: C; }); + (class extends Base { set: A; }); + (class extends Base { getset: B; }); diff --git a/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap b/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap index de3a76b7..a4577d6f 100644 --- a/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ignore_package/__snapshots__/jsfmt.spec.js.snap @@ -22,9 +22,11 @@ module.exports = foo; \'Required module not found\'. */ var _ = require(\"underscore\"); + function foo(): string { return _.foo(); } + module.exports = foo; " `; diff --git a/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap b/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap index c2bc11be..c51f2ab8 100644 --- a/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap +++ b/tests/immutable_methods/__snapshots__/jsfmt.spec.js.snap @@ -21,6 +21,7 @@ class B extends A { } class C extends A {} var a: A = new B(); + a.foo = function(): C { return new C(); }; diff --git a/tests/import_type/__snapshots__/jsfmt.spec.js.snap b/tests/import_type/__snapshots__/jsfmt.spec.js.snap index b43f1483..e68d9b3b 100644 --- a/tests/import_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_type/__snapshots__/jsfmt.spec.js.snap @@ -23,6 +23,7 @@ class ClassFoo3 { return new ClassFoo3(); } } + module.exports = ClassFoo3; " `; @@ -60,15 +61,21 @@ class ClassFoo4 { } } class ClassFoo5 {} + function givesAFoo4(): ClassFoo4 { return new ClassFoo4(); } + function givesAFoo5(): ClassFoo5 { return new ClassFoo5(); } + exports.ClassFoo4 = ClassFoo4; + exports.ClassFoo5 = ClassFoo5; + exports.foo4Inst = new ClassFoo4(); + exports.foo5Inst = new ClassFoo5(); " `; @@ -294,20 +301,24 @@ import type ClassFoo1 from \"./ExportDefault_Class\"; import { foo1Inst } from \"./ExportDefault_Class\"; 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\"; @@ -317,6 +328,7 @@ var e2: number = givesAFoo3Obj(); var e3: typeof AliasFoo3 = givesAFoo3Obj(); import type { numValue } from \"./ExportsANumber\"; import type ClassFoo6 from \"./issue-359\"; + function foo() { ClassFoo6; } diff --git a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap index 3da3d3df..bc7e96aa 100644 --- a/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import_typeof/__snapshots__/jsfmt.spec.js.snap @@ -23,6 +23,7 @@ class ClassFoo3 { return new ClassFoo3(); } } + module.exports = ClassFoo3; " `; @@ -50,6 +51,7 @@ exports.ClassFoo4 = ClassFoo4; * @flow */ class ClassFoo4 {} + exports.ClassFoo4 = ClassFoo4; " `; @@ -330,11 +332,13 @@ import typeof ClassFoo1T from \"./ExportDefault_Class\"; import ClassFoo1 from \"./ExportDefault_Class\"; 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\"; diff --git a/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap index a0eb1b11..8856a065 100644 --- a/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/__snapshots__/jsfmt.spec.js.snap @@ -5,6 +5,7 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a: string = 0; + module.exports = a; " `; @@ -18,6 +19,7 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; + module.exports = b; " `; @@ -31,6 +33,7 @@ module.exports = c; // @flow var b = require(\"./b\"); var c: string = b; + module.exports = c; " `; diff --git a/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap index 11d82fe8..b7674dd7 100644 --- a/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp1/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ module.exports = b; // @flow var a = require(\"./a\"); var b = a; + module.exports = b; " `; diff --git a/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap index 5e716253..8ad3c26a 100644 --- a/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp2/__snapshots__/jsfmt.spec.js.snap @@ -5,6 +5,7 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a = 0; + module.exports = a; " `; diff --git a/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap index b56a5d3b..7dc23dfc 100644 --- a/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_basic/tmp3/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; + module.exports = b; " `; diff --git a/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap index 47f24548..bde85b2e 100644 --- a/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_cycle/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,7 @@ class A { b: number; c: string; } + module.exports = A; " `; @@ -34,6 +35,7 @@ import type C from \"./C\"; class B extends A { c: C; } + module.exports = B; " `; @@ -55,6 +57,7 @@ import type B from \"./B\"; class C extends A { b: B; } + module.exports = C; " `; diff --git a/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap index 741c8d32..c7f9ffdf 100644 --- a/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_cycle/tmp1/__snapshots__/jsfmt.spec.js.snap @@ -29,6 +29,7 @@ import type { B } from \"./B\"; class C extends A { b: B; } + module.exports = C; " `; diff --git a/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap index 85093731..3f9e10d8 100644 --- a/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_delete/__snapshots__/jsfmt.spec.js.snap @@ -5,6 +5,7 @@ module.exports = a; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var a: string = 0; + module.exports = a; " `; @@ -18,6 +19,7 @@ module.exports = b; // @flow var a = require(\"./a\"); var b: number = a; + module.exports = b; " `; @@ -31,6 +33,7 @@ module.exports = c; // @flow var b = require(\"./b\"); var c: string = b; + module.exports = c; " `; diff --git a/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap b/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap index 3d5a61e0..dece80a4 100644 --- a/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap +++ b/tests/incremental_mixed_naming_cycle/__snapshots__/jsfmt.spec.js.snap @@ -14,7 +14,9 @@ module.exports = \'A\'; * @flow */ (require(\"./b\"): void); + (require(\"C\"): void); + module.exports = \"A\"; " `; @@ -35,7 +37,9 @@ module.exports = \'B\'; * @flow */ (require(\"A\"): void); + (require(\"D\"): void); + module.exports = \"B\"; " `; @@ -56,7 +60,9 @@ module.exports = \'C\'; * @flow */ require(\"Root\"); + (require(\"./b\"): void); + module.exports = \"C\"; " `; @@ -76,6 +82,7 @@ module.exports = \'D\'; * @flow */ (require(\"./b\"): void); + module.exports = \"D\"; " `; diff --git a/tests/indexer/__snapshots__/jsfmt.spec.js.snap b/tests/indexer/__snapshots__/jsfmt.spec.js.snap index a47ec802..fd61761e 100644 --- a/tests/indexer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/indexer/__snapshots__/jsfmt.spec.js.snap @@ -50,24 +50,31 @@ function foo7(): {[key: string]: number; foo: number} { function foo0(): {} { return { foo: \"bar\" }; } + function foo1(): { [key: string]: string } { return { foo: \"bar\" }; } + function foo2(): { [key: number]: string } { return { foo: \"bar\" }; } + function foo3(): { [key: string]: number } { return { foo: \"bar\" }; } + function foo4(): { [key: number]: number } { return { foo: \"bar\" }; } + function foo5(): { [key: string]: number; foo: string } { return { foo: \"bar\" }; } + function foo6(): { [key: number]: number; foo: string } { return { foo: \"bar\" }; } + function foo7(): { [key: string]: number; foo: number } { return { foo: \"bar\" }; } diff --git a/tests/init/__snapshots__/jsfmt.spec.js.snap b/tests/init/__snapshots__/jsfmt.spec.js.snap index 5a6dec13..93b9b4ad 100644 --- a/tests/init/__snapshots__/jsfmt.spec.js.snap +++ b/tests/init/__snapshots__/jsfmt.spec.js.snap @@ -58,50 +58,49 @@ function _for_of(arr: Array) { // error, possibly undefined function _if(b: () => boolean) { if (b()) { - var f = function() { - - }; + var f = function() {}; } + f(); } + function _while(b: () => boolean) { while (b()) { - var f = function() { - - }; + var f = function() {}; } + f(); } + function _do_while(b: () => boolean) { do { - var f = function() { - - }; + var f = function() {}; } while (b()); + f(); } + function _for(n: number) { for (var i = 0; i < n; i++) { - var f = function() { - - }; + var f = function() {}; } + f(); } + function _for_in(obj: Object) { for (var p in obj) { - var f = function() { - - }; + var f = function() {}; } + f(); } + function _for_of(arr: Array) { for (var x of arr) { - var f = function() { - - }; + var f = function() {}; } + f(); } " @@ -433,19 +432,23 @@ function for_in_post_init() { // error function linear_deferred_init() { var x: number; + x = 0; var y: number = x; } + function linear_pre_init() { var x: number; var y: number = x; } + function if_scoped_init(b) { if (b) { var x: number = 0; var y: number = x; } } + function if_else_partial_init(b) { if (b) { var x: number = 0; @@ -453,18 +456,22 @@ function if_else_partial_init(b) { var y: number = x; } } + function if_pre_init(b) { var y: number = x; + if (b) { var x: number = 0; } } + function if_partial_post_init(b) { if (b) { var x: number = 0; } var y: number = x; } + function if_post_init(b) { if (b) { var x: number = 0; @@ -473,15 +480,19 @@ function if_post_init(b) { } 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 { @@ -489,32 +500,40 @@ function if_post_init(b) { } var y: number = x; } + 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; } + 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; } + function switch_scoped_init_1(i) { switch (i) { case 0: @@ -522,6 +541,7 @@ function switch_scoped_init_1(i) { var y: number = x; } } + function switch_scoped_init_2(i) { var y: number = x; switch (i) { @@ -529,6 +549,7 @@ function switch_scoped_init_2(i) { var x: number = 0; } } + function switch_scoped_init_3(i) { switch (i) { case 0: @@ -536,6 +557,7 @@ function switch_scoped_init_3(i) { } var y: number = x; } + function switch_scoped_init_4(i) { switch (i) { case 0: @@ -544,90 +566,108 @@ function switch_scoped_init_4(i) { var y: number = x; } } + function while_scoped_init(b) { while (b) { var x: number = 0; var y: number = x; } } + function while_pre_init(b) { var y: number = x; while (b) { var x: number = 0; } } + function while_post_init(b) { while (b) { var x: number = 0; } var y: number = x; } + function do_while_scoped_init(b) { do { var x: number = 0; var y: number = x; } while (b); } + function do_while_pre_init(b) { var y: number = x; do { var x: number = 0; } while (b); } + function do_while_post_init(b) { do { var x: number = 0; } while (b); var y: number = x; } + function for_scoped_init(b) { for (; b; ) { var x: number = 0; var y: number = x; } } + function for_pre_init(b) { var y: number = x; + for (; b; ) { var x: number = 0; } } + function for_post_init(b) { for (; b; ) { var x: number = 0; } var y: number = x; } + function for_in_scoped_init() { for (var p in { a: 1, b: 2 }) { var x: number = 0; var y: number = x; } } + function for_in_pre_init() { var y: number = x; + for (var p in { a: 1, b: 2 }) { var x: number = 0; } } + function for_in_post_init() { for (var p in { a: 1, b: 2 }) { var x: number = 0; } var y: number = x; } + function for_of_scoped_init() { for (var x of [ 1, 2, 3 ]) { var x: number = 0; var y: number = x; } } + function for_in_pre_init() { var y: number = x; + for (var x of [ 1, 2, 3 ]) { var x: number = 0; } } + function for_in_post_init() { for (var x of [ 1, 2, 3 ]) { var x: number = 0; @@ -833,28 +873,36 @@ function sub_closure_init_reference() { // TDZ (...even though this is weird...) function linear_deferred_init() { let x: number; + x = 0; let y: number = x; } + function linear_pre_init() { let x: number; let y: ?number = x; let z: number = x; + x = 0; let w: number = x; } + function self_init() { let x = x; } + 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 { @@ -862,32 +910,40 @@ function if_post_init(b) { } var y: number = x; } + 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; } + 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; } + function switch_scoped_init_2(i) { switch (i) { case 0: @@ -896,6 +952,7 @@ function switch_scoped_init_2(i) { let y: number = x; } } + function while_post_init(b) { let x: number; while (b) { @@ -903,6 +960,7 @@ function while_post_init(b) { } var y: number = x; } + function do_while_post_init(b) { let x: number; do { @@ -910,24 +968,30 @@ function do_while_post_init(b) { } while (b); var y: number = x; } + 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 [ ]) { + + for (var x of []) { x = 0; } var y: number = x; } + function switch_post_init2(i): number { let bar; switch (i) { case 1: + bar = 3; break; default: @@ -935,10 +999,12 @@ function switch_post_init2(i): number { } return bar; } + function switch_post_init2(i): number { let bar; switch (i) { case 1: + bar = 3; break; default: @@ -946,6 +1012,7 @@ function switch_post_init2(i): number { } return bar; } + function sub_closure_init_reference() { let x = function() { return x; diff --git a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap index f17c7de0..60fee403 100644 --- a/tests/instanceof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/instanceof/__snapshots__/jsfmt.spec.js.snap @@ -103,18 +103,23 @@ class X1 { class X2 { foo: string; } + function x(b) { return (b ? new X1() : new X2()); } + function consumer1(b) { var g = x(b); + if (g instanceof X2) g.foo = \"1337\"; else g.foo = 1337; } + function consumer2(b) { var g = x(b); + if (g instanceof X1) g.foo = \"1337\"; } @@ -124,18 +129,23 @@ class Y1 { class Y2 { bar: X2; } + function y(b) { return (b ? new Y1() : new Y2()); } + function consumer3(b) { var g = y(b); + if (g.bar instanceof X2) g.bar.foo = \"1337\"; else g.bar.foo = 1337; } + function consumer4(b) { var g = y(b); + if (g.bar instanceof X1) g.bar.foo = \"1337\"; } @@ -145,18 +155,23 @@ class Z1 { class Z2 { baz: Y2; } + function z(b) { return (b ? new Z1() : new Z2()); } + function consumer5(b) { var g = z(b); + if (g.baz.bar instanceof X2) g.baz.bar.foo = \"1337\"; else g.baz.bar.foo = 1337; } + function consumer6(b) { var g = z(b); + if (g.baz.bar instanceof X1) g.baz.bar.foo = \"1337\"; } @@ -172,9 +187,11 @@ class D extends C { s: string; constructor() { super(); + this.s = \"yup\"; } } + function foo0(x: Array | number) { if (x instanceof Array) { x[0] = 123; @@ -182,6 +199,7 @@ function foo0(x: Array | number) { x++; } } + function foo1(x: Array | number) { if (x instanceof Array) { x++; diff --git a/tests/interface/__snapshots__/jsfmt.spec.js.snap b/tests/interface/__snapshots__/jsfmt.spec.js.snap index 67a97b23..e81eb6d8 100644 --- a/tests/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/interface/__snapshots__/jsfmt.spec.js.snap @@ -48,8 +48,10 @@ declare class C { x: number } var x: string = new C().x; interface I { x: number } var i = new I(); + function testInterfaceName(o: I) { (o.name: string); + (o.constructor.name: string); } " @@ -91,7 +93,9 @@ interface I_ { x: number } interface J extends I, I_ {} interface K extends J {} var k: K = { x: \"\", y: \"\" }; + (k.x: string); + (k.y: string); declare class C { x: number } declare class D extends C, Other {} @@ -100,8 +104,11 @@ interface A_ { x: X } interface B extends A, A_ { z: Z } interface E extends B {} var e: E = { x: \"\", y: \"\", z: \"\" }; + (e.x: string); + (e.y: string); + (e.z: string); " `; @@ -124,15 +131,21 @@ function bar(m: M) { m.x; m.y; m.z; } // OK import type { J } from \"./import\"; interface K {} 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; } " @@ -153,8 +166,10 @@ function foo(k: K) { interface I { x: number; y: string } interface J { y: number } interface K extends I, J { x: string } + function foo(k: K) { (k.x: number); + (k.y: number); } " @@ -174,14 +189,10 @@ new C().bar((x: string) => { }); // error, number ~/~> string // error, property \`foo\` not found function // error, number ~/~> string interface I { foo(x: number): void } -(function foo(x: number) { - -}: I); + +(function foo(x: number) {}: I); declare class C { bar(i: I): void; bar(f: (x: number) => void): void } -new C().bar( - (x: string) => { - - } -); + +new C().bar((x: string) => {}); " `; diff --git a/tests/intersection/__snapshots__/jsfmt.spec.js.snap b/tests/intersection/__snapshots__/jsfmt.spec.js.snap index 35f46c7e..4df74080 100644 --- a/tests/intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/intersection/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,7 @@ function bar(x: Error & {type:number}): number { function foo(x: $All): number { return x.type; } + function bar(x: Error & { type: number }): number { return x.type; } @@ -80,10 +81,12 @@ type DuplexStreamOptions = ReadableStreamOptions & WritableStreamOptions & { readableObjectMode?: boolean; writableObjectMode?: boolean }; + function hasObjectMode_bad(options: DuplexStreamOptions): boolean { return options.objectMode || options.readableObjectMode || options.writableObjectMode; } + function hasObjectMode_ok(options: DuplexStreamOptions): boolean { return !!(options.objectMode || options.readableObjectMode || options.writableObjectMode); @@ -145,6 +148,7 @@ type F = (_: ObjA) => void; type G = (_: ObjB) => void; type FG = (_: ObjA | ObjB) => void; declare var fun1: F & G; + (fun1: FG); var fun2: FG = fun1; declare var f: ((_: number) => void) & ((_: string) => void); diff --git a/tests/issues-11/__snapshots__/jsfmt.spec.js.snap b/tests/issues-11/__snapshots__/jsfmt.spec.js.snap index 31d0b8f3..c3dbf1e2 100644 --- a/tests/issues-11/__snapshots__/jsfmt.spec.js.snap +++ b/tests/issues-11/__snapshots__/jsfmt.spec.js.snap @@ -5,6 +5,7 @@ exports.y = \"\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ exports.x = 1; + exports.y = \"\"; " `; diff --git a/tests/iter/__snapshots__/jsfmt.spec.js.snap b/tests/iter/__snapshots__/jsfmt.spec.js.snap index 8d040ac1..577e7f23 100644 --- a/tests/iter/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iter/__snapshots__/jsfmt.spec.js.snap @@ -44,35 +44,41 @@ for (var y in this) { // regression test to make sure \`in this\` doesn\'t fatal. it\'s currently // allowed, even though we can\'t actually enumerate all the keys on \`this\`. var a = [ true, false ]; -function foo(x) { - -} + +function foo(x) {} + for (var i = 0; i < 3; i++) { foo(a[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) { foo(d[n]); } + for (var x in undefined) { foo(x); } + for (var x in null) { foo(x); } -for (var y in this) { - -} + +for (var y in this) + {} " `; diff --git a/tests/iterable/__snapshots__/jsfmt.spec.js.snap b/tests/iterable/__snapshots__/jsfmt.spec.js.snap index a58f2d16..0481cceb 100644 --- a/tests/iterable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/iterable/__snapshots__/jsfmt.spec.js.snap @@ -63,6 +63,7 @@ function miss_the_cache(x: Array): Iterable { return x; function fill_the_cache(x: Array): Iterable { return x; } + function miss_the_cache(x: Array): Iterable { return x; } @@ -89,6 +90,7 @@ function foo(strs: Iterable): void { } } var m: Map = new Map(); + foo(m.keys()); " `; @@ -135,6 +137,7 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); + if (!done) { return { done, value: \"still going...\" }; } else { @@ -143,6 +146,7 @@ function makeIterator(coin_flip: () => boolean): Iterator { } }; } + function makeIterator(coin_flip: () => boolean): Iterator { return { \"@@iterator\"() { @@ -150,6 +154,7 @@ function makeIterator(coin_flip: () => boolean): Iterator { }, next(): IteratorResult { var done = coin_flip(); + if (done) { return { done, value: \"still going...\" }; } else { @@ -183,12 +188,15 @@ function mapTest4(map: Map): Iterable { function mapTest1(map: Map): Iterable<[string, number]> { return map; } + function mapTest2(map: Map): Iterable<[K, V]> { return map; } + function mapTest3(map: Map): Iterable<*> { return map; } + function mapTest4(map: Map): Iterable { return map; } @@ -217,12 +225,15 @@ function setTest4(set: Set): Iterable { function setTest1(set: Set): Iterable { return set; } + function setTest2(set: Set): Iterable { return set; } + function setTest3(set: Set): Iterable<*> { return set; } + function setTest4(set: Set): Iterable { return set; } @@ -254,7 +265,8 @@ exports[`test variance.js 1`] = ` /* @flow */ // ok, Iterable<+T> // ok, Iterator<+T> -(([ ]: Array): Iterable); -(([ ]: Array).values(): Iterable); +(([]: Array): Iterable); + +(([]: Array).values(): Iterable); " `; diff --git a/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap index 654f05bb..fca6f91a 100644 --- a/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_intrinsics.builtin/__snapshots__/jsfmt.spec.js.snap @@ -74,11 +74,17 @@ var React = require(\"react\"); var Div = \"div\"; var Bad = \"bad\"; var Str: string = \"str\"; +
; + ; + ; + React.createElement(\"div\", {}); + React.createElement(\"bad\", {}); +
; " `; diff --git a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap index f2adad66..ba4af193 100644 --- a/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_intrinsics.custom/__snapshots__/jsfmt.spec.js.snap @@ -27,7 +27,9 @@ class CustomComponent extends React.Component { } var a: React.Element<{ prop: string }> = ; var b: React.Element<{ prop1: string }> = ; +
; +
; var c: React.Element<{ id: string }> =
; var d: React.Element<{ id: number }> =
; @@ -67,12 +69,19 @@ var React = require(\"react\"); var Div = \"div\"; var Bad = \"bad\"; var Str: string = \"str\"; +
; + ; + ; + React.createElement(\"div\", {}); + React.createElement(\"bad\", {}); + React.createElement(Str, {}); +
; " `; diff --git a/tests/keys/__snapshots__/jsfmt.spec.js.snap b/tests/keys/__snapshots__/jsfmt.spec.js.snap index 5429c131..7044e9f6 100644 --- a/tests/keys/__snapshots__/jsfmt.spec.js.snap +++ b/tests/keys/__snapshots__/jsfmt.spec.js.snap @@ -65,38 +65,54 @@ 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 78425ba0..f8059f75 100644 --- a/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/last_duplicate_property_wins/__snapshots__/jsfmt.spec.js.snap @@ -80,9 +80,13 @@ class C { return \"hello\"; } } + (new C().foo(): boolean); + (new C().x: boolean); + (new C().bar: boolean); + (new C().qux: boolean); const o = { foo(): number { @@ -102,9 +106,13 @@ const o = { return \"hello\"; } }; + (o.foo(): boolean); + (o.x: boolean); + (o.bar: boolean); + (o.qux(): boolean); " `; diff --git a/tests/lib/__snapshots__/jsfmt.spec.js.snap b/tests/lib/__snapshots__/jsfmt.spec.js.snap index 305e1b07..100377f7 100644 --- a/tests/lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/lib/__snapshots__/jsfmt.spec.js.snap @@ -16,10 +16,11 @@ var y: string = Number.MAX_VALUE; var z: number = new TypeError().name; var w: string = parseInt(\"...\"); var a = new Map(); + a.delete(\"foobar\"); var b = undefined; -if (undefined) { - -} + +if (undefined) + {} " `; diff --git a/tests/libconfig/__snapshots__/jsfmt.spec.js.snap b/tests/libconfig/__snapshots__/jsfmt.spec.js.snap index 7fd71f3a..228bf3a0 100644 --- a/tests/libconfig/__snapshots__/jsfmt.spec.js.snap +++ b/tests/libconfig/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,7 @@ exports[`test libtest.js 1`] = ` bar(123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foo(123); + bar(123); " `; diff --git a/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap b/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap index 6bc3f2f4..a1a70c83 100644 --- a/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/libdef_ignored_module/__snapshots__/jsfmt.spec.js.snap @@ -8,6 +8,7 @@ import foo from \"foo\"; /* @flow */ // error number ~> string import foo from \"foo\"; + (foo.bar: string); " `; diff --git a/tests/librec/__snapshots__/jsfmt.spec.js.snap b/tests/librec/__snapshots__/jsfmt.spec.js.snap index 9d7c8b78..7916eed2 100644 --- a/tests/librec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/librec/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test libtest.js 1`] = ` bar(123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ foo(123); + bar(123); " `; diff --git a/tests/literal/__snapshots__/jsfmt.spec.js.snap b/tests/literal/__snapshots__/jsfmt.spec.js.snap index 60a307f5..ff9c8ac8 100644 --- a/tests/literal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/literal/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ exports[`test enum.js 1`] = ` module.exports = APIKeys; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var APIKeys = { AGE: \"age\", NAME: \"name\" }; + module.exports = APIKeys; " `; @@ -43,18 +44,22 @@ var red:string = tuple[indices.red]; // error: tuple[0] is a number // error: object.name is a string // error: tuple[0] is a number var APIKeys = require(\"./enum\"); -function foo(x: $Keys) { - -} + +function foo(x: $Keys) {} + foo(\"AGE\"); + foo(\"LOCATION\"); -function bar(x: $Keys<{ age: number }>) { - -} + +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]; @@ -94,17 +99,21 @@ function test4(flip_times: number): number { function test1(x: number): number { return -x; } + function test2(x: string): number { return -x; } + 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; } diff --git a/tests/locals/__snapshots__/jsfmt.spec.js.snap b/tests/locals/__snapshots__/jsfmt.spec.js.snap index db1a3e12..a8a33794 100644 --- a/tests/locals/__snapshots__/jsfmt.spec.js.snap +++ b/tests/locals/__snapshots__/jsfmt.spec.js.snap @@ -78,54 +78,79 @@ function switch_scope(x: mixed) { switch (x) { case \"foo\": let a; + a = 0; + b = 0; } + (a: string); + (b: string); } + function try_scope_finally() { let a; 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); } " @@ -160,19 +185,22 @@ function foo0(b: bool): number { // error: string ~> number var x: string = 0; var x: number = 1; -function foo(p: boolean) { - -} + +function foo(p: boolean) {} + function sorry(really: boolean) { if (really) { var x: number | string = 1337; } else { var x: boolean = true; } + foo(x); } + function foo0(b: boolean): number { var x = 0; + if (b) { var x = \"\"; } diff --git a/tests/logical/__snapshots__/jsfmt.spec.js.snap b/tests/logical/__snapshots__/jsfmt.spec.js.snap index 9b534898..0631cdca 100644 --- a/tests/logical/__snapshots__/jsfmt.spec.js.snap +++ b/tests/logical/__snapshots__/jsfmt.spec.js.snap @@ -735,174 +735,224 @@ function logical1a(): number { var x = false; return x && \"123\"; } + function logical1b(): string { var x = true; return x && \"123\"; } + function logical2a(): number { return false && \"123\"; } + function logical2b(): number { return 0 && \"123\"; } + function logical2c(): string { return \"\" && 123; } + function logical2d(): string { return true && \"123\"; } + function logical2e(): number { return \"foo\" && 123; } + function logical2f(): string { return 123 && \"foo\"; } + function logical2g(): string { return [ 1, 2, 3 ] && \"foo\"; } + function logical2h(x: { a: number }): string { return x && \"foo\"; } + function logical2i(x: Object): string { return x && \"foo\"; } + function logical2j(x: (a: number) => number): string { return x && \"foo\"; } + function logical2k(x: Function): string { return x && \"foo\"; } + function logical3a(): string { var x: ?number = null; return x != null && x > 10; } + function logical3b(): number { var x: ?number = null; return x != null && x; } + function logical3c(): ?number { var x: ?number = null; return x != undefined && x; } + function logical4(x: boolean): string { return x && \"123\"; } + function logical5a(): number { var x = false; return x || 0; } + function logical5b(): number { var x: ?number = null; return x || 0; } + function logical5c(): string { var x = true; return x || 0; } + function logical6a(): string { return false || \"123\"; } + function logical6b(): string { return 0 || \"123\"; } + function logical6c(): number { return \"\" || 123; } + function logical6d(): number { return true || \"123\"; } + function logical6e(): string { return \"foo\" || 123; } + function logical6f(): number { return 123 || \"foo\"; } + function logical7a(): number { var x: ?number = null; return x != null && x || 0; } + function logical7b(x: boolean, y: number): number { return x && y || 0; } + function logical7c(x: string): number { return x && 1 || 0; } + function logical7d(x: number): string { return x && \"foo\" || \"bar\"; } + function logical7e(x: number): string { return false && x || \"bar\"; } + function logical8a(): number { var x = false; return (x || 0) && \"foo\"; } + function logical8b(): string { var x = false; return (x || 1) && \"foo\"; } + function logical8c(): string { var x = true; return (x || 1) && \"foo\"; } + function logical8d(): number { var x = false; return x || 0 && \"foo\"; } + function logical8e(): string { var x = false; return x || 1 && \"foo\"; } + function logical8f(): string { var x = true; return x || 1 && \"foo\"; } + function logical9a(x: number, y: string): number | string { return x || y || false; } + function logical9b(x: number, y: string): number | string { return false || x || y; } + function logical9c(x: number, y: boolean): string { return \"a\" || x || y; } + function logical10a(x: number, y: string): number | string { return x && y && false; } + function logical10b(x: number, y: string): Array { return false && x && y; } + function logical10c(x: number, y: string): Array { return x && false && y; } + function logical11a(): number { var y = 1; + for (var x = 0; x < 5; x++) { y = y || true; } return y; } + 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; } + function logical12b(y: number): number { for (var x = 0; x < 5; x++) { y = y && true; } return y; } + function logical13(x: number): Array<{ x: string }> { return [ { x: x && \"bar\" }, @@ -915,6 +965,7 @@ function logical13(x: number): Array<{ x: string }> { { x: \"foo\" && \"bar\" } ]; } + function logical14(x: number): Array<{ x: string }> { return [ { x: x || \"bar\" }, @@ -927,51 +978,67 @@ function logical14(x: number): Array<{ x: string }> { { x: \"foo\" || \"bar\" } ]; } + function logical15a(x: number): number { return 5 + (x || 7); } + function logical15b(x: number): number { return (x || 7) + 5; } + function logical15c(x: number): number { return 5 + (x && 7); } + function logical15d(x: number): number { return (x && 7) + 5; } + function logical16a(x: number): boolean { return 5 < (x || 7); } + function logical16b(x: number): boolean { return (x || 7) < 5; } + function logical16c(x: number): boolean { return 5 < (x && 7); } + function logical16d(x: number): boolean { return (x && 7) < 5; } + function logical17a(x: number): boolean { return 5 == (x || 7); } + function logical17b(x: number): boolean { return (x || 7) == 5; } + function logical17c(x: number): boolean { return 5 == (x && 7); } + function logical17d(x: number): boolean { return (x && 7) == 5; } + function logical18a(x: number, y: number): number { return x - 1 || y - 1; } + function logical18b(x: { a: number }, y: { b: number }): number { return x.a - 1 || y.b - 1; } + function logical19a(x: { y: string; z: boolean }): boolean { return x.y && x.z; } + function logical19b(x: { y: string; z: boolean }): boolean { return x.y || x.z; } diff --git a/tests/loners/__snapshots__/jsfmt.spec.js.snap b/tests/loners/__snapshots__/jsfmt.spec.js.snap index 37c7f72b..c7f0b0f4 100644 --- a/tests/loners/__snapshots__/jsfmt.spec.js.snap +++ b/tests/loners/__snapshots__/jsfmt.spec.js.snap @@ -13,10 +13,12 @@ module.exports = export_f; var o = { x: 5, y: \"jello\" }; var z = o.z; 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 77059867..451d5d5f 100644 --- a/tests/method_properties/__snapshots__/jsfmt.spec.js.snap +++ b/tests/method_properties/__snapshots__/jsfmt.spec.js.snap @@ -36,28 +36,28 @@ f(foo); // error, could be undefined // error. caused by \`f(foo)\`; annotate x to track it down. class C { - C() { - - } - foo() { - - } - static bar() { - - } + C() {} + foo() {} + static bar() {} qux() { this.constructor.x; } } + C.x; + new C().foo.x; + C.bar.x; import { Foo } from \"./exports_optional_prop\"; const foo = new Foo(); + (foo.bar(): string); + function f(x) { (x.bar(): string); } + f(foo); " `; diff --git a/tests/misc/__snapshots__/jsfmt.spec.js.snap b/tests/misc/__snapshots__/jsfmt.spec.js.snap index 46f10dc8..21ed79a3 100644 --- a/tests/misc/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/__snapshots__/jsfmt.spec.js.snap @@ -18,13 +18,17 @@ f(A.x); // A.x is now a string, by def assign // A.x is now a string, by def assign module.exports = {}; var A = { x: true, ...{} }; + module.exports.cls = A; -function f(x: boolean) { - -} + +function f(x: boolean) {} + module.exports.fn = f; + A.y = \"?\"; + A.x = A.y; + f(A.x); " `; @@ -48,14 +52,19 @@ module.exports = B; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule B */ var A = require(\"A\").cls; + function B() { this.b = \"...\"; } + function f(): number { return this.b; } + B.prototype.s = 0; + B.prototype.fn = f; + module.exports = B; " `; @@ -79,12 +88,17 @@ module.exports = C; /* @providesModule C */ var B = require(\"B\"); var f = require(\"A\").fn; + function C() { var o = new B(); + f(o.b); + f(o.s); + o.fn(); } + module.exports = C; " `; @@ -107,13 +121,17 @@ module.exports = \"D for dummy\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule D */ var f = require(\"A\").fn; + function g(): string { return this.i; } var o = { fn: g, ...{} }; + o.i = true; var i = o.fn(); + f(i); + module.exports = \"D for dummy\"; " `; @@ -131,12 +149,12 @@ o.fn(false); module.exports = {obj: o}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule E */ -function h(x: number) { - -} +function h(x: number) {} var proto = { fn: h }; var o = Object.create(proto); + o.fn(false); + module.exports = { obj: o }; " `; @@ -152,7 +170,9 @@ function foo(x: Array): string { function fn2(x) { return x.length * 4; } + fn2({ length: \"hi\" }); + function foo(x: Array): string { return x.length; } @@ -169,10 +189,14 @@ b.length = \"duck\"; b.length(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = { length: \"duck\" }; + a.length = 123; + a.length(); var b = [ 123 ]; + b.length = \"duck\"; + b.length(); " `; diff --git a/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap b/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap index 8825ef9d..e5eaab89 100644 --- a/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap +++ b/tests/missing_annotation/__snapshots__/jsfmt.spec.js.snap @@ -132,6 +132,7 @@ var Bar = { c: Foo.c(\"bar\"), d: Foo.d(\"bar\") }; + module.exports = Foo, Bar; " `; diff --git a/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap b/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap index 1ac16e79..041a06f0 100644 --- a/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap +++ b/tests/modified_lib/__snapshots__/jsfmt.spec.js.snap @@ -7,6 +7,7 @@ bar(5); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import { bar } from \"foo\"; + bar(5); " `; diff --git a/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap b/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap index f0bdd78a..e8727e80 100644 --- a/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap +++ b/tests/module_not_found_errors/src/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ require(\'module_outside_of_root\'); // node_modules/module_outside_of_root/ sits outside of the Flow project root. // Flow should give a descriptive error about this require(\"module_completely_absent\"); + require(\"module_outside_of_root\"); " `; diff --git a/tests/modules/__snapshots__/jsfmt.spec.js.snap b/tests/modules/__snapshots__/jsfmt.spec.js.snap index 1472c43d..4cf8b95c 100644 --- a/tests/modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/modules/__snapshots__/jsfmt.spec.js.snap @@ -20,6 +20,7 @@ f(\"...\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var f = require(\"./lib\"); + f(\"...\"); " `; @@ -38,13 +39,13 @@ module.exports = f; /* @flow */ //function f(x) { g(x); return x; } //function f(x:number) { g(x); return x; } -function g(x: string) { - -} +function g(x: string) {} + function f(x: number): number { g(x); return x; } + module.exports = f; " `; diff --git a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap index 73d4cf6c..009c8722 100644 --- a/tests/more_annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_annot/__snapshots__/jsfmt.spec.js.snap @@ -23,7 +23,9 @@ module.exports = o3; var o1 = { x: 0, y: \"\" }; var o2 = { z: o1 }; var o3 = {}; + o3.w = o2; + module.exports = o3; " `; @@ -39,9 +41,8 @@ var o2: Foo = new Foo(); function Foo() { this.x = 0; } -Foo.prototype.m = function() { - -}; + +Foo.prototype.m = function() {}; var o1: { x: number; m(): void } = new Foo(); var o2: Foo = new Foo(); " @@ -54,9 +55,7 @@ class D extends C { } var d: { +m: () => void } = new D(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C { - m() { - - } + m() {} } class D extends C {} var d: { +m: () => void } = new D(); diff --git a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap index 4bd4e61b..605334d5 100644 --- a/tests/more_classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_classes/__snapshots__/jsfmt.spec.js.snap @@ -27,6 +27,7 @@ class Bar { self: Bar; constructor(y: number) { this.y = y; + this.self = this; } bar(z: string, u: string): string { @@ -34,6 +35,7 @@ class Bar { return z; } } + module.exports = Bar; " `; @@ -78,6 +80,7 @@ class Foo extends Qux { this.x = y; var u = new Foo(\"...\").qux(); var v = new Bar(y); + v.self = v; return v.bar(z, u); } @@ -85,6 +88,7 @@ class Foo extends Qux { this.x; } } + module.exports = Foo; " `; @@ -109,10 +113,9 @@ class Qux { qux() { return this.w; } - fooqux(x: number) { - - } + fooqux(x: number) {} } + module.exports = Qux; " `; diff --git a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap index 1388e940..c54471c6 100644 --- a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap @@ -41,27 +41,33 @@ function foo8(x:U,y):U { var foo1 = function(x: T): T { return x; }; + function foo2(x: T): S { return x; } var foo3 = function(x: T): T { return foo3(x); }; + function foo4(x: T): S { return foo4(x); } -var x = [ ]; +var x = []; + function foo5(): Array { return x; } var foo6 = function(x: R): R { return foo1(x); }; + function foo7(x: R): R { return foo5(); } + 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 3a6ae913..9db808cf 100644 --- a/tests/more_path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_path/__snapshots__/jsfmt.spec.js.snap @@ -62,60 +62,69 @@ module.exports = true; // if (typeof x == \'number\') { //f(x); //f(y); -function f(x: number) { - -} +function f(x: number) {} + function g() { return 42 || \"hello\"; } var x = g(); + if (typeof x === \"string\") { x = 0; } + f(x); class A {} + function h() { return 42 || new A(); } var y = h(); + if (y instanceof A) { y = 0; } + function bar() { return true; } class C { - qux() { - - } + qux() {} } + function foo() { var c = \"...\"; + c = new C(); + if (bar()) { c.qux(); } } + function goofy() { var x = g(); + if (typeof x == \"function\") { x(); - } else { - - } + } else + {} } + function goofy2() { var o = { x: 0 }; + if (typeof o.x == \"function\") { o.x(); } var y = o.x; + if (typeof y == \"function\") { y(); - } else { - - } + } else + {} } + module.exports = true; " `; @@ -135,14 +144,16 @@ function FlowSA() { module.exports = FlowSA; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule FlowSA */ -function check(x: string) { - -} +function check(x: string) {} + function FlowSA() { var x = 0; + x = \"...\"; + check(x); } + module.exports = FlowSA; " `; @@ -196,49 +207,49 @@ module.exports = \"sigma\"; // error // unreachable, TODO: this shouldn\'t throw class A { - a() { - - } + a() {} } class B extends A { - b() { - - } + b() {} } class C extends B { - c() { - - } + c() {} } + function bar(x: B) { if (x instanceof A) { x.a(); + x.c(); } else { x++; } } + function foo(x: A) { if (x instanceof C) { x.a(); + x.b(); + x.c(); + x.d(); } else { x.a(); + x.c(); } } class D { - d() { - - } + d() {} } + function baz(x: D) { - if (x instanceof A) { - - } + if (x instanceof A) + {} } + module.exports = \"sigma\"; " `; @@ -266,6 +277,7 @@ class BaseClass { class ChildClass extends BaseClass { childProp: string; } + function test(obj: BaseClass): string { if (obj instanceof ChildClass) { return obj.childProp_TYPO; diff --git a/tests/namespace/__snapshots__/jsfmt.spec.js.snap b/tests/namespace/__snapshots__/jsfmt.spec.js.snap index faff8b91..fe0c0865 100644 --- a/tests/namespace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/namespace/__snapshots__/jsfmt.spec.js.snap @@ -30,10 +30,9 @@ module.exports = { foo: (\"\": number) }; /*@flow*/ // import type { T } from \'...\' type T = (x: number) => void; -var f: T = function(x: string): void { - -}; +var f: T = function(x: string): void {}; type Map = (x: X) => Y; + function bar(x: U, f: Map): V { return f(x); } @@ -41,6 +40,7 @@ var y: number = bar(0, x => \"\"); type Seq = number | Array; var s1: Seq = [ 0, [ 0 ] ]; var s2: Seq = [ [ \"\" ] ]; + module.exports = { foo: (\"\": number) }; " `; diff --git a/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap b/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap index 20acb26b..df899f28 100644 --- a/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_modules_with_symlinks/root/__snapshots__/jsfmt.spec.js.snap @@ -6,7 +6,9 @@ console.log(y); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"symlink_lib\"); var y = require(\"symlink_lib_outside_root\"); + console.log(x); + console.log(y); " `; diff --git a/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap index 35b84c3b..9ef8d717 100644 --- a/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/assert/__snapshots__/jsfmt.spec.js.snap @@ -9,7 +9,9 @@ assert.ok(true) // ok // ok // ok var assert = require(\"assert\"); + assert(true); + assert.ok(true); " `; diff --git a/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap index da8e1cb6..c2fb53b3 100644 --- a/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"./bar.js\"); + console.log(x); " `; diff --git a/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap index d1b67587..2d694c58 100644 --- a/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_file/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // bar.js does not work var x = require(\"./bar\"); + console.log(x); " `; diff --git a/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap index 4caf098a..781fee3c 100644 --- a/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_node_modules/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar.js\"); + console.log(x); " `; diff --git a/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap index 68209ae1..7f860b9b 100644 --- a/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_node_modules_with_path/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/bar\"); + console.log(x); " `; diff --git a/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap index bdc2306d..db75331d 100644 --- a/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/basic_package/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x = require(\"./bar_lib\"); + console.log(x); " `; diff --git a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap index 40e4aa87..777d7f2e 100644 --- a/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/buffer/__snapshots__/jsfmt.spec.js.snap @@ -70,54 +70,84 @@ let bool: boolean = false; let buffer: Buffer = new Buffer(0); let num: number = 0; let maybeNum: ?number; + buffer.length; + buffer.buffer; + buffer.byteOffset; + buffer.byteLength; + buffer[1]; + buffer.copyWithin(0, 0); + buffer.copyWithin(0, 0, 0); const it1: Iterator<[number, number]> = buffer.entries(); + bool = buffer.every((element: number) => false); + bool = buffer.every((element: number) => false, buffer); + buffer = buffer.fill(1); + buffer = buffer.fill(1, 0, 0); + buffer = buffer.fill(\"a\"); + buffer = buffer.fill(\"a\", 0, 0); + buffer = buffer.fill(\"a\", 0, 0, \"utf8\"); + buffer = buffer.fill(\"a\", \"utf8\"); + maybeNum = buffer.find( (element: number, index: number, array: Uint8Array) => false ); + maybeNum = buffer.find( (element: number, index: number, array: Uint8Array) => false, buffer ); + num = buffer.findIndex( (element: number, index: number, array: Uint8Array) => false ); + num = buffer.findIndex( (element: number, index: number, array: Uint8Array) => false, buffer ); + buffer.forEach((value: number) => console.log(value), buffer); + buffer.forEach( (value: number, index: number, array: Uint8Array) => console.log(value), buffer ); + bool = buffer.includes(3); + bool = buffer.includes(3, 4); + 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( typedArray.buffer, typedArray.byteOffset, typedArray.byteLength ); + buffer = Buffer.from(new Buffer(0)); + buffer = Buffer.from(\"foo\", \"utf8\"); + buffer = Buffer.from([ 98, 117, 102, 102, 101, 114 ], (a: number) => a + 1, {}); " `; 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 72218f15..dbd4386d 100644 --- a/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/child_process/__snapshots__/jsfmt.spec.js.snap @@ -21,13 +21,16 @@ exec(\'ls\', {maxBuffer: 100}, function(error, stdout, stderr) { // options only. // options + callback. var exec = require(\"child_process\").exec; + exec( \"ls\", function(error, stdout, stderr) { console.info(stdout); } ); + exec(\"ls\", { timeout: 250 }); + exec( \"ls\", { maxBuffer: 100 }, @@ -75,14 +78,18 @@ execFile(\'ls\', [\'-l\'], {timeout: 250}, function(error, stdout, stderr) { // args + options. // Put it all together. var execFile = require(\"child_process\").execFile; + execFile(\"ls\", [ \"-lh\" ]); + execFile( \"ls\", function(error, stdout, stderr) { console.info(stdout); } ); + execFile(\"wc\", { timeout: 250 }); + execFile( \"ls\", [ \"-l\" ], @@ -90,7 +97,9 @@ execFile( console.info(stdout); } ); + execFile(\"ls\", [ \"-l\" ], { timeout: 250 }); + execFile( \"ls\", [ \"-l\" ], @@ -122,11 +131,17 @@ var execSync = require(\'child_process\').execSync; // error, no signatures match // error, no signatures match var execSync = require(\"child_process\").execSync; + (execSync(\"ls\"): Buffer); + (execSync(\"ls\", { encoding: \"buffer\" }): Buffer); + (execSync(\"ls\", { encoding: \"utf8\" }): string); + execSync(\"ls\", { timeout: \"250\" }); + execSync(\"ls\", { stdio: \"inherit\" }); + execSync(\"ls\", { stdio: [ \"inherit\" ] }); " `; @@ -169,34 +184,42 @@ wc.stderr.pipe(process.stderr); var child_process = require(\"child_process\"); var ls = child_process.spawn(\"ls\"); var wc = child_process.spawn(\"wc\", [ \"-l\" ]); + child_process.spawn( \"echo\", [ \"-n\", \"\\\"Testing...\\\"\" ], { env: { TEST: \"foo\" } } ); + child_process.spawn(\"echo\", { env: { FOO: 2 } }); + ls.stdout.on( \"data\", function(data) { wc.stdin.write(data); } ); + ls.stderr.on( \"data\", function(data) { console.warn(data); } ); + ls.on( \"close\", function(code) { if (code !== 0) { console.warn(\"\`ls\` exited with code %s\", code); } + wc.stdin.end(); } ); + wc.stdout.pipe(process.stdout); + wc.stderr.pipe(process.stderr); " `; diff --git a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap index 7b7760ba..62830212 100644 --- a/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/crypto/__snapshots__/jsfmt.spec.js.snap @@ -52,28 +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/fs/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap index def77bd1..09c25640 100644 --- a/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/fs/__snapshots__/jsfmt.spec.js.snap @@ -40,12 +40,14 @@ fs.readFile(\"file.exp\", {}, (_, data) => { // error // error var fs = require(\"fs\"); + fs.readFile( \"file.exp\", (_, data) => { (data: Buffer); } ); + fs.readFile( \"file.exp\", \"blah\", @@ -53,6 +55,7 @@ fs.readFile( (data: string); } ); + fs.readFile( \"file.exp\", { encoding: \"blah\" }, @@ -60,6 +63,7 @@ fs.readFile( (data: string); } ); + fs.readFile( \"file.exp\", {}, @@ -67,13 +71,21 @@ fs.readFile( (data: Buffer); } ); + (fs.readFileSync(\"file.exp\"): Buffer); + (fs.readFileSync(\"file.exp\"): string); + (fs.readFileSync(\"file.exp\", \"blah\"): string); + (fs.readFileSync(\"file.exp\", \"blah\"): Buffer); + (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): string); + (fs.readFileSync(\"file.exp\", { encoding: \"blah\" }): Buffer); + (fs.readFileSync(\"file.exp\", {}): Buffer); + (fs.readFileSync(\"file.exp\", {}): string); " `; 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 722a7156..06cb4233 100644 --- a/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/json_file/__snapshots__/jsfmt.spec.js.snap @@ -37,21 +37,34 @@ let data4 = require(\'./json_array\'); // error, should be null // ok let data = require(\"./package/index.json\"); + (data.foo: void); + (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); + (data4: void); + (require(\"./json_string\"): void); + (require(\"./json_number\"): void); + (require(\"./json_true\"): void); + (require(\"./json_false\"): void); + (require(\"./json_null\"): void); + (require(\"./json_negative_number\"): -1); " `; diff --git a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap index bccf9dff..3c9a4c71 100644 --- a/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/os/__snapshots__/jsfmt.spec.js.snap @@ -21,13 +21,19 @@ var u3 = os.userInfo({encoding: \'buffer\'}); // error var os = require(\"os\"); 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); + (u3.username: Buffer); " `; diff --git a/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap index b71f83ab..869132ca 100644 --- a/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/package_file/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x: string = require(\"./bar_lib\"); + console.log(x); " `; diff --git a/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap index 5604ee51..56acd783 100644 --- a/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/package_file_node_modules/foo/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // \'bar_lib\' does not work! var x: string = require(\"bar_lib\"); + console.log(x); " `; diff --git a/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap index 51bc929a..6da9a82e 100644 --- a/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/src/lib/bar\"); + console.log(x); " `; diff --git a/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap index d2e4c58f..3ed654b1 100644 --- a/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules_with_short_main/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib\"); + console.log(x); " `; diff --git a/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap index d2e4c58f..3ed654b1 100644 --- a/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_node_modules_without_main/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib\"); + console.log(x); " `; diff --git a/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap index e77df483..0d81ff4d 100644 --- a/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/path_package/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test foo.js 1`] = ` console.log(x); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x = require(\"bar_lib/src/lib\"); + console.log(x); " `; diff --git a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap index e510e6e3..0ac5cef2 100644 --- a/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/stream/__snapshots__/jsfmt.spec.js.snap @@ -39,43 +39,32 @@ var fs = require(\"fs\"); var stream = require(\"stream\"); var ls = child_process.spawn(\"ls\"); var data = \"foo\"; + ls.stdin.write(data); + ls.stdin.write(data, \"utf-8\"); -ls.stdin.write( - data, - () => { - - } -); -ls.stdin.write( - data, - \"utf-8\", - () => { - - } -); + +ls.stdin.write(data, () => {}); + +ls.stdin.write(data, \"utf-8\", () => {}); + ls.stdin.end(); + ls.stdin.end(data); + ls.stdin.end(data, \"utf-8\"); -ls.stdin.end( - data, - () => { - - } -); -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 {} class MyTransform extends stream.Duplex {} + new MyReadStream().pipe(new MyDuplex()).pipe(new MyTransform()).pipe( new MyWriteStream() ); diff --git a/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap index 862e8381..569e8e36 100644 --- a/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/timers/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ setImmediate(setImmediateCallback); function setImmediateCallback(): number { return 0; } + setImmediate(setImmediateCallback); " `; diff --git a/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap b/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap index f335f9ef..a08c91e9 100644 --- a/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap +++ b/tests/node_tests/url/__snapshots__/jsfmt.spec.js.snap @@ -3,6 +3,7 @@ exports[`test url.js 1`] = ` url.format(url.parse(\'https://example.com/foo\')); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const url = require(\"url\"); + url.format(url.parse(\"https://example.com/foo\")); " `; diff --git a/tests/nullable/__snapshots__/jsfmt.spec.js.snap b/tests/nullable/__snapshots__/jsfmt.spec.js.snap index c1a757cf..18cd15f6 100644 --- a/tests/nullable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/nullable/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,7 @@ exports[`test maybe.js 1`] = ` // ok // error (only num ~> string) ((\"foo\": ??string): ?string); + ((123: ??number): ?string); " `; @@ -40,25 +41,29 @@ var array_of_nullable: Array = [null, 3]; function foo(): string { return null; } + function bar(): ?string { return null; } -function qux(x: string) { - -} -function corge(x: number) { - -} + +function qux(x: string) {} + +function corge(x: number) {} var x = bar(); + if (x != null) qux(x); + if (x != null) corge(x); + function grault() { x = null; } + if (x != null) { grault(); + qux(x); } var array_of_nullable: Array = [ null, 3 ]; @@ -74,17 +79,16 @@ bar(\'hmm\'); function fn(data: ?{}) {} fn({some: \'literal\'}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function foo(x: ?string) { - -} -function bar(x: ?number) { - -} +function foo(x: ?string) {} + +function bar(x: ?number) {} + foo(\"hmm\"); + bar(\"hmm\"); -function fn(data: ?{}) { - -} + +function fn(data: ?{}) {} + fn({ some: \"literal\" }); " `; diff --git a/tests/object-method/__snapshots__/jsfmt.spec.js.snap b/tests/object-method/__snapshots__/jsfmt.spec.js.snap index 6b3dc937..509cceba 100644 --- a/tests/object-method/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object-method/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ exports[`test id.js 1`] = ` module.exports = id; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare function id(_: X): X; + module.exports = id; " `; @@ -18,6 +19,7 @@ function subtypeCheck(x: Interface): ObjectType { return x; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ interface Interface { m(): void } import type { ObjectType } from \"./test\"; + function subtypeCheck(x: Interface): ObjectType { return x; } @@ -41,9 +43,11 @@ module.exports = id( ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ const id = require(\"./id\"); export type ObjectType = { +m: () => void }; + function methodCaller(x: ObjectType) { x.m(); } + module.exports = id(methodCaller); " `; @@ -75,7 +79,9 @@ function f() { } var a = { p: 0, f }; var b = { f }; + a.f(); + b.f(); " `; @@ -109,14 +115,19 @@ qux({ f: foo }); // error, since \`this\` is used non-trivially in \`foo\` function foo() { this.m(); } + function bar(f: () => void) { f(); + ({ f }).f(); } + bar(foo); + function qux(o: { f(): void }) { o.f(); } + qux({ f: foo }); " `; diff --git a/tests/object_annot/__snapshots__/jsfmt.spec.js.snap b/tests/object_annot/__snapshots__/jsfmt.spec.js.snap index 173c7a7b..73b5e962 100644 --- a/tests/object_annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_annot/__snapshots__/jsfmt.spec.js.snap @@ -12,6 +12,7 @@ function bar(x: Object): Array { function foo(x: Array): Array { return x.sort((a, b) => a.foo - b.foo); } + function bar(x: Object): Array { return Object.keys(x); } diff --git a/tests/object_api/__snapshots__/jsfmt.spec.js.snap b/tests/object_api/__snapshots__/jsfmt.spec.js.snap index d227179d..c4070aab 100644 --- a/tests/object_api/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_api/__snapshots__/jsfmt.spec.js.snap @@ -3,11 +3,7 @@ exports[`test a.js 1`] = ` module.exports = { a() {} };~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ -module.exports = { - a() { - - } -}; +module.exports = { a() {} }; " `; @@ -22,16 +18,10 @@ module.exports = b; /* @flow */ // works here var a = require(\"./a\"); -var b = Object.assign( - { - bar() { - - }, - ...{} - }, - a -); +var b = Object.assign({ bar() {}, ...{} }, a); + b.a(); + module.exports = b; " `; @@ -44,7 +34,9 @@ c.a(); c.foo();~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var c = require(\"./b\"); + c.a(); + c.foo(); " `; @@ -75,7 +67,9 @@ var export_ = Object.assign( ); var decl_export_: { foo: any; bar: any } = Object.assign({}, export_); let anyObj: Object = {}; + Object.assign(anyObj, anyObj); + module.exports = export_; " `; @@ -107,11 +101,15 @@ declare var o: O; class C { foo: string; } + (Object.create(C.prototype): C); + (Object.create(new C()): C); + ({ foo: \"foo\" }: C); type O = { foo: string }; declare var o: O; + (o: C); " `; @@ -135,6 +133,7 @@ class Bar extends Foo {} let tests = [ function() { const x = new Bar(); + (Object.getPrototypeOf(x): Foo); } ]; @@ -185,35 +184,38 @@ class Bar extends Foo { // only own enumerable props // error: bar_prop ~> error var sealed = { one: \"one\", two: \"two\" }; + (Object.keys(sealed): Array<\"one\" | \"two\">); + (Object.keys(sealed): void); var unsealed = {}; + Object.keys(unsealed).forEach( k => { (k: number); } ); var dict: { [k: number]: string } = {}; + Object.keys(dict).forEach( k => { (k: number); } ); var any: Object = {}; + (Object.keys(any): Array); class Foo { prop: string; - foo() { - - } + foo() {} } + (Object.keys(new Foo()): Array<\"error\">); class Bar extends Foo { bar_prop: string; - bar() { - - } + bar() {} } + (Object.keys(new Bar()): Array<\"error\">); " `; @@ -467,18 +469,13 @@ var k : Object = a.constructor; // // constructor // -function takesABool(x: boolean) { - -} -function takesAString(x: string) { - -} -function takesANumber(x: number) { - -} -function takesAnObject(x: Object) { - -} +function takesABool(x: boolean) {} + +function takesAString(x: string) {} + +function takesANumber(x: number) {} + +function takesAnObject(x: Object) {} class Foo {} var a = { foo: \"bar\" }; var b = { foo: \"bar\", ...{} }; @@ -491,82 +488,114 @@ var c = { var d: { [key: string]: string } = { foo: \"bar\" }; var x = new Date(); var y = new Foo(); + takesAString(a.toString()); + d.toString(); var aToString: () => string = a.toString; var aToString2 = a.toString; + takesAString(aToString2()); + b.toString = function(): string { return \"foo\"; }; + 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()); + (123).toString(); + (123).toString; -(123).toString = function() { - -}; + +(123).toString = function() {}; + (123).toString(2); + (123).toString(\"foo\"); + (123).toString(null); + takesABool(a.hasOwnProperty(\"foo\")); var aHasOwnProperty: (prop: string) => boolean = a.hasOwnProperty; var aHasOwnProperty2 = a.hasOwnProperty; + 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; + 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; + 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; + 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_assign/__snapshots__/jsfmt.spec.js.snap b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap index a6af5708..39a29d28 100644 --- a/tests/object_assign/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_assign/__snapshots__/jsfmt.spec.js.snap @@ -55,6 +55,7 @@ var Good = Object.assign( } ); var good: number = Good.foo(); + module.exports = { Bad: Bad, Good: Good }; " `; @@ -108,6 +109,7 @@ exports[`test apply.js 1`] = ` a: number; b: string }); + (Object.assign({}, ...[ { a: 1 }, { b: \"foo\" } ]): { a: number; b: string }); " `; @@ -121,7 +123,9 @@ Object.assign({a: \"foo\"}, 123); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ Object.assign(\"123\", { a: \"foo\" }); + Object.assign(123, { a: \"foo\" }); + Object.assign({ a: \"foo\" }, 123); " `; @@ -161,7 +165,9 @@ class MyReactThing extends React.Component { return this.props.foo; } } + ; + ; " `; diff --git a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap index ded3b2c4..6a8f83d1 100644 --- a/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_freeze/__snapshots__/jsfmt.spec.js.snap @@ -29,17 +29,23 @@ var xx : { x: number } = Object.freeze({ x: \"error\" }) // error // error 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 }); + bliffl.bar = \"23456\"; + bliffl.baz = 3456; + bliffl.corge; + bliffl.constructor = baz; -bliffl.toString = function() { - -}; + +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 8bc88aaa..35fe0eb7 100644 --- a/tests/object_is/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_is/__snapshots__/jsfmt.spec.js.snap @@ -23,19 +23,30 @@ var c: boolean = Object.is(\'a\'); var d: boolean = Object.is(\'a\', \'b\', \'c\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Object.is(1, 1); + Object.is(1, 2); + Object.is(1, {}); + Object.is(1, NaN); + Object.is(0, 0); + Object.is(0, -0); + Object.is(NaN, NaN); + Object.is({}, {}); var emptyObject = {}; -var emptyArray = [ ]; +var emptyArray = []; + 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\"); diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index a322f6db..6fc68964 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -23,18 +23,28 @@ var z = Object(123); // error (next line makes this not match any signatures) // error // error (next line makes this not match any signatures) (Object({ foo: \"bar\" }): { foo: string }); + (Object(\"123\"): String); + (Object(123): Number); + (Object(true): Boolean); + (Object(null): {}); + (Object(undefined): {}); + (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); " `; @@ -73,18 +83,30 @@ y[\'bar\'] = \'abc\'; // error, property not found // error, property not found // error, prototype method is not a string var x: { \"123\": string; bar: string } = { \"123\": \"val\", bar: \"bar\" }; + (x.foo: string); + (x[\"foo\"]: string); + (x[123]: boolean); + (x.bar: boolean); + (x[\"123\"]: boolean); + x[\"123\"] = false; + x[123] = false; + x[\"foo\" + \"bar\"] = \"derp\"; + (x[\`foo\`]: string); var y: { foo: string } = { foo: \"bar\" }; + y[\"foo\"] = 123; + y[\"bar\"] = \"abc\"; + (y[\"hasOwnProperty\"]: string); " `; @@ -134,14 +156,20 @@ function assign_then_widen() { // error: subsequent assignment might make glob.x a number // ok, by lvalue\'s given type 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 fd2b47d7..9dff0d4d 100644 --- a/tests/objmap/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objmap/__snapshots__/jsfmt.spec.js.snap @@ -25,11 +25,15 @@ promiseAllByKey({ declare function promiseAllByKey(o: O): Promise<$ObjMap>; declare function keyMirror(o: O): $ObjMapi(k: K) => K>; var o = keyMirror({ FOO: null, BAR: null }); + (o.FOO: \"FOO\"); + (o.FOO: \"BAR\"); + 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 519ea361..dfdbc2e2 100644 --- a/tests/optional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional/__snapshots__/jsfmt.spec.js.snap @@ -4,6 +4,7 @@ exports[`test client_optional.js 1`] = ` qux(0); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var qux = require(\"./optional\"); + qux(0); " `; @@ -26,13 +27,9 @@ class C { x(x: T = 0) {} } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function x(x: T = 0) { - -} +function x(x: T = 0) {} class C { - x(x: T = 0) { - - } + x(x: T = 0) {} } " `; @@ -109,36 +106,43 @@ function optionalNullable1(x: { y?: ?number }) { x.y++; } } + function optionalNullable2(x: { y?: ?number }) { if (x.y !== undefined && x.y !== null) { x.y++; } } + function optionalNullable3(x: { y?: ?number }) { if (!(x.y !== null && x.y !== undefined)) { x.y++; } } + function optionalNullable4(x: { y?: ?number }) { if (!(x.y !== undefined && x.y !== null)) { x.y++; } } + function optionalNullable5(x: { y?: ?number }) { if (x.y === null || x.y === undefined) { x.y++; } } + function optionalNullable6(x: { y?: ?number }) { if (x.y === undefined || x.y === null) { x.y++; } } + function optionalNullable7(x: { y?: ?number }) { if (!(x.y === null || x.y === undefined)) { x.y++; } } + function optionalNullable8(x: { y?: ?number }) { if (!(x.y === undefined || x.y === null)) { x.y++; @@ -164,15 +168,21 @@ module.exports = qux; function bar(x?, y?) { x * 0; } + bar(0); var foo: (x?: number) => void = bar; + foo(); + function qux(x = \"hello\", ...y): string { foo(x); return y[0]; } + qux(0, 0); + qux(0, ...[ \"\", 42 ]); + module.exports = qux; " `; @@ -221,40 +231,45 @@ function foo(x?: string): string { } return x; } + function bar(obj: { x?: string }): string { if (obj.x == null) { return \"foo\"; } return obj.x; } + function baz(bar?) { if (!bar) { return 1; } return bar.duck; } + function testOptionalNullable(x?: ?string): string { if (x == null) { return \"foo\"; } return x; } + function testOptionalNullableDefault(x?: ?string = \"hi\"): string { if (x == null) { return \"foo\"; } return x; } + 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) { - - }; + var f = function(y: ?string) {}; + f(x); } " @@ -286,13 +301,14 @@ bar(undefined); // ok ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ok // ok -function foo(x?: number) { - -} +function foo(x?: number) {} + foo(undefined); + function bar(x = \"bar\"): string { return x; } + bar(undefined); " `; @@ -321,9 +337,13 @@ foo(123, true); // ERROR boolean ~> string function foo(x?: number, ...y: Array): [?number, Array] { return [ x, y ]; } + foo(); + foo(123), foo(123, \"hello\"); + foo(true); + foo(123, true); " `; @@ -340,9 +360,11 @@ function bar() { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; + function foo(bar? = undefined) { x = bar; } + function bar() { return x.duck; } @@ -361,9 +383,11 @@ function bar() { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var x; + function foo(bar?) { x = bar; } + function bar() { return x.duck; } diff --git a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap index 1b3ee083..d588ecd2 100644 --- a/tests/optional_props/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional_props/__snapshots__/jsfmt.spec.js.snap @@ -19,12 +19,15 @@ var x: {} = { foo: 0 }; var y: { foo?: string } = x; var z: string = y.foo || \"\"; var o = {}; + y = o; + o.foo = 0; -function bar(config: { foo?: number }) { - -} + +function bar(config: { foo?: number }) {} + bar({}); + bar({ foo: \"\" }); " `; @@ -53,10 +56,14 @@ var f: { foo?: ?string } = { foo: null }; // Also fine // This is fine // Also fine 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 }; @@ -165,12 +172,15 @@ class A { // annotation will be processed before the flow involving the // access. Here we lose the race and get an error on the write. 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\"; } } @@ -194,6 +204,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 0df61d1d..2ba0f471 100644 --- a/tests/overload/__snapshots__/jsfmt.spec.js.snap +++ b/tests/overload/__snapshots__/jsfmt.spec.js.snap @@ -92,13 +92,20 @@ declare class C { bar(x: { a: string }): string } var a = new C(); + a.foo(0); + a.foo(\"hey\"); + a.foo(true); + a.bar({ a: 0 }); + a.bar({ a: \"hey\" }); + a.bar({ a: true }); declare var x: { a: boolean } & { b: string }; + a.bar(x); " `; @@ -112,6 +119,7 @@ exports[`test test.js 1`] = ` // matches one of the overloads of set function foo() { var output = new FakeUint8Array(); + output.set(new FakeUint8Array(), 0); } " @@ -130,7 +138,9 @@ var foo = new Foo; // error declare class Foo { bar(x: \"hmm\"): number; bar(x: string): string } var foo = new Foo(); + (foo.bar(\"hmm\"): number); + (foo.bar(\"hmmm\"): number); " `; @@ -169,15 +179,18 @@ h(x_h.p); // ok declare function f(x: string): void; 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 }; + h(x_h.p); " `; @@ -189,7 +202,7 @@ var x1:number = foo(0)[0]; var x2:string = foo([\"\"])[0]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo(x: $Either, U>): Array { - return [ ]; + 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 2de635b6..8c46efe5 100644 --- a/tests/path/__snapshots__/jsfmt.spec.js.snap +++ b/tests/path/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +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 a20611cb..5240481c 100644 --- a/tests/plsummit/__snapshots__/jsfmt.spec.js.snap +++ b/tests/plsummit/__snapshots__/jsfmt.spec.js.snap @@ -8,6 +8,7 @@ function foo(x) { return [ x, x > 0, \"number \" + x ]; } var [ n, b, s ] = foo(42); + n * s.length; " `; @@ -26,6 +27,7 @@ class C { this.x = x; } } + module.exports = C; " `; @@ -38,6 +40,7 @@ function foo(x: X): X { r = x; return x; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var r: number = 0; + function foo(x: X): X { r = x; return x; @@ -73,6 +76,7 @@ function foo() { var x = 0; var y = x; } + function bar(x: ?string): number { if (x == null) x = \"\"; @@ -99,19 +103,23 @@ var y: number = o2.bar(); function C() { this.x = 0; } + C.prototype.foo = function() { return this.x; }; var c = new C(); var x: string = c.foo(); + function foo() { return this.y; } + 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 16a4986a..ba671790 100644 --- a/tests/poly/__snapshots__/jsfmt.spec.js.snap +++ b/tests/poly/__snapshots__/jsfmt.spec.js.snap @@ -16,11 +16,14 @@ function bar(): A<*> { // error, * can\'t be {} and {x: string} at the same time // ok but unsafe, caller may assume any type arg // error, * can\'t be {} and {x: string} at the same time class A {} + new A(); class B extends A {} + function foo(b): A { return (b ? (new A(): A) : (new A(): A)); } + function bar(): A<*> { return (new A(): A<{}>) || (new A(): A<{ x: string }>); } @@ -63,9 +66,13 @@ class C { } } var a: C<*> = new C(); + a.meth(new Middle()); + a.meth(new Child()); + a.meth(42); + a.meth(new Base()); " `; @@ -102,6 +109,7 @@ type Box = { }; declare var bool: Box; declare function unbox(box: Box): A; + unbox(bool); " `; @@ -132,6 +140,7 @@ class Foo { this.x = x; } } + function bar(foo: Foo, y: S): Foo { return new Foo(y); } diff --git a/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap b/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap index a34a5433..76725074 100644 --- a/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/poly_class_export/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ module.exports = A; class A { x: T; } + module.exports = A; " `; @@ -35,6 +36,7 @@ class B extends A { super(); } } + module.exports = new B(); " `; diff --git a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap index c89941b6..80e8e4f4 100644 --- a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap @@ -19,7 +19,9 @@ declare function my_filter>(v: Array, cb: P): Array<$Refine>; declare var arr: Array; const barr = my_filter(arr, is_string); + (barr: Array); + function is_string(x): %checks { return typeof x === \"string\"; } @@ -57,7 +59,9 @@ type C = { kind: \"C\"; y: boolean }; type D = { kind: \"D\"; x: boolean }; type E = { kind: \"E\"; y: boolean }; declare var ab: Array; + (my_filter(ab, (x): %checks => x.kind === \"A\"): Array); + (my_filter(ab, (x): %checks => x.kind !== \"A\"): Array); " `; @@ -133,6 +137,7 @@ function is_string_and_number(x, y): %checks { declare function refine>(v: T, cb: P): $Refine; declare var a: mixed; var b = refine(a, is_string); + (b: string); declare function refine_fst>(v: T, w: T, @@ -140,11 +145,14 @@ cb: P): $Refine; declare var c: mixed; 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 { return typeof x === \"string\"; } + function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } @@ -182,13 +190,17 @@ declare function my_filter>(v: Array, cb: P): Array<$Refine>; 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); + (d: Array); + function is_string(x): boolean %checks { return typeof x === \"string\"; } + function is_string_regular(x): boolean { return typeof x === \"string\"; } @@ -226,7 +238,9 @@ type C = { kind: \"C\"; y: boolean }; type D = { kind: \"D\"; x: boolean }; type E = { kind: \"E\"; y: boolean }; declare var ab: Array; + (my_filter(ab, (x): %checks => x.kind === \"A\"): Array); + (my_filter(ab, (x): %checks => x.kind !== \"A\"): Array); " `; @@ -289,6 +303,7 @@ function is_string_and_number(x, y): %checks { declare function refine>(v: T, cb: P): $Refine; declare var a: mixed; var b = refine(a, is_string); + (b: string); declare var c: mixed; declare var d: mixed; @@ -298,18 +313,24 @@ v: T, w: T, cb: P): $Refine; var e = refine3(c, d, e, is_string_and_number); + (e: string); + function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } var e = refine(a, is_string_regular); + (e: number); + function is_string(x): %checks { return typeof x === \"string\"; } + function is_string_regular(x) { return typeof x === \"string\"; } + function is_string_and_number(x, y): %checks { return typeof x === \"string\" && typeof y === \"number\"; } diff --git a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap index f5b20161..ab046733 100644 --- a/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-declared/__snapshots__/jsfmt.spec.js.snap @@ -59,22 +59,22 @@ class C { } declare var m: Function; const o = { a: 1 }; + if (m.bind(o)) { o.a; } class D { m: Function; n() { - if (this.m({})) { - - } + if (this.m({})) + {} } } declare var m: Function; const x = \"\"; -if (m.bind(this)(x)) { - -} + +if (m.bind(this)(x)) + {} " `; @@ -103,8 +103,10 @@ function foo(x: number | string | Array): number { declare function f1(x: mixed): boolean %checks(typeof x === \"string\"); declare function f2(x: mixed): boolean %checks(Array.isArray(x)); declare var cond: boolean; + function foo(x: number | string | Array): number { var f = (cond ? f1 : f2); + if (f(x)) { return x.length; } else { @@ -143,6 +145,7 @@ function foo(x: string | Array): string { // guarantees that \`x\` here is an Array declare function is_string(x: mixed): boolean %checks(typeof x === \"string\"); declare function is_number(x: mixed): boolean %checks(typeof x === \"number\"); + function foo(x: string | Array): string { if (is_string(x)) { return x; @@ -184,16 +187,21 @@ function foo(x: mixed) { return 1; } declare function r(x: string): number; 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) { return 1; } + foo(dollars) || 0; + Number(dollars) || 0; " `; @@ -229,13 +237,14 @@ function f(_this: { m: ?Meeting }): string { // - preserving \`havoc\` semantics type Meeting = { organizer: ?Invitee; es: Array }; type Invitee = { fbid: number }; + function f(_this: { m: ?Meeting }): string { if (!_this.m) { return \"0\"; } - if (_this.m.es.some(a => a.fbid === 0)) { - - } + + if (_this.m.es.some(a => a.fbid === 0)) + {} return \"3\"; } " @@ -288,6 +297,7 @@ function foo(s: Array): string { // Sanity check: // - we should still be getting an error at the second return statement declare function pred(x: T): boolean; + function foo(s: Array): string { if (pred(s)) { return \"1\"; @@ -322,10 +332,12 @@ function foo(s: Array): string { // Sanity check: // - invalid calls at predicate positions declare function pred(x: T): boolean; + function foo(s: Array): string { if (1(s)) { return \"1\"; } + if ((pred + 1)(\"s\")) { return \"1\"; } @@ -357,6 +369,7 @@ function bar(x: string | Array): string { // error: both string and Array can flow to x declare function is_string(x: mixed): boolean %checks(typeof x === \"string\"); declare function is_number(x: mixed): boolean %checks(typeof x === \"number\"); + function bar(x: string | Array): string { if (is_number(x)) { return x; @@ -384,6 +397,7 @@ foo(3, 3); declare function foo(input: mixed, types: string | Array): boolean %checks(typeof input === \"string\" || Array.isArray(input)); + foo(3, 3); " `; @@ -412,6 +426,7 @@ function foo(x: string | Array): string { function pred(x: mixed): boolean %checks(typeof x === \"string\") { return typeof x === \"string\"; } + function foo(x: string | Array): string { if (pred(x)) { return x; diff --git a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap index 8f85dd8f..3f931d10 100644 --- a/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-inferred/__snapshots__/jsfmt.spec.js.snap @@ -34,13 +34,16 @@ function check(y): %checks(typeof y === \"string\") { return typeof y === \"number\"; } declare var y: number | boolean; + if (check(y)) { (y: number); } + function indirect_is_number(y): %checks { var y = 1; return typeof y === \"number\"; } + function bak(z: string | number): number { if (indirect_is_number(z)) { return z; @@ -72,6 +75,7 @@ function foo(x: string | Array): string { function multi_param(w, x, y, z): %checks { return typeof z === \"string\"; } + function foo(x: string | Array): string { if (multi_param(\"1\", \"2\", x, \"3\")) { return x; @@ -105,14 +109,17 @@ function dotAccess(head, create) { // @flow declare var key: string; declare var obj: { page: ?Object }; + if (dotAccess(obj)) { (obj.page: Object); } + function dotAccess(head, create) { const path = \"path.location\"; const stack = path.split(\".\"); do { const key = stack.shift(); + head = head[key] || create && (head[key] = {}); } while (stack.length && head); return head; @@ -143,9 +150,11 @@ function foo(x: string | Array): string { // Sanity check: this should fail, because the preficate function // checks \`y\` instead of \`x\`. declare var y: mixed; + function err(x): %checks { return typeof y === \"string\"; } + function foo(x: string | Array): string { if (err(x)) { return x; @@ -243,12 +252,15 @@ declare function from_two_strings(x: string, y: string): void; function is_string(y): %checks { return typeof y === \"string\"; } + function is_bool(y): %checks { return typeof y === \"boolean\"; } + function is_number(y): %checks { return typeof y === \"number\"; } + function foo(x: string | Array): string { if (is_string(x)) { return x; @@ -256,6 +268,7 @@ function foo(x: string | Array): string { return x.join(); } } + function bar(z: { f: string | Array }): string { if (is_string(z.f)) { return z.f; @@ -263,9 +276,11 @@ function bar(z: { f: string | Array }): string { return z.f.join(); } } + function is_number_or_bool(y): %checks { return is_number(y) || is_bool(y); } + function baz(z: string | number): number { if (is_number_or_bool(z)) { return z; @@ -273,9 +288,11 @@ function baz(z: string | number): number { return z.length; } } + function multi_param(w, x, y, z): %checks { return typeof z === \"string\"; } + function foo(x: string | Array): string { if (multi_param(\"1\", \"2\", \"3\", x)) { return x; @@ -283,11 +300,13 @@ function foo(x: string | Array): string { return x.join(); } } + function foo(a, b) { if (two_strings(a, b)) { from_two_strings(a, b); } } + function two_strings(x, y): %checks { return is_string(x) && is_string(y); } @@ -333,6 +352,7 @@ function foo(x: string | Array): string { return x.join(); } } + function is_string(x): %checks { return typeof x === \"string\"; } diff --git a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap index 8ef86288..831689cf 100644 --- a/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-parsing/__snapshots__/jsfmt.spec.js.snap @@ -20,9 +20,7 @@ function f6(x: mixed): %checks (x !== null) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow // Error: no return statement -function f6(x: mixed): %checks(x !== null) { - -} +function f6(x: mixed): %checks(x !== null) {} " `; @@ -93,19 +91,24 @@ declare function f(x: mixed): checks declare function f1(x: mixed): boolean; declare function f3(x: mixed): boolean %checks(x !== null); 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; + x; + checks => 123; type checks = any; declare function f(x: mixed): checks; + typeof x === null; " `; diff --git a/tests/private/__snapshots__/jsfmt.spec.js.snap b/tests/private/__snapshots__/jsfmt.spec.js.snap index fbef504c..c3709fef 100644 --- a/tests/private/__snapshots__/jsfmt.spec.js.snap +++ b/tests/private/__snapshots__/jsfmt.spec.js.snap @@ -20,7 +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 9354e0c7..ce71426a 100644 --- a/tests/promises/__snapshots__/jsfmt.spec.js.snap +++ b/tests/promises/__snapshots__/jsfmt.spec.js.snap @@ -55,12 +55,17 @@ function tes2(val: Map>) { // Promise.all supports iterables declare var pstr: Promise; 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); @@ -68,12 +73,17 @@ Promise.all([ pstr, pnum, true ]).then( ); } ); + Promise.all(); + Promise.all(0); + (Promise.all: Function); + function test(val: Iterable>) { const r: Promise> = Promise.all(val); } + function tes2(val: Map>) { const r: Promise> = Promise.all(val.values()); } @@ -103,12 +113,13 @@ async function testRace() { * which was previously an error due to Array\'s invariance and an improper * definition of Promise.all */ async function testAll() { - const x: Array> = [ ]; + const x: Array> = []; const y: Promise> = Promise.all(x); const z: Array = await y; } + async function testRace() { - const x: Array> = [ ]; + const x: Array> = []; const y: Promise = Promise.race(x); const z: ?string = await y; } @@ -427,12 +438,14 @@ new Promise( var b: string = num; } ); + new Promise((resolve, reject) => resolve(0)).then( function(num) { var a: number = num; var b: string = num; } ); + new Promise( function(resolve, reject) { resolve( @@ -449,6 +462,7 @@ new Promise( var b: string = num; } ); + new Promise( function(resolve, reject) { resolve( @@ -471,6 +485,7 @@ new Promise( var b: string = num; } ); + new Promise( function(resolve, reject) { if (Math.random()) { @@ -489,6 +504,7 @@ new Promise( var c: string = numOrStr; } ); + new Promise( function(resolve, reject) { reject(0); @@ -499,6 +515,7 @@ new Promise( var b: string = num; } ); + new Promise( function(resolve, reject) { reject( @@ -515,6 +532,7 @@ new Promise( var b: number = num; } ); + new Promise( function(resolve, reject) { if (Math.random()) { @@ -533,36 +551,42 @@ new Promise( var c: string = numOrStr; } ); + Promise.resolve(0).then( function(num) { var a: number = num; var b: string = num; } ); + Promise.resolve(Promise.resolve(0)).then( function(num) { var a: number = num; var b: string = num; } ); + Promise.resolve(Promise.resolve(Promise.resolve(0))).then( function(num) { var a: number = num; var b: string = num; } ); + Promise.reject(0).catch( function(num) { var a: number = num; var b: string = num; } ); + Promise.reject(Promise.resolve(0)).then( function(num) { var a: Promise = num; var b: number = num; } ); + Promise.resolve(0).then( function(num) { return \"asdf\"; @@ -573,6 +597,7 @@ Promise.resolve(0).then( var b: number = str; } ); + Promise.resolve(0).then( function(num) { return Promise.resolve(\"asdf\"); @@ -583,6 +608,7 @@ Promise.resolve(0).then( var b: number = str; } ); + Promise.resolve(0).then( function(num) { return Promise.resolve(Promise.resolve(\"asdf\")); @@ -593,6 +619,7 @@ Promise.resolve(0).then( var b: number = str; } ); + Promise.resolve(0).then( function(num) { throw \"str\"; @@ -603,6 +630,7 @@ Promise.resolve(0).then( var b: number = str; } ); + Promise.reject(0).catch( function(num) { return \"asdf\"; @@ -613,6 +641,7 @@ Promise.reject(0).catch( var b: number = str; } ); + Promise.reject(0).catch( function(num) { return Promise.resolve(\"asdf\"); @@ -623,6 +652,7 @@ Promise.reject(0).catch( var b: number = str; } ); + Promise.reject(0).catch( function(num) { return Promise.resolve(Promise.resolve(\"asdf\")); @@ -633,11 +663,8 @@ Promise.reject(0).catch( var b: number = str; } ); -Promise.resolve(0).catch( - function(err) { - - } -).then( + +Promise.resolve(0).catch(function(err) {}).then( function(num) { var a: number = num; var b: string = num; @@ -706,6 +733,7 @@ async function baz(): Promise { // error: \`Promise\` in return expr is the local binding // error: return type anno is a ref to the local binding class Promise {} + async function foo(x: boolean) { if (x) { return { bar: \"baz\" }; @@ -713,14 +741,19 @@ async function foo(x: boolean) { return null; } } + async function run() { console.log(await foo(true)); + console.log(await foo(false)); } + run(); + async function bar() { return Promise.resolve(0); } + async function baz(): Promise { return 0; } @@ -738,6 +771,7 @@ exports[`test resolve_void.js 1`] = ` // error // error (Promise.resolve(): Promise); + (Promise.resolve(undefined): Promise); " `; diff --git a/tests/pure_component/__snapshots__/jsfmt.spec.js.snap b/tests/pure_component/__snapshots__/jsfmt.spec.js.snap index 8c898746..af656e82 100644 --- a/tests/pure_component/__snapshots__/jsfmt.spec.js.snap +++ b/tests/pure_component/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,7 @@ var React = require(\"react\"); class C extends React.PureComponent { props: { x: number }; } + ; " `; diff --git a/tests/react/__snapshots__/jsfmt.spec.js.snap b/tests/react/__snapshots__/jsfmt.spec.js.snap index c3db9f23..cd21dd5c 100644 --- a/tests/react/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react/__snapshots__/jsfmt.spec.js.snap @@ -20,6 +20,7 @@ var AudienceInsightsContainer = React.createClass({ return ; } }); + module.exports = AudienceInsightsContainer; " `; @@ -157,7 +158,7 @@ var React = require(\"react\"); var Example = React.createClass({ propTypes: { arr: React.PropTypes.arrayOf(React.PropTypes.number).isRequired } }); -var ok_empty = ; +var ok_empty = ; var ok_numbers = ; var fail_not_array = ; var fail_mistyped_elems = ; @@ -185,12 +186,8 @@ var React = require(\"react\"); var Example = React.createClass({ propTypes: { func: React.PropTypes.func.isRequired } }); -var ok_void = { - -}}/>; -var ok_args = { - -}}/>; +var ok_void = {}}/>; +var ok_args = {}}/>; var ok_retval = 1}/>; var fail_mistyped = ; " diff --git a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap index 6d48d7f6..20a31780 100644 --- a/tests/react_functional/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react_functional/__snapshots__/jsfmt.spec.js.snap @@ -20,17 +20,20 @@ var Z = 0; // ok // error, expected React component import React from \"react\"; -function F(props: { foo: string }) { - -} + +function F(props: { foo: string }) {} + ; + ; + ; -function G(props: { foo: string | numner }) { - -} + +function G(props: { foo: string | numner }) {} + ; var Z = 0; + ; " `; diff --git a/tests/react_modules/__snapshots__/jsfmt.spec.js.snap b/tests/react_modules/__snapshots__/jsfmt.spec.js.snap index 061e9dcf..06a72f33 100644 --- a/tests/react_modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/react_modules/__snapshots__/jsfmt.spec.js.snap @@ -45,6 +45,7 @@ var Callsite = React.createClass({ ); } }); + module.exports = Callsite; " `; @@ -73,6 +74,7 @@ var Hello = React.createClass({ return
{this.props.name}
; } }); + module.exports = Hello; " `; @@ -125,6 +127,7 @@ class Callsite extends React.Component { ); } } + module.exports = Callsite; " `; @@ -156,6 +159,7 @@ class Hello extends React.Component<{}, Props, void> { return
{this.props.name}
; } } + module.exports = Hello; " `; diff --git a/tests/rec/__snapshots__/jsfmt.spec.js.snap b/tests/rec/__snapshots__/jsfmt.spec.js.snap index 0f0530a6..c9cc68ed 100644 --- a/tests/rec/__snapshots__/jsfmt.spec.js.snap +++ b/tests/rec/__snapshots__/jsfmt.spec.js.snap @@ -22,17 +22,22 @@ function identity
(val: A): Functor { /* @flow */ type F = { foo(x: A): F }; declare function foo(x: any): F; + ({ foo }: F); + function bar(y: F): F { return y; } + function bar1(y: F): F { return y; } + function bar2(y: F): F { return y; } type Functor = { map(f: (val: A) => B): Functor }; + function identity(val: A): Functor { return { map(f: (_: typeof val) => B): Functor { @@ -57,6 +62,7 @@ function id(x: Task): Task { return x; } type Task = { chain(next: (input: value) => Task): Task }; + function id(x: Task): Task { return x; } @@ -96,12 +102,18 @@ class P { } type Pstar = X | Pstar>; var p: P = new P(); + (p.x: string); var pstar: Pstar = 0; + (pstar: number); + pstar = p; + (pstar.x: string); + pstar = (new P(): P>); + (pstar.x: string); " `; @@ -150,25 +162,29 @@ class C extends B { } // S<*> = { y: S> } // Both S> and S<*> expand to { y: { y: ... }}. // error: number ~/~ string -var a = [ ]; +var a = []; + function bar() { - a = a.concat([ ]); + a = a.concat([]); } class A { x: A>; } 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 {} + ((new C(): C): D); " `; @@ -198,11 +214,13 @@ function bar(x: P): () => P { // () => P = () => () => { x: P } type I = () => I>; type J = () => J>; + function foo(x: I): J { return x; } type Q = { x: X }; type P = () => Q>; + function bar(x: P): () => P { return x; } @@ -231,10 +249,11 @@ function flatten(arrArg: NestedArray) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ type NestedArray = Array>; + function flatten(arrArg: NestedArray) { let arr = arrArg; while (true) { - arr = Array.prototype.concat.apply([ ], arr); + arr = Array.prototype.concat.apply([], arr); } } " diff --git a/tests/recheck/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/__snapshots__/jsfmt.spec.js.snap index 2a556a58..45011f7d 100644 --- a/tests/recheck/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,9 @@ module.exports = foo; function foo(x: number): string { return 5; } + foo(0); + module.exports = foo; " `; @@ -25,6 +27,7 @@ module.exports = foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow const foo = require(\"./a1\"); + module.exports = foo(\"\"); " `; @@ -38,6 +41,7 @@ const five = require(\'./a2\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow const five = require(\"./a2\"); + (five + five: string); " `; @@ -57,6 +61,7 @@ class C { class E { x: C; } + module.exports = { C, E }; " `; @@ -74,15 +79,18 @@ module.exports = { C, D }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import { C, E } from \"./b0\"; + function foo() { return C; } + function bar() { return E; } let X = foo(); class F extends X {} class D extends F {} + module.exports = { C, D }; " `; @@ -106,6 +114,7 @@ import { C, D } from \"./b2\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import { C, D } from \"./b2\"; + (new D(): C); " `; @@ -116,9 +125,7 @@ exports[`test c1.js 1`] = ` export function foo(props: { x: number }) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow -export function foo(props: { x: number }) { - -} +export function foo(props: { x: number }) {} " `; @@ -148,6 +155,7 @@ bar({ x: 0 }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import { bar } from \"./c2\"; + bar({ x: 0 }); " `; @@ -213,6 +221,7 @@ const f = (): Action => { return { type: \"FOO\" }; }; import { LIFE } from \"./e1\"; + (LIFE: 42); " `; @@ -235,6 +244,7 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; + module.exports = { a, b, c }; " `; @@ -247,6 +257,7 @@ var { a, b, c } = require(\'./f1\'); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var { a, b, c } = require(\"./f1\"); + (c: { x: number }); " `; @@ -273,6 +284,7 @@ module.exports = { D }; // @flow import { C } from \"./g1\"; class D extends C {} + module.exports = { D }; " `; @@ -288,6 +300,7 @@ import { D } from \'./g2\'; // @flow import { C } from \"./g1\"; import { D } from \"./g2\"; + (new D(): C); " `; diff --git a/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap index 66ae79e5..6b838f34 100644 --- a/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1a/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,9 @@ module.exports = foo; function foo(x: number): number { return 5; } + foo(0); + module.exports = foo; " `; diff --git a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap index 58834809..9fe20896 100644 --- a/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1b/__snapshots__/jsfmt.spec.js.snap @@ -11,15 +11,18 @@ module.exports = { C, D }; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow import { C, E } from \"./b0\"; + function foo() { return C; } + function bar() { return E; } let X = bar(); class F extends X {} class D extends F {} + module.exports = { C, D }; " `; diff --git a/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap index 6c3f470b..d0977560 100644 --- a/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1e/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,7 @@ const f = (): Action => { return { type: \"QUX\" }; }; import { LIFE } from \"./e1\"; + (LIFE: 42); " `; diff --git a/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap index 67d680d1..8fc7eff8 100644 --- a/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp1f/__snapshots__/jsfmt.spec.js.snap @@ -16,6 +16,7 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: S; + module.exports = { a, b, c }; " `; diff --git a/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap index 53e7ab99..d04b23f4 100644 --- a/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2a/__snapshots__/jsfmt.spec.js.snap @@ -11,7 +11,9 @@ module.exports = foo; function foo(x: number): number { return 5; } + foo(\"\"); + module.exports = foo; " `; diff --git a/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap index 66607eac..5c9820b9 100644 --- a/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2b/__snapshots__/jsfmt.spec.js.snap @@ -13,6 +13,7 @@ class C { class E extends C { x: C; } + module.exports = { C, E }; " `; diff --git a/tests/recheck/tmp2c/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2c/__snapshots__/jsfmt.spec.js.snap index c6b4ace1..6a1836f4 100644 --- a/tests/recheck/tmp2c/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2c/__snapshots__/jsfmt.spec.js.snap @@ -4,8 +4,6 @@ exports[`test c1.js 1`] = ` export function foo(props: { y: number }) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow -export function foo(props: { y: number }) { - -} +export function foo(props: { y: number }) {} " `; diff --git a/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap index a0e8a11d..66d9e0ad 100644 --- a/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp2f/__snapshots__/jsfmt.spec.js.snap @@ -16,6 +16,7 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; + module.exports = { a, b, c }; " `; diff --git a/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap index 390a9faf..3d91b708 100644 --- a/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp3e/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,7 @@ const f = (): Action => { return { type: \"QUX\" }; }; import { LIFE } from \"./e1\"; + (LIFE: 0); " `; diff --git a/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap index a5b3f715..aa5165df 100644 --- a/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp3f/__snapshots__/jsfmt.spec.js.snap @@ -16,6 +16,7 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; + module.exports = { a, b, c: a }; " `; diff --git a/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap b/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap index d65ea4c7..287d23f1 100644 --- a/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap +++ b/tests/recheck/tmp4f/__snapshots__/jsfmt.spec.js.snap @@ -16,6 +16,7 @@ type S = { x: string }; declare var a: T; declare var b: S; declare var c: T; + module.exports = { a, b, c: b }; " `; diff --git a/tests/record/__snapshots__/jsfmt.spec.js.snap b/tests/record/__snapshots__/jsfmt.spec.js.snap index 24ac7b51..0661c99a 100644 --- a/tests/record/__snapshots__/jsfmt.spec.js.snap +++ b/tests/record/__snapshots__/jsfmt.spec.js.snap @@ -37,13 +37,18 @@ var o3: {[key: AnyKey]: number} = { foo: 0 }; // error: qux not found type Key1 = \"foo\" | \"bar\"; var o1: { [key: Key1]: number } = { foo: 0, bar: \"\" }; + o1.foo; + o1.qux; + o1.toString(); type R = { foo: any; bar: any }; type Key2 = $Keys; 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 2c362b85..aa9bb5ce 100644 --- a/tests/refi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refi/__snapshots__/jsfmt.spec.js.snap @@ -95,9 +95,9 @@ var tests = [ } }, function() { - if (x == null) { - - } else { + if (x == null) + {} +else { var y: string = x; } }, @@ -107,22 +107,21 @@ var tests = [ var y: string = x; }, function() { - if (!(x != null)) { - - } else { + if (!(x != null)) + {} +else { var y: string = x; } }, function() { - if (x != null) { - - } + if (x != null) + {} var y: string = x; }, function() { - if (x != null) { - - } else { + if (x != null) + {} +else { var y: string = x; } }, @@ -416,34 +415,39 @@ 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 { + + if (x.p == null) + {} +else { var y: string = x.p; } }, 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 { + + if (!(x.p != null)) + {} +else { var y: string = x.p; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; + if (x.p != null) { alert(\"\"); var y: string = x.p; @@ -451,6 +455,7 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; + if (x.p != null) { x.p = null; var y: string = x.p; @@ -458,16 +463,17 @@ var tests = [ }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { - - } + + if (x.p != null) + {} var y: string = x.p; }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p != null) { - - } else { + + if (x.p != null) + {} +else { var y: string = x.p; } }, @@ -481,6 +487,7 @@ var tests = [ }, function() { var x: { p: string | string[] } = { p: [ \"xxx\" ] }; + if (Array.isArray(x.p)) { var y: string[] = x.p; } else { @@ -489,139 +496,170 @@ var tests = [ }, 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 { + + 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\") { - - } + if (x === \"a\") + {} + (x: \"b\"); }, function(x: mixed) { - if (typeof x.bar === \"string\") { - - } + if (typeof x.bar === \"string\") + {} + (x: string & number); }, function() { let x: { foo: ?string } = { foo: null }; + if (!x.foo) { - if (false) { - - } + if (false) + {} + x.foo = \"foo\"; } + (x.foo: string); }, function() { let x: { foo: ?string } = { foo: null }; + if (!x.foo) { - while (false) { - - } + 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++) { - - } + 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); } } @@ -680,34 +718,45 @@ function try_scope_catch(x: string | number) { function block_scope(x: string | number) { { let x; + x = \"\"; } + (x: string); } + 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); } + function try_scope_catch(x: string | number) { try { x = \"\"; } catch (e) { let x; + x = \"\"; } + (x: string); } " @@ -818,34 +867,39 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; + if (x != null) { var y: string = x; } }, function() { var x: ?string = \"xxx\"; - if (x == null) { - - } else { + + if (x == null) + {} +else { var y: string = x; } }, function() { var x: ?string = \"xxx\"; + if (x == null) return; var y: string = x; }, function() { var x: ?string = \"xxx\"; - if (!(x != null)) { - - } else { + + if (!(x != null)) + {} +else { var y: string = x; } }, function() { var x: ?string = \"xxx\"; + if (x != null) { alert(\"\"); var y: string = x; @@ -853,16 +907,17 @@ var paths = [ }, function() { var x: ?string = \"xxx\"; - if (x != null) { - - } + + if (x != null) + {} var y: string = x; }, function() { var x: ?string = \"xxx\"; - if (x != null) { - - } else { + + if (x != null) + {} +else { var y: string = x; } }, @@ -876,6 +931,7 @@ var paths = [ }, function() { var x: string | string[] = [ \"xxx\" ]; + if (Array.isArray(x)) { var y: string[] = x; } else { @@ -884,6 +940,7 @@ var paths = [ }, function() { var x: ?string = null; + if (!x) { x = \"xxx\"; } @@ -1072,91 +1129,104 @@ 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 { + + if (x == null) + {} +else { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p == null) { - - } else { + + if (x.p == null) + {} +else { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q == null) { - - } else { + + if (x.p.q == null) + {} +else { var y: string = x.p.q; } }, 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 { + + if (x === null) + {} +else { var y: string | void = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === null) { - - } else { + + if (x.p === null) + {} +else { var y: string | void = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === null) { - - } else { + + if (x.p.q === null) + {} +else { var y: string | void = x.p.q; } } @@ -1303,11 +1373,13 @@ function foo(a, b, c) { return; } } + function exhaustion1(x): number { var foo; switch (x) { case 0: case 1: + foo = 3; break; default: @@ -1315,14 +1387,17 @@ function exhaustion1(x): number { } return foo; } + function exhaustion2(x, y): number { var foo; switch (x) { case 0: + if (y) { break; } case 1: + foo = 3; break; default: @@ -1330,11 +1405,13 @@ function exhaustion2(x, y): number { } return foo; } + function exhaustion3(x): number { let foo = null; switch (x) { case 0: case 1: + foo = 3; break; default: @@ -1498,91 +1575,104 @@ 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 { + + if (typeof x != \"string\") + {} +else { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p != \"string\") { - - } else { + + if (typeof x.p != \"string\") + {} +else { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q != \"string\") { - - } else { + + if (typeof x.p.q != \"string\") + {} +else { var y: string = x.p.q; } }, 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 { + + if (typeof x !== \"string\") + {} +else { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (typeof x.p !== \"string\") { - - } else { + + if (typeof x.p !== \"string\") + {} +else { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (typeof x.p.q !== \"string\") { - - } else { + + if (typeof x.p.q !== \"string\") + {} +else { var y: string = x.p.q; } } @@ -1707,49 +1797,56 @@ 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 { + + if (x === undefined || x === null) + {} +else { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === undefined || x.p === null) { - - } else { + + if (x.p === undefined || x.p === null) + {} +else { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === undefined || x.p.q === null) { - - } else { + + if (x.p.q === undefined || x.p.q === null) + {} +else { var y: string = x.p.q; } } @@ -1862,49 +1959,56 @@ 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 { + + if (x === void 0 || x === null) + {} +else { var y: string = x; } }, function() { var x: { p: ?string } = { p: \"xxx\" }; - if (x.p === void 0 || x.p === null) { - - } else { + + if (x.p === void 0 || x.p === null) + {} +else { var y: string = x.p; } }, function() { var x: { p: { q: ?string } } = { p: { q: \"xxx\" } }; - if (x.p.q === void 0 || x.p.q === null) { - - } else { + + if (x.p.q === void 0 || x.p.q === null) + {} +else { var y: string = x.p.q; } } diff --git a/tests/refinements/__snapshots__/jsfmt.spec.js.snap b/tests/refinements/__snapshots__/jsfmt.spec.js.snap index 74220dc5..ac4d4eb4 100644 --- a/tests/refinements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/refinements/__snapshots__/jsfmt.spec.js.snap @@ -37,21 +37,25 @@ 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) { while (x = x.parent) { x.doStuff(); } } + function bar1(x: ?Bar) { while (x = x.parent) { x.doStuff(); } } + function bar2(x: Bar) { var y = x; while (y = y.parent) { @@ -137,11 +141,14 @@ function foo(x: ?boolean) { if (x === false) { return; } + if (x === true) { return; } + x[0]; } + function bar(x: ?boolean) { if (x !== true) { if (x !== false) { @@ -149,10 +156,12 @@ function bar(x: ?boolean) { } } } + function baz(x: ?boolean) { if (100 * false) { return; } + if (false * 100) { return; } @@ -197,14 +206,15 @@ function testLiteralProperty(a: A) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow type A = { \"b_c\": ?string }; -function stuff(str: string) { - -} + +function stuff(str: string) {} + function testProperty(a: A) { if (a.b_c) { stuff(a.b_c); } } + function testLiteralProperty(a: A) { if (a[\"b_c\"]) { stuff(a[\"b_c\"]); @@ -284,6 +294,7 @@ type Name = { kind: \"Name\"; value: string; type: void }; type ListType = { kind: \"ListType\"; type: Type }; type NonNullType = { kind: \"NonNullType\"; type: Name | ListType | BadType }; type BadType = {}; + function getTypeASTName(typeAST: Type): string { if (!typeAST.type) throw new Error(\"Must be wrapping type\"); @@ -304,6 +315,7 @@ let tests = [ }, function() { type T = { foo: Object; bar: string } | { baz: string; quux: string }; + function testAlwaysTruthyProp(t: T) { if (t.foo) { (t.bar: string); @@ -311,6 +323,7 @@ let tests = [ (t.quux: string); } } + function testSometimesTruthyProp(t: T) { if (t.bar) { (t.foo: Object); @@ -369,33 +382,29 @@ let tests = [ // ok let tests = [ function(x: string, y: number) { - if (x == y) { - - } - if (x === y) { - - } + if (x == y) + {} + + if (x === y) + {} }, function(x: string) { - if (x == undefined) { - - } - if (x == void 0) { - - } + if (x == undefined) + {} + + if (x == void 0) + {} }, function(x: string) { - if (x == null) { - - } + if (x == null) + {} }, function(x: { y: \"foo\" } | { y: \"bar\" }) { - if (x.y == 123) { - - } - if (x.y === 123) { - - } + if (x.y == 123) + {} + + if (x.y === 123) + {} } ]; " @@ -419,12 +428,15 @@ function foo2(x: ?Class): string { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class Foo { foo: string } + function foo0(x: ?string): string { return x && x || \"\"; } + function foo1(x: ?Foo): string { return x && x.foo || \"\"; } + function foo2(x: ?Class): string { return x && new x().foo || \"\"; } @@ -492,18 +504,23 @@ 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(); } } + function bar(x: Object) { x.y(); + if (x.hasOwnProperty(\"y\")) { x.y(); } + if (x.hasOwnProperty(\"z\")) { x.z(); } @@ -633,24 +650,30 @@ function def_assign_setprop_nohavoc(obj: Obj, obj2: Obj2) { // doesn\'t clear refi of .p // still ok type Obj = { p: number | string }; -function f() { - -} + +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; @@ -658,6 +681,7 @@ function def_assign_within_if(b: boolean, obj: Obj) { } var y: number = obj.p; } + function def_assign_within_while(b: boolean, obj: Obj) { while (b) { obj.p = 10; @@ -665,6 +689,7 @@ function def_assign_within_while(b: boolean, obj: Obj) { } var y: number = obj.p; } + function def_assign_within_do(b: boolean, obj: Obj) { do { obj.p = 10; @@ -672,20 +697,25 @@ function def_assign_within_do(b: boolean, obj: Obj) { } while (b); var y: number = obj.p; } + 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; } + function def_assign_within_for(b: boolean, obj: Obj) { for (; b; ) { obj.p = 10; @@ -694,8 +724,10 @@ function def_assign_within_for(b: boolean, obj: Obj) { 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; } @@ -783,14 +815,17 @@ function foo1(o: { x: number }) { o.x; } } + function foo2(o: { x: number }) { if (o.p2) { o.p2.x; } } + function foo3(o: { x: number }) { o.p3.x; } + function foo4(o: $Exact<{ x: number }>) { if (o.p4) { o.p4.x; @@ -798,44 +833,46 @@ function foo4(o: $Exact<{ x: number }>) { o.p4.x; } } + function foo5() { const o = {}; + _foo5(); + if (o.p) { o.p(); } + function _foo5() { - o.p = function() { - - }; + o.p = function() {}; } } + function foo6(o: mixed) { - if (o.bar) { - - } + if (o.bar) + {} } + 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\") { - - } + 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\") + {} } + function foo8(o: { p: mixed }) { - if (o.p && o.p.q) { - - } - if (o.p && o.p.q && o.p.q.r) { - - } + if (o.p && o.p.q) + {} + + if (o.p && o.p.q && o.p.q.r) + {} } " `; @@ -986,110 +1023,134 @@ function arr0(x: mixed) { // error // error, mixed // error -function takesNumber(x: number) { - -} -function takesString(x: string) { - -} +function takesNumber(x: number) {} + +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); } } + 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); } } + 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); } } + function fun(x: mixed) { if (typeof x === \"function\") { takesString(x); } } + function obj0(x: mixed) { if (typeof x === \"object\") { takesString(x); } } + function obj1(x: mixed) { if (Array.isArray(x)) { takesString(x); } } + function undef(x: mixed) { if (typeof x === \"undefined\") { takesString(x); } } + function null_(x: mixed) { if (x === null) { takesString(x); } } + function maybe(x: mixed) { if (x == null) { takesString(x); } } + function true_(x: mixed) { if (x === true) { takesString(x); } } + function false_(x: mixed) { if (x === false) { takesString(x); } } + function obj2(x: mixed) { if (typeof x === \"object\") { (x: { [key: string]: mixed } | null); + if (x !== null) { (x[\"foo\"]: string); } } } + 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); } } + function arr0(x: mixed) { if (Array.isArray(x)) { takesString(x[0]); @@ -1174,15 +1235,18 @@ function foo(x: ?boolean) { x++; } } + function bar(x: ?number) { if (!x) { x[0]; } } + function baz(x: ?number) { if (x === null || x === undefined) { return; } + if (!x) { x[0]; } @@ -1234,6 +1298,7 @@ function null_bogus_comparison() { if (100 * null) { return; } + if (null * 100) { return; } @@ -1384,12 +1449,14 @@ let tests = [ if (x === 0) { (x: void); } + (x: 0); }, function(x: number) { if (x !== 0) { (x: 0); } + (x: void); }, function(x: 1): 0 { @@ -1408,6 +1475,7 @@ let tests = [ if (x !== 1) { (x: 0); } + (x: 0); }, function(x: 0): number { @@ -1419,10 +1487,13 @@ let tests = [ function(x: 0 | 1) { if (x === 0) { (x: 0); + (x: void); } + if (x === 1) { (x: 1); + (x: void); } }, @@ -1440,14 +1511,12 @@ let tests = [ } }, function(num: number, obj: { foo: number }) { - if (num === obj.bar) { - - } + if (num === obj.bar) + {} }, function(num: number, obj: { [key: string]: number }) { - if (num === obj.bar) { - - } + if (num === obj.bar) + {} }, function(n: number): Mode { if (n !== 0 && n !== 1 && n !== 2) { @@ -1466,10 +1535,12 @@ let tests = [ function(mode: Mode) { switch (mode) { case 0: + (mode: 0); break; case 1: case 2: + (mode: 1 | 2); break; } @@ -1579,54 +1650,63 @@ function a(x: { [key: string]: ?string }, y: string): string { } return \"\"; } + function b(x: { y: { [key: string]: ?string } }, z: string): string { if (x.y[z]) { return x.y[z]; } return \"\"; } + function c(x: { [key: string]: ?string }, y: { z: string }): string { if (x[y.z]) { return x[y.z]; } return \"\"; } + function d(x: { y: { [key: string]: ?string } }, a: { b: string }): string { if (x.y[a.b]) { return x.y[a.b]; } return \"\"; } + function a_array(x: Array, y: number): string { if (x[y]) { return x[y]; } return \"\"; } + function b_array(x: { y: Array }, z: number): string { if (x.y[z]) { return x.y[z]; } return \"\"; } + function c_array(x: Array, y: { z: number }): string { if (x[y.z]) { return x[y.z]; } return \"\"; } + function d_array(x: { y: Array }, a: { b: number }): string { if (x.y[a.b]) { return x.y[a.b]; } return \"\"; } + 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\"; @@ -1634,6 +1714,7 @@ function c2(x: { [key: string]: ?string }, y: { z: string }): string { } return \"\"; } + function c3( x: { [key: string]: ?string }, y: { z: string; a: string } ): string { @@ -1744,35 +1825,42 @@ 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; } + function bar(b) { var x = (b ? 0 : null); do { var y: string = x; + x = false; } while (x === null); var z: string = x; } -function maybe_throw() { - -} + +function maybe_throw() {} + 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; } + function corge(b) { for ( var x = (b ? 0 : null); @@ -1783,26 +1871,28 @@ function corge(b) { } var z: string = x; } + function waldo() { var o = {}; var x = false; + for (x in o) { x = 0; } var z: number = x; } + function global_in_conditional0(x: number) { if (x != 0) { - if (BAZ) { - - } + if (BAZ) + {} } } + function global_in_conditional2(x: number) { for (var i = 0; i < 100; i++) { - if (BAZ) { - - } + if (BAZ) + {} } } " @@ -1964,12 +2054,14 @@ let tests = [ if (x === \"foo\") { (x: void); } + (x: \"foo\"); }, function(x: string) { if (x !== \"foo\") { (x: \"foo\"); } + (x: void); }, function(x: \"bar\"): \"foo\" { @@ -1988,6 +2080,7 @@ let tests = [ if (x !== \"bar\") { (x: \"foo\"); } + (x: \"foo\"); }, function(x: \"foo\"): string { @@ -1999,10 +2092,13 @@ let tests = [ function(x: \"foo\" | \"bar\") { if (x === \"foo\") { (x: \"foo\"); + (x: void); } + if (x === \"bar\") { (x: \"bar\"); + (x: void); } }, @@ -2022,17 +2118,16 @@ let tests = [ } }, function(str: string, obj: { foo: string }) { - if (str === obj.bar) { - - } + if (str === obj.bar) + {} }, function(str: string, obj: { [key: string]: string }) { - if (str === obj.bar) { - - } + if (str === obj.bar) + {} }, function(str: string): Mode { var ch = str[0]; + if (ch !== \"a\" && ch !== \"b\" && ch !== \"c\") { throw new Error(\"Wrong string passed\"); } @@ -2049,10 +2144,12 @@ let tests = [ function(mode: Mode) { switch (mode) { case \"a\": + (mode: \"a\"); break; case \"b\": case \"c\": + (mode: \"b\" | \"c\"); break; } @@ -2068,6 +2165,7 @@ let tests = [ if (x === \`foo\`) { return x; } + if (\`foo\` === x) { return x; } @@ -2207,6 +2305,7 @@ function foo(text: string | number): string { return \"wat\"; } } + function bar(text: string | number): string { switch (typeof text) { case \"string\": @@ -2215,6 +2314,7 @@ function bar(text: string | number): string { return text++ + \"\"; } } + function baz1(text: string | number): string { switch (typeof text) { case \"number\": @@ -2224,6 +2324,7 @@ function baz1(text: string | number): string { return \"wat\"; } } + function baz2(text: string | number): string { switch (typeof text) { case \"string\": @@ -2233,6 +2334,7 @@ function baz2(text: string | number): string { return \"wat\"; } } + function corge(text: string | number | Array): string { switch (typeof text) { case \"object\": @@ -2558,6 +2660,7 @@ let tests = [ type Type = Name | ListType; type Name = { kind: \"Name\"; value: string }; type ListType = { kind: \"ListType\"; name: string }; + function getTypeASTName(typeAST: Type): string { if (typeAST.kind === \"Name\") { return typeAST.value; @@ -2567,6 +2670,7 @@ function getTypeASTName(typeAST: Type): string { } import type { ASTNode } from \"./ast_node\"; var Node = require(\"./node1\"); + function foo(x: ASTNode) { if (x.kind === Node) { return x.prop1.charAt(0); @@ -2578,22 +2682,26 @@ type Orange = { kind: \"Fruit\"; taste: \"Good\" }; type Broccoli = { kind: \"Veg\"; taste: \"Bad\"; raw: \"No\" }; type Carrot = { kind: \"Veg\"; taste: \"Good\"; raw: \"Maybe\" }; type Breakfast = Apple | Orange | Broccoli | Carrot; + function bar(x: Breakfast) { if (x.kind === \"Fruit\") { (x.taste: \"Good\"); } else (x.raw: \"No\"); } + function qux(x: Breakfast) { if (x.taste === \"Good\") { (x.raw: \"Yes\" | \"No\"); } } + function list(n) { if (n > 0) return { kind: \"cons\", next: list(n - 1) }; return { kind: \"nil\" }; } + function length(l) { switch (l.kind) { case \"cons\": @@ -2602,6 +2710,7 @@ function length(l) { return 0; } } + function check(n) { if (n >= 0) return n === length(list(n)); @@ -2611,6 +2720,7 @@ var EnumKind = { A: 1, B: 2, C: 3 }; type A = { kind: 1; A: number }; type B = { kind: 2; B: number }; type C = { kind: 3; C: number }; + function kind(x: A | B | C): number { switch (x.kind) { case EnumKind.A: @@ -2621,9 +2731,11 @@ function kind(x: A | B | C): number { return x.A; } } + kind({ kind: EnumKind.A, A: 1 }); type Citizen = { citizen: true }; type NonCitizen = { citizen: false; nationality: string }; + function nationality(x: Citizen | NonCitizen) { if (x.citizen) return \"Shire\"; @@ -2637,20 +2749,18 @@ let tests = [ } }, function test8(x: { foo: { bar: 1 } }) { - if (x.foo.bar === 1) { - - } - if (x.fooTypo.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()) { - - } + if (x.kind === null.toString()) + {} + + if ({ kind: 1 }.kind === null.toString()) + {} }, function( x: Array, @@ -2661,46 +2771,56 @@ let tests = [ s: Function, t: () => void ) { - if (x.length === 0) { - - } + if (x.length === 0) + {} + if (x.legnth === 0) { (x.legnth: number); + (x.legnth: string); } - if (y.length === 0) { - - } + + if (y.length === 0) + {} + if (y.legnth === 0) { (y.legnth: number); + (y.legnth: string); } - if (z.toString === 0) { - - } + + if (z.toString === 0) + {} + if (z.toStirng === 0) { (z.toStirng: number); + (z.toStirng: string); } - if (q.valueOf === 0) { - - } + + 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.call === 0) + {} + if (s.calll === 0) { (t.calll: empty); } - if (t.call === 0) { - - } + + if (t.call === 0) + {} + if (t.calll === 0) { (t.calll: empty); } @@ -2709,18 +2829,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); } @@ -2728,48 +2853,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; } }, @@ -2778,6 +2918,7 @@ let tests = [ ) { if (x.foo === num) { x.y; + x.z; } } @@ -2814,12 +2955,15 @@ function handleStatus(status: Success | Error) { import { SUCCESS, ERROR } from \"./constants\"; type Success = { type: typeof SUCCESS; message: string }; 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}\`); } } @@ -2909,48 +3053,60 @@ function foo(x: boolean | number) { x[0]; } } + function bar(): number { var x = null; + if (typeof x === \"object\") { return x; } return 0; } + 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); } } + function anyfun(x: number | Function): number { if (typeof x === \"function\") { return 0; } return x; } + function anyobj(x: number | Object): number { if (typeof x === \"object\") { return 0; } return x; } + function testInvalidValue(x: mixed) { if (typeof x === \"foo\") { return 0; } } + function testTemplateLiteral(x: string | number) { if (typeof x === \`string\`) { return x.length; } } + function testInvalidTemplateLiteral(x: string | number) { if (typeof x === \`foo\`) { return 0; @@ -3050,69 +3206,82 @@ function undef_var(x: ?number) { var y = x * 1000; } } + function undef_var_rev(x: ?number) { - if (x === null || x === undefined) { - - } else { + if (x === null || x === undefined) + {} +else { var y = x * 1000; } } + function undef_prop(x: { x: ?number }) { if (x.x !== null && x.x !== undefined) { var y = x.x * 1000; } } + function undef_prop_rev(x: { x: ?number }) { - if (x.x === null || x.x === undefined) { - - } else { + if (x.x === null || x.x === undefined) + {} +else { var y = x.x * 1000; } } + function undef_var_fail(x: ?number) { if (x !== undefined) { var y = x * 1000; } } + function undef_var_fail_rev(x: ?number) { - if (x === undefined) { - - } else { + if (x === undefined) + {} +else { var y = x * 1000; } } + function undef_prop_fail(x: { x: ?number }) { if (x.x !== undefined) { var y = x.x * 1000; } } + function undef_prop_fail_rev(x: { x: ?number }) { - if (x.x === undefined) { - - } else { + if (x.x === undefined) + {} +else { var y = x.x * 1000; } } + function undef_unreachable(x: number) { if (x === undefined) { var y = x * 1000; } + if (x == undefined) { var z = x * 1000; } } + function undef_var_nonstrict(x: ?number, y: ?number) { if (x != undefined) { var a = x * 1000; } + if (y == undefined) { var b = y * 1000; } } + function undef_bogus_comparison() { if (100 * undefined) { return; } + if (undefined * 100) { return; } @@ -3148,16 +3317,19 @@ function baz(x: ?thing) { // error on number // error on number type thing = number | boolean; + function foo(x: thing) { if (x === true) { x[0]; } } + function bar(x: thing) { if (x !== true && x !== false) { x[0]; } } + function baz(x: ?thing) { if (x && x !== true) { x[0]; @@ -3269,83 +3441,98 @@ function void_var(x: ?number) { var y = x * 1000; } } + function void_var_rev(x: ?number) { - if (x === null || x === void 0) { - - } else { + if (x === null || x === void 0) + {} +else { var y = x * 1000; } } + function void_pro(x: { x: ?number }) { if (x.x !== null && x.x !== void 0) { var y = x.x * 1000; } } + function void_pro_rev(x: { x: ?number }) { - if (x.x === null || x.x === void 0) { - - } else { + if (x.x === null || x.x === void 0) + {} +else { var y = x.x * 1000; } } + function void_var_fail(x: ?number) { if (x !== void 0) { var y = x * 1000; } } + function void_var_fail_rev(x: ?number) { - if (x === void 0) { - - } else { + if (x === void 0) + {} +else { var y = x * 1000; } } + function void_pro_fail(x: { x: ?number }) { if (x.x !== void 0) { var y = x.x * 1000; } } + function void_pro_fail_rev(x: { x: ?number }) { - if (x.x === void 0) { - - } else { + if (x.x === void 0) + {} +else { var y = x.x * 1000; } } + function void_var_side_effect(x: ?number) { if (x !== null && x !== void (x * 1000)) { var y = x * 1000; } } + function void_var_side_effect_rev(x: ?number) { - if (x === null || x === void (x * 1000)) { - - } else { + if (x === null || x === void (x * 1000)) + {} +else { var y = x * 1000; } } + function void_prop_side_effect(x: { x: ?number }) { if (x.x !== null && x.x !== void (x.x * 1000)) { var y = x.x * 1000; } } + function void_prop_side_effect_rev(x: { x: ?number }) { - if (x.x === null || x.x === void (x.x * 1000)) { - - } else { + if (x.x === null || x.x === void (x.x * 1000)) + {} +else { var y = x.x * 1000; } } + function void_bogus_comparison() { if (100 * void 0) { return; } + if (void 0 * 100) { return; } } + function void_redefined_undefined(x: ?number) { var undefined = \"foo\"; + if (x !== null && x !== void 0) { var y = x * 1000; } diff --git a/tests/replace/__snapshots__/jsfmt.spec.js.snap b/tests/replace/__snapshots__/jsfmt.spec.js.snap index 3fb9ae38..9a21d5fb 100644 --- a/tests/replace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/replace/__snapshots__/jsfmt.spec.js.snap @@ -6,9 +6,9 @@ function foo(x) { } foo(\"\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var a = 0; -function foo(x) { - -} + +function foo(x) {} + foo(\"\"); " `; diff --git a/tests/require/__snapshots__/jsfmt.spec.js.snap b/tests/require/__snapshots__/jsfmt.spec.js.snap index 76293e5b..38d00b5d 100644 --- a/tests/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/require/__snapshots__/jsfmt.spec.js.snap @@ -33,6 +33,7 @@ exports = {stringValue: \'\'}; // value will affect the exports object but re-binding it makes it useless and // does not affect the exports value. module.exports = { numberValue: 42 }; + exports = { stringValue: \"\" }; " `; @@ -74,9 +75,8 @@ function require() {} require(\"not a module name\"); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow -function require() { - -} +function require() {} + require(\"not a module name\"); " `; @@ -143,27 +143,35 @@ require.call(null, \"DoesNotExist\"); // template literals are ok... // error: but only if they have no expressions // require.call is allowed but circumverts Flow\'s static analysis -function takesANumber(num: number): void { - -} -function takesAString(str: string): void { - -} +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); + takesAString(B.numberValue); + require(\"C\"); + require(\"./D\"); var E = require(\"./E\"); var e_1: number = E.numberValue; + E.stringValue; var a = \"./E\"; + require(a); + require(\`./E\`); + require(\`\${\"./E\"}\`); + require.call(null, \"DoesNotExist\"); " `; diff --git a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap index be377ae3..e1641827 100644 --- a/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap +++ b/tests/requireLazy/__snapshots__/jsfmt.spec.js.snap @@ -85,13 +85,11 @@ requireLazy( ); var notA: Object = A; var notB: Object = B; + requireLazy(); -requireLazy( - [ nope ], - function() { - - } -); + +requireLazy([ nope ], function() {}); + requireLazy([ \"A\" ]); " `; diff --git a/tests/return/__snapshots__/jsfmt.spec.js.snap b/tests/return/__snapshots__/jsfmt.spec.js.snap index 1d07dd80..b0305283 100644 --- a/tests/return/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return/__snapshots__/jsfmt.spec.js.snap @@ -39,9 +39,7 @@ module.exports = C; //function fn(x:number) { return x; } //module.exports = fn; class C { - foo() { - - } + foo() {} bar() { return; } @@ -49,28 +47,33 @@ class C { return x; } } + function f(x): number { if (x > 1) { return 42; } } + function g(x): ?number { if (x > 1) { return 42; } } + function h(x): number { if (x > 1) { return 42; } return; } + function i(x): ?number { if (x > 1) { return 42; } return; } + module.exports = C; " `; @@ -100,6 +103,7 @@ function f(b) { return \"nope\"; } } + (f(true): void); " `; diff --git a/tests/return_new/__snapshots__/jsfmt.spec.js.snap b/tests/return_new/__snapshots__/jsfmt.spec.js.snap index 7b2b1d62..7b09eb9d 100644 --- a/tests/return_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/return_new/__snapshots__/jsfmt.spec.js.snap @@ -20,15 +20,16 @@ function Foo() { return {}; } var foo: number = new Foo(); + function Bar() { return 0; } var bar: number = new Bar(); -function Qux() { - -} + +function Qux() {} var qux: number = new Qux(); class A {} + function B() { return new A(); } @@ -54,8 +55,11 @@ module.exports = D; // error, new D is an object, D not in proto chain declare class D { constructor(): { x: number }; y: any } var d = new D(); + d.x = \"\"; + (new D(): D); + module.exports = D; " `; diff --git a/tests/seal/__snapshots__/jsfmt.spec.js.snap b/tests/seal/__snapshots__/jsfmt.spec.js.snap index a6fc1d18..c1fabc24 100644 --- a/tests/seal/__snapshots__/jsfmt.spec.js.snap +++ b/tests/seal/__snapshots__/jsfmt.spec.js.snap @@ -6,6 +6,7 @@ imp({ name: \"imp\" }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var imp = require(\"./obj_annot\"); + imp({ name: \"imp\" }); " `; @@ -25,7 +26,9 @@ module.exports = foo; function foo(param: { name: string }): number { return param.id; } + foo({ name: \"test\" }); + module.exports = foo; " `; diff --git a/tests/sealed/__snapshots__/jsfmt.spec.js.snap b/tests/sealed/__snapshots__/jsfmt.spec.js.snap index 95f2e939..3ef70937 100644 --- a/tests/sealed/__snapshots__/jsfmt.spec.js.snap +++ b/tests/sealed/__snapshots__/jsfmt.spec.js.snap @@ -13,12 +13,15 @@ module.exports = Bar; function Bar(x: number) { this.x = x; } + Bar.prototype.getX = function() { return this.x; }; + Bar.prototype.getY = function(): string { return this.y; }; + module.exports = Bar; " `; @@ -40,22 +43,24 @@ var export_o: { x:any; } = o; // awkward type cast module.exports = export_o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // awkward type cast -function Foo() { - -} +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 = \"...\"; + Foo.prototype = { m: function() { return false; } }; var export_o: { x: any } = o; + module.exports = export_o; " `; @@ -75,13 +80,18 @@ a.y = \'abc\'; // error, needs to be declared in Bar\'s constructor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // 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); + a.x = 123; + a.y = \"abc\"; + (a.getX(): number); + (a.getY(): string); " `; diff --git a/tests/shape/__snapshots__/jsfmt.spec.js.snap b/tests/shape/__snapshots__/jsfmt.spec.js.snap index 421bf828..454eda45 100644 --- a/tests/shape/__snapshots__/jsfmt.spec.js.snap +++ b/tests/shape/__snapshots__/jsfmt.spec.js.snap @@ -10,6 +10,7 @@ var y: $Shape = x; type Foo = { field: number }; var x: { field?: number } = {}; var y: $Shape = x; + (y.field: number); " `; diff --git a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap index a452a133..d9463026 100644 --- a/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/simple_arrays/__snapshots__/jsfmt.spec.js.snap @@ -28,7 +28,8 @@ function baz(i:number): string { return a[i]; } // annotations suffice to unblock the access constraint as well, so only // uncalled internal functions will not find a type error, which is acceptable // behavior as such functions are dead code. -var a = [ ]; +var a = []; + for (var i = 0; i < 10; ++i) { if (i % 2 == 0) { a[i] = 0; @@ -36,13 +37,17 @@ for (var i = 0; i < 10; ++i) { a[i] = \"\"; } } + function foo(i): string { return a[i]; } + function bar(i): string { return a[i]; } + bar(0); + function baz(i: number): string { return a[i]; } @@ -60,7 +65,8 @@ for (var i = 0; i < 10; ++i) { function foo(i: number): string { return a[i]; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ -var a = [ ]; +var a = []; + for (var i = 0; i < 10; ++i) { if (i % 2 == 0) { a[i] = 0; @@ -68,6 +74,7 @@ for (var i = 0; i < 10; ++i) { a[i] = \"\"; } } + function foo(i: number): string { return a[i]; } diff --git a/tests/singleton/__snapshots__/jsfmt.spec.js.snap b/tests/singleton/__snapshots__/jsfmt.spec.js.snap index 5a10d7fd..d56cd7d7 100644 --- a/tests/singleton/__snapshots__/jsfmt.spec.js.snap +++ b/tests/singleton/__snapshots__/jsfmt.spec.js.snap @@ -47,12 +47,14 @@ function veryOptimistic(isThisAwesome: true): boolean { } 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; + function bar(x: MyOwnBooleanLOL): false { if (x) { return x; @@ -60,9 +62,13 @@ function bar(x: MyOwnBooleanLOL): false { return !x; } } + bar(true); + bar(false); + bar(1); + function alwaysFalsy(x: boolean): false { if (x) { return !x; @@ -105,19 +111,25 @@ sort((x, y) => -1); function highlander(howMany: 1): number { return howMany; } + highlander(1); + highlander(2); type Foo = 1 | 2; + function bar(num: Foo): number { return num + 1; } + bar(1); + bar(2); + bar(3); type ComparatorResult = -1 | 0 | 1; -function sort(fn: (x: any, y: any) => ComparatorResult) { - -} + +function sort(fn: (x: any, y: any) => ComparatorResult) {} + sort((x, y) => -1); " `; @@ -133,8 +145,10 @@ type HasSpaces = \"foo bar\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ 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 39775bdf..4b09355d 100644 --- a/tests/spread/__snapshots__/jsfmt.spec.js.snap +++ b/tests/spread/__snapshots__/jsfmt.spec.js.snap @@ -33,9 +33,11 @@ function parseTimeframe(line: string): { begin: number; end: number } { function parseTimestamp(timestamp: string): number { return 0; } + function parseCounter(line: string): number { return 0; } + function parseGroup(lines: Array): { counter: number; begin: number; @@ -46,6 +48,7 @@ function parseGroup(lines: Array): { var timeframe = parseTimeframe(lines[1]); return { counter, ...timeframe, text: lines[2] }; } + function parseTimeframe(line: string): { begin: number; end: number } { var timestamps = line.split(\"-->\"); return { @@ -73,9 +76,9 @@ foo({foo: 42}); function foo(o) { bar({ ...o }); } -function bar(_: { foo: number }) { - -} + +function bar(_: { foo: number }) {} + foo({ foo: 42 }); " `; @@ -119,9 +122,8 @@ function test(...nums: Array) {} test(0, ...[1, 2, 3]); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ -function test(...nums: Array) { - -} +function test(...nums: Array) {} + test(0, ...[ 1, 2, 3 ]); " `; @@ -163,6 +165,7 @@ function test( // OK declare function map(obj: { [key: string]: Tv }, iterator: (obj: Tv) => TNext): Array; + function test(x: { kind: ?string }, kinds: { [key: string]: string }): Array<{ kind: ?string }> { @@ -201,16 +204,23 @@ for (var i = 0; i < 10; i++) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // error, p doesn\'t have \`abc\` yet var o = { foo: \"bar\" }; + o = { ...o }; + (o: { foo: string }); var p = { foo: \"bar\" }; + (p: { foo: string; abc: string }); + p = { ...p, abc: \"def\" }; + (p: { foo: string; abc: string }); var q = { foo: \"bar\" }; + for (var i = 0; i < 10; i++) { q = { ...q }; } + (q: { foo: string }); " `; @@ -230,6 +240,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 435e2ee7..c4d9eccf 100644 --- a/tests/statics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/statics/__snapshots__/jsfmt.spec.js.snap @@ -10,16 +10,17 @@ C.g(0); var x:number = C.x; C.x = 0;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class C { - static f(x: number) { - - } + static f(x: number) {} static x: string; } + C.g = function(x: string) { C.f(x); }; + C.g(0); var x: number = C.x; + C.x = 0; " `; @@ -31,12 +32,12 @@ C.g = function(x) { return x; }; var x:string = new C().f(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -function C() { - -} +function C() {} + C.prototype.f = function() { return C.g(0); }; + C.g = function(x) { return x; }; diff --git a/tests/strict/__snapshots__/jsfmt.spec.js.snap b/tests/strict/__snapshots__/jsfmt.spec.js.snap index fdc437ef..a789f71a 100644 --- a/tests/strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strict/__snapshots__/jsfmt.spec.js.snap @@ -14,13 +14,12 @@ class B extends A { foo(x: A): A { return x; } - bar(x) { - - } + bar(x) {} qux(x: X, y: Y): X { return x; } } + module.exports = B; " `; @@ -50,6 +49,7 @@ function f(x: number) { return x; } var x: string = f(0); + module.exports = f; " `; @@ -75,6 +75,7 @@ module.exports = o; //var o: {x: number;} = { x: 0 } var o = { x: 0 }; var x: string = o.x; + module.exports = o; " `; diff --git a/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap b/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap index c7ecb582..735c86ff 100644 --- a/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strict_requires/__snapshots__/jsfmt.spec.js.snap @@ -26,6 +26,7 @@ module.exports = o; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var o = { A: require(\"./A\"), ...require(\"./B\") }; + module.exports = o; " `; @@ -41,6 +42,7 @@ C.A = false; var C = require(\"./C\"); var x: number = C.foo; var y: string = C.A; + C.A = false; " `; diff --git a/tests/strings/__snapshots__/jsfmt.spec.js.snap b/tests/strings/__snapshots__/jsfmt.spec.js.snap index 3c0c0783..eed59f20 100644 --- a/tests/strings/__snapshots__/jsfmt.spec.js.snap +++ b/tests/strings/__snapshots__/jsfmt.spec.js.snap @@ -22,19 +22,33 @@ exports[`test strings.js 1`] = ` \'🐶\' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \"abc\"; + \"abc\"; + \"\'\"; + \"\\\"\"; + \"\\\"\"; + \"\\\\\\\"\"; + \"\'\"; + \"\'\"; + \"\\\\\'\"; + \"\'\\\"\"; + \"\'\\\"\"; + \"\\\\\"; + \"\\\\\"; + \"\\u0000\"; + \"🐶\"; " `; diff --git a/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap b/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap index 2cd01334..afecacb8 100644 --- a/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap +++ b/tests/structural_subtyping/__snapshots__/jsfmt.spec.js.snap @@ -18,7 +18,7 @@ var lengthTest4: IHasLength = true; // bool doesn\'t have length // number doesn\'t have length // bool doesn\'t have length interface IHasLength { length: number } -var lengthTest1: IHasLength = [ ]; +var lengthTest1: IHasLength = []; var lengthTest2: IHasLength = \"hello\"; var lengthTest3: IHasLength = 123; var lengthTest4: IHasLength = true; @@ -101,9 +101,11 @@ var propTest1: IHasXString = { x: \"hello\" }; var propTest2: IHasXString = { x: 123 }; var propTest3: IHasXString = {}; var propTest4: IHasXString = ({}: Object); + function propTest5(y: { [key: string]: string }) { (y: IHasXString); } + function propTest6(y: { [key: string]: number }) { (y: IHasXString); } diff --git a/tests/suggest/__snapshots__/jsfmt.spec.js.snap b/tests/suggest/__snapshots__/jsfmt.spec.js.snap index 3e4009b9..198c96a6 100644 --- a/tests/suggest/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suggest/__snapshots__/jsfmt.spec.js.snap @@ -9,6 +9,7 @@ module.exports = bar; function bar(w: number): number { return w; } + module.exports = bar; " `; @@ -27,11 +28,14 @@ module.exports = {foo:foo}; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ var bar = require(\"./lib\"); + function foo(z: number) { return bar(z); } var array = [ \"foo\", \"bar\" ]; + array; + module.exports = { foo: foo }; " `; diff --git a/tests/super/__snapshots__/jsfmt.spec.js.snap b/tests/super/__snapshots__/jsfmt.spec.js.snap index b68f8c17..53caf108 100644 --- a/tests/super/__snapshots__/jsfmt.spec.js.snap +++ b/tests/super/__snapshots__/jsfmt.spec.js.snap @@ -195,6 +195,7 @@ class D extends A { y: number; constructor() { this.y; + this.x; } } @@ -202,20 +203,27 @@ 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; } } @@ -231,7 +239,9 @@ class H extends A { super(); else super(); + this.y; + this.x; } } @@ -239,9 +249,7 @@ class I_ { constructor(leaked_this) { leaked_this.foo(); } - foo() { - - } + foo() {} } class I extends I_ { constructor() { @@ -252,11 +260,10 @@ class J__ {} class J_ extends J__ { constructor(closure_leaking_this) { closure_leaking_this(); + super(); } - foo() { - - } + foo() {} } class J extends J_ { constructor() { @@ -268,9 +275,7 @@ class K_ { constructor(closure_leaking_this) { this.closure_leaking_this = closure_leaking_this; } - foo() { - - } + foo() {} } class K extends K_ { constructor() { @@ -281,6 +286,7 @@ class K extends K_ { } ); var _this = this; + this.closure_leaking_this(); } } @@ -295,7 +301,9 @@ class L extends L_ { return x; } } + (new L_(): L_); + (new L(): L); class M_ { constructor() { @@ -307,7 +315,9 @@ class M extends M_ { return super(); } } + (new M_(): { foo: string }); + (new M(): { foo: string }); class N_ { constructor(): this { @@ -320,7 +330,9 @@ class N extends N_ { return super(); } } + (new N_(): N_); + (new N(): N); " `; @@ -336,6 +348,7 @@ class D { return 0; } } + module.exports = D; " `; @@ -367,15 +380,11 @@ class B extends A { // error, string !~> number // error, A doesn\'t have a doesntExist method class A { - constructor(x: number) { - - } + constructor(x: number) {} static staticMethod(x: string): string { return x; } - f(x: string) { - - } + f(x: string) {} } class B extends A { constructor(x: string, y: number) { @@ -383,6 +392,7 @@ class B extends A { } static anotherStatic() { (super.staticMethod(\"foo\"): number); + super.doesntExist(); } g() { @@ -410,6 +420,7 @@ class C extends D { return super.foo(); } } + module.exports = C; " `; diff --git a/tests/suppress/__snapshots__/jsfmt.spec.js.snap b/tests/suppress/__snapshots__/jsfmt.spec.js.snap index bfb65e39..9cd8fcb7 100644 --- a/tests/suppress/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress/__snapshots__/jsfmt.spec.js.snap @@ -39,6 +39,7 @@ var test6: string = 123; */ var test1: string = 123; var test2: string = 123; + function getNum() { return 123; } @@ -69,9 +70,8 @@ function runTest(y: number): void { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* $FlowFixMe - suppressing the error op location should also work */ -function takesAString(x: string): void { - -} +function takesAString(x: string): void {} + function runTest(y: number): void { takesAString(y); } diff --git a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap index ade0d0ba..c4dc8b56 100644 --- a/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/suppress_traces/__snapshots__/jsfmt.spec.js.snap @@ -26,6 +26,7 @@ var a: string = foo(\'hi\'); // error number ~> string function bar(): number { return 5; } + function foo(x: string) { return bar(); } diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index 64116faa..c76be626 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -36,6 +36,7 @@ function foo(x): number { throw new Error(\"hi\"); } } + function bar(x) { switch (x) { case 0: @@ -43,8 +44,10 @@ function bar(x) { default: return; } + 1; } + function baz(x): number { switch (x) { case 0: @@ -101,6 +104,7 @@ function foo(): number { } return 2; } + function bar() { switch (\"bar\") { case \"bar\": @@ -109,12 +113,15 @@ function bar() { break; } } + function qux(b) { var x = (b ? 0 : \"\"); switch (\"qux\") { case \"\": + x = 0; case \"qux\": + x = x * x; } } @@ -191,30 +198,43 @@ function foo(x: mixed): string { var b = \"\"; switch (x) { case \"foo\": + a = 0; default: + b = 0; } + (a: string); + (a: number); + (b: number); return b; } + function baz(x: mixed): number { var a = \"\"; 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; } @@ -316,32 +336,39 @@ 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; } + function f2(i) { var x; switch (i) { case 0: case 1: default: + x = 1; break; case 2: } var y: number = x; } + function f3(i) { var x; switch (i) { @@ -349,10 +376,12 @@ function f3(i) { case 1: default: case 2: + x = 1; } var y: number = x; } + function foo(x): number { switch (x) { case 0: @@ -362,6 +391,7 @@ function foo(x): number { return 1; } } + function bar(x) { switch (x) { default: @@ -369,8 +399,10 @@ function bar(x) { case 0: break; } + 1; } + function baz(x): number { switch (x) { case 0: diff --git a/tests/symlink/__snapshots__/jsfmt.spec.js.snap b/tests/symlink/__snapshots__/jsfmt.spec.js.snap index 36cbc18c..2f490c5e 100644 --- a/tests/symlink/__snapshots__/jsfmt.spec.js.snap +++ b/tests/symlink/__snapshots__/jsfmt.spec.js.snap @@ -17,6 +17,7 @@ exports[`test qux.js 1`] = ` ({ x: \"\" }: Foo); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import type { Foo } from \"./bar.js\"; + ({ x: \"\" }: Foo); " `; diff --git a/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap b/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap index 43d39029..73b74510 100644 --- a/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/tagged-unions/__snapshots__/jsfmt.spec.js.snap @@ -41,6 +41,7 @@ class Bar { bar: string; } type Foobar = Foo | Bar; + function foobar(x: Foobar): string { if (x.type === \"foo\") { return foo(x); @@ -51,9 +52,11 @@ function foobar(x: Foobar): string { return \"unknown\"; } } + function foo(x: Foo): string { return x.foo; } + function bar(x: Bar): string { return x.bar; } @@ -94,6 +97,7 @@ interface IUserData extends IDataBase { kind: \"user\" } interface ISystemData extends IDataBase { kind: \"system\" } type IData = IUserData | ISystemData; const data: IData = { id: \"\", name: \"\", kind: \"system\" }; + if (data.kind === \"user\") { (data: ISystemData); } @@ -134,6 +138,7 @@ interface IUserData extends IDataBase { kind: \"user\" } interface ISystemData extends IDataBase { kind: \"system\" } type IData = IUserData | ISystemData; const data: IData = { id: \"\", name: \"\", kind: \"system\" }; + if (data.kind === \"system\") { (data: ISystemData); } @@ -178,6 +183,7 @@ type UserData = { id: string; name: string; kind: \"user\" }; type SystemData = { id: string; name: string; kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; + if (data.kind === \"user\") { (data: SystemData); } @@ -222,6 +228,7 @@ type UserData = { id: string; name: string; kind: \"user\" }; type SystemData = { id: string; name: string; kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; + if (data.kind === \"system\") { (data: SystemData); } diff --git a/tests/taint/__snapshots__/jsfmt.spec.js.snap b/tests/taint/__snapshots__/jsfmt.spec.js.snap index 15da7235..8d302de9 100644 --- a/tests/taint/__snapshots__/jsfmt.spec.js.snap +++ b/tests/taint/__snapshots__/jsfmt.spec.js.snap @@ -40,24 +40,31 @@ function f7(x : $Tainted, y : $Tainted) { function f(x: $Tainted, y: $Tainted) { var z: $Tainted = x + y; } + function f1(x: $Tainted, y: number) { var z: $Tainted = x + y; } + function f2(x: number, y: $Tainted) { var z: $Tainted = x + y; } + function f3(x: $Tainted, y: number) { var z: number = x + y; } + function f4(x: number, y: $Tainted) { var z: number = x + y; } + function f5(x: number, y: $Tainted) { var z: string = x + y; } + function f6(x: string, y: $Tainted) { var z: string = x + y; } + function f7(x: $Tainted, y: $Tainted) { var z: string = x + y; } @@ -103,17 +110,22 @@ 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); } ]; @@ -153,21 +165,27 @@ function f_foo3(f1 : Function, o1 : Object, o2 : {t : $Tainted}) { function foo(x: $Tainted, o: Object) { o.f(x); } + function foo1(x: $Tainted, o: { f(y: $Tainted): void }) { o.f(x); } + function foo2(o1: Object, o2: { t: $Tainted }) { o1.f(o2.t); } + function foo3(x: $Tainted, o: { f(y: $Tainted): void }) { o.f(x); } + function f_foo1(x: $Tainted, f: Function) { f(x); } + function f_foo2(f1: Function, o: { t: $Tainted }) { f1(o.t); } + function f_foo3(f1: Function, o1: Object, o2: { t: $Tainted }) { f1(o1)(o2.t); } @@ -203,12 +221,15 @@ function f3(x : $Tainted, y : string) { function f(x: $Tainted, y: $Tainted) { var z: $Tainted = x < y; } + function f1(x: string, y: $Tainted) { var z: $Tainted = x < y; } + function f2(x: $Tainted, y: number) { var z: $Tainted = x < y; } + function f3(x: $Tainted, y: string) { var z: boolean = x < y; } @@ -241,6 +262,7 @@ let tests = [ }, function(x: any, y: $Tainted) { let z = x(); + z(y); } ]; @@ -268,6 +290,7 @@ class A { class A { f(x: $Tainted) { fakeDocument.location = x; + doStuff(x); } f1(x: $Tainted) { @@ -401,6 +424,7 @@ function f(x : $Tainted) { // Should cause error. var safe: string = \"safe\"; var tainted: $Tainted = safe; + function f(x: $Tainted) { var y: any = x; } @@ -452,21 +476,27 @@ function foo6 (a : $Tainted>) { function foo(x: $Tainted) { var should_fail: number = x * 42; } + function foo1(x: $Tainted<{ f: number }>) { var ok: number = x.f; } + function foo2(o: { f(y: number): number }, t: $Tainted) { return o.f(t); } + function foo3(x: $Tainted<{ f: number }>) { var also_tainted: $Tainted = x.f; } + function foo4(a: $Tainted>) { var trusted: string = a[0]; } + function foo5(a: $Tainted>) { var trusted_number: number = a[0]; } + function foo6(a: $Tainted>) { var trusted: $Tainted = a[0]; } diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index e7ff9907..286eb2c5 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -50,29 +50,41 @@ let tests = [ // error // error (\`foo\`: string); + (\`bar\`: \"bar\"); + (\`baz\`: number); + \`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 3de35025..ae577dc9 100644 --- a/tests/this/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this/__snapshots__/jsfmt.spec.js.snap @@ -88,24 +88,34 @@ module.exports = true; function F() { this.x = 0; } + F.prototype.m = function() { this.y = 0; }; -function foo(p: string) { - -} + +function foo(p: string) {} var o1 = new F(); + o1.x = \"\"; + foo(o1.x); var o2 = new F(); + o1.y = 0; + o2.y = \"\"; + foo(o2.y); var o3 = new F(); + o3.m(); + o3.y = \"\"; + foo(o3.y); + foo(o2.y); + function f1(): number { return this.x; } @@ -117,6 +127,7 @@ var a1 = () => { return this.x; }; var ax = a1(); + function f2(): number { var a2 = () => { return this.x; @@ -127,7 +138,9 @@ var f2_1 = f2.bind({ x: 0 })(); var f2_2: string = f2.bind({ x: 0 })(); var f2_3 = f2.bind({ x: \"\" })(); var f2_4 = f2(); + (this: void); + module.exports = true; " `; @@ -182,16 +195,16 @@ class C { var c = new C(); 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) { - - } + foo(x: number) {} } class F extends E { foo() { diff --git a/tests/this_type/__snapshots__/jsfmt.spec.js.snap b/tests/this_type/__snapshots__/jsfmt.spec.js.snap index 0c0eba6b..4326dd51 100644 --- a/tests/this_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/this_type/__snapshots__/jsfmt.spec.js.snap @@ -91,56 +91,44 @@ class C { } class D extends C {} var d = new D(); + (d: C).next = new C(); + (d.next: D); class A { - foo(that: X) { - - } + foo(that: X) {} } class B extends A { - foo(that: Y) { - - } + foo(that: Y) {} } class Invariant { out_object(): { _: this } { return { _: this }; } - in_object(_: { _: this }) { - - } + in_object(_: { _: this }) {} inout_object: { _: this }; out_array(): Array { return [ this ]; } - in_array(_: Array) { - - } + in_array(_: Array) {} inout_array: Array; } class Misc { out_set(): Set { return new Set().add(this); } - in_set(_: Set) { - - } + in_set(_: Set) {} inout_set: Set; async out_promise(): Promise { return this; } - in_promise(_: Promise) { - - } + in_promise(_: Promise) {} inout_promise: Promise; *out_generator(): Generator { yield this; return this; } - in_generator(_: Generator) { - - } + in_generator(_: Generator) {} inout_generator: Generator; } " @@ -206,6 +194,7 @@ class Implicit { class ImplicitNumber extends Implicit { arg: number; } + (new ImplicitNumber().val: string); " `; @@ -251,16 +240,22 @@ class B1 extends A1 { return new B1(); } } + (new B1().bar(): B1); class B3 extends A3 { foo(): B3 { return new B3(); } } + (new B3().bar(): B3<*>); + (new B3().qux(0): string); + (new B3().bar(): A2<*>); + ((new B3().bar(): B3): A2); + ((new B3(): A2).qux(0): string); " `; @@ -283,9 +278,11 @@ class C { return this; } } + function foo(c: C): I { return c; } + function bar(c: C): J { return c; } @@ -305,6 +302,7 @@ class C { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (new DoublyLinkedList().prev(): DoublyLinkedList); + (new DoublyLinkedList().next(): DoublyLinkedList); var MiniImmutable = require(\"mini-immutable\"); class C { @@ -379,9 +377,13 @@ class A { } } class B extends A {} + (A.make(): A); + (B.make(): B); + (B.make(): A); + (A.make(): B); " `; @@ -505,12 +507,19 @@ class Override extends Base { } } class InheritOverride extends Override {} + (new Inherit().foo(): Base); + (new Inherit().foo(): Inherit); + ((new Inherit(): Base).foo(): Base); + (new Override().foo(): Base); + (new Override().foo(): Override); + ((new Override(): Base).foo(): Base); + (new InheritOverride().bar_caller(): InheritOverride); class Base2 { foo(): this { @@ -525,12 +534,8 @@ class Base2 { bar_caller(): this { return this.bar(); } - corge(that: this) { - - } - grault(that: Base2) { - - } + corge(that: this) {} + grault(that: Base2) {} } class Inherit2 extends Base2 {} class Override2 extends Base2 { @@ -543,21 +548,25 @@ class Override2 extends Base2 { bar(): Override2 { return new Override2(); } - corge(that: this) { - - } - grault(that: this) { - - } + corge(that: this) {} + grault(that: this) {} } class InheritOverride2 extends Override2 {} + (new Inherit2().foo(): Base2); + (new Inherit2().foo(): Inherit2); + ((new Inherit2(): Base2).foo(): Base2); + (new Override2().foo(): Base2); + (new Override2().foo(): Override2); + ((new Override2(): Base2).foo(): Base2); + (new InheritOverride2().bar_caller(): InheritOverride2); + (new Override2(): Base2).corge(new Base2()); " `; diff --git a/tests/throw/__snapshots__/jsfmt.spec.js.snap b/tests/throw/__snapshots__/jsfmt.spec.js.snap index 2ae1e197..705459e0 100644 --- a/tests/throw/__snapshots__/jsfmt.spec.js.snap +++ b/tests/throw/__snapshots__/jsfmt.spec.js.snap @@ -30,12 +30,14 @@ function h(x: number): string { function f(): number { throw new Error(); } + function g(a: ?string) { if (a == null) { throw new Error(); } return a * 1; } + function h(x: number): string { if (x) { return \"foo\"; diff --git a/tests/traces/__snapshots__/jsfmt.spec.js.snap b/tests/traces/__snapshots__/jsfmt.spec.js.snap index 2c2caa5d..aae29dc0 100644 --- a/tests/traces/__snapshots__/jsfmt.spec.js.snap +++ b/tests/traces/__snapshots__/jsfmt.spec.js.snap @@ -24,40 +24,44 @@ f3(double); // ...on arg n // h/o call with function expr // h/o call with function def -function g0(y: string) { - -} +function g0(y: string) {} + function f0(x) { g0(x); } + f0(0); -function g1(a: string, b: string) { - -} + +function g1(a: string, b: string) {} + function f1(x, y) { g1(x, y); } + f1(\"hey\", 0); -function g2(ylam: (s: string) => number) { - -} + +function g2(ylam: (s: string) => number) {} + function f2(xlam) { g2(xlam); } + f2( function(x) { return x * x; } ); -function g3(ylam: (s: string) => number) { - -} + +function g3(ylam: (s: string) => number) {} + function f3(xlam) { g3(xlam); } + function double(n) { return n * 2; } + f3(double); " `; @@ -91,6 +95,7 @@ var A = React.createClass({ var B = React.createClass({ propTypes: { bar: React.PropTypes.string.isRequired } }); + function f(b): React.Element<*> { if (b) { return ; diff --git a/tests/traits/__snapshots__/jsfmt.spec.js.snap b/tests/traits/__snapshots__/jsfmt.spec.js.snap index 893959ab..36497f67 100644 --- a/tests/traits/__snapshots__/jsfmt.spec.js.snap +++ b/tests/traits/__snapshots__/jsfmt.spec.js.snap @@ -32,8 +32,11 @@ declare class Foo extends Qux {} declare class Bar extends Baz { y: T } declare class Qux extends Baz { y: T; z: T } declare class Baz { x: T } + (new Foo().x: number); + (new Foo().y: string); + (new Foo().z: number); " `; diff --git a/tests/try/__snapshots__/jsfmt.spec.js.snap b/tests/try/__snapshots__/jsfmt.spec.js.snap index f883eadb..5682b24a 100644 --- a/tests/try/__snapshots__/jsfmt.spec.js.snap +++ b/tests/try/__snapshots__/jsfmt.spec.js.snap @@ -22,9 +22,7 @@ function foo() { * abnormal. It was weird. */ function foo() { - try { - - } catch (error) { + try {} catch (error) { if (error.foo === 4) { throw error; } @@ -221,25 +219,22 @@ function f(b) { // error // ditto // error -function might_throw() { - -} +function might_throw() {} + function f() { try { var x: number = 0; var y: number = x; - } catch (e) { - - } + } catch (e) {} } + function f() { - try { - - } catch (e) { + try {} catch (e) { var x: number = 0; var y: number = x; } } + function f() { try { might_throw(); @@ -248,6 +243,7 @@ function f() { var y: number = x; } } + function f() { try { might_throw(); @@ -256,15 +252,15 @@ function f() { var y: number = x; } } + function f() { - try { - - } catch (e) { + try {} catch (e) { var x: number = 0; } finally { var y: number = x; } } + function f() { try { var x: number = 0; @@ -275,6 +271,7 @@ function f() { var y: number = x; } } + function f() { try { var x: number = 0; @@ -284,73 +281,68 @@ function f() { } var y: number = x; } + function f() { - try { - - } catch (e) { - - } finally { + try {} catch (e) {} finally { might_throw(); var x: number = 0; } var y: number = x; } + function f() { try { var x: number; - } catch (e) { - - } finally { + } catch (e) {} finally { might_throw(); + x = 0; } var y: number = x; } + function f() { - try { - - } catch (e) { + try {} catch (e) { var x: number; } finally { might_throw(); + x = 0; } var y: number = x; } + function f() { var y: number = x; try { var x: number = 0; - } catch (e) { - - } + } catch (e) {} } + function f() { try { var x: number = 0; - } catch (e) { - - } + } catch (e) {} var y: number = x; } + function f() { - try { - - } catch (e) { + try {} catch (e) { var x: number = 0; } var y: number = x; } + function f(b) { try { var x: number; + if (b) { throw new Error(); } - x = 0; - } catch (e) { - } + x = 0; + } catch (e) {} var y: number = x; } " @@ -429,14 +421,14 @@ function corge(): string { // unreachable // unreachable function foo(x: ?number): string { - try { - - } catch (e) { + try {} catch (e) { return \"bar\"; } + console.log(); return \"foo\"; } + function bar(): string { try { return \"foo\"; @@ -444,6 +436,7 @@ function bar(): string { return \"bar\"; } } + function baz(): string { try { throw new Error(\"foo\"); @@ -452,23 +445,23 @@ function baz(): string { } return \"bar\"; } + function qux(): string { try { throw new Error(\"foo\"); - } catch (e) { - - } + } catch (e) {} + console.log(); return \"bar\"; } + function quux(): string { try { return qux(); - } catch (e) { - - } + } catch (e) {} return \"bar\"; } + function bliffl(): string { try { throw new Error(\"foo\"); @@ -478,12 +471,14 @@ function bliffl(): string { return \"bar\"; } } + function corge(): string { try { return \"foo\"; } catch (e) { throw new Error(\"bar\"); } + bar(); } " @@ -555,9 +550,12 @@ function foo() { } finally { y = {}; } + x(); + y(); } + function bar(response) { var payload; try { @@ -565,17 +563,17 @@ function bar(response) { } catch (e) { throw new Error(\"...\"); } - if (payload.error) { - - } + + if (payload.error) + {} } + function qux() { var x = 5; try { throw -1; - } finally { - - } + } finally {} + x(); } " diff --git a/tests/tuples/__snapshots__/jsfmt.spec.js.snap b/tests/tuples/__snapshots__/jsfmt.spec.js.snap index d17fca42..a20396e1 100644 --- a/tests/tuples/__snapshots__/jsfmt.spec.js.snap +++ b/tests/tuples/__snapshots__/jsfmt.spec.js.snap @@ -15,6 +15,7 @@ function foo(x: Array): [number, ?number] { function foo(x: Array): [number, ?number] { return x; } + function foo(x: Array): [number, ?number] { return [ x[0], x[1] ]; } @@ -34,8 +35,10 @@ exports[`test optional.js 1`] = ` // Error, arity is enforced // error, since second element is not marked optional ([ 0, undefined ]: [number, ?string]); + ([ 0 ]: [number, ?string]); -([ ]: [?number, string]); + +([]: [?number, string]); " `; @@ -48,9 +51,8 @@ foo([ {} ]); // error, too few elements in array passed to a tuple ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ // error, too few elements in array passed to a tuple -function foo(a: [Object, Object]) { - -} +function foo(a: [Object, Object]) {} + foo([ {} ]); " `; @@ -65,9 +67,9 @@ var f: [number, string] = [123, 456]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Error - arity mismatch // nope -var a: [] = [ ]; +var a: [] = []; var b: [] = [ 123 ]; -var c: [number] = [ ]; +var c: [number] = []; var d: [number, string] = [ 123, \"duck\" ]; var e: [number, string] = [ 123, \"duck\" ]; var f: [number, string] = [ 123, 456 ]; diff --git a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap index 44cfaef7..fc3fc02f 100644 --- a/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-at-pos/__snapshots__/jsfmt.spec.js.snap @@ -55,11 +55,7 @@ const y = { // class X { // foo(): void {} // } -const y = { - bar(): void { - - } -}; +const y = { bar(): void {} }; " `; @@ -95,24 +91,31 @@ mn; // error: application of non-poly type class C {} var cn: C = new C(); + 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(); + mn; " `; @@ -126,10 +129,11 @@ module.exports = num; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var num = 42; -function bar() { - -} + +function bar() {} + bar(); + module.exports = num; " `; @@ -148,6 +152,7 @@ let tests = [ let tests = [ function() { let x = {}; + Object.defineProperty(x, \"foo\", { value: \"\" }); } ]; @@ -175,10 +180,13 @@ function qux(x?) { function foo(x?: string) { return x; } + foo(); + function bar(obj: { x?: string }) { return obj.x; } + function qux(x?) { return x; } @@ -195,15 +203,15 @@ if (Array.isArray(x)) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ let x = 0; -if (x == null) { - -} -if (x == undefined) { - -} -if (Array.isArray(x)) { - -} + +if (x == null) + {} + +if (x == undefined) + {} + +if (Array.isArray(x)) + {} " `; @@ -212,6 +220,7 @@ exports[`test react.js 1`] = ` React.createElement; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ import React from \"react\"; + React.createElement; " `; @@ -243,10 +252,11 @@ const w:MyNum = 42; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow var str = require(\"./import\"); -function foo() { - -} + +function foo() {} + foo(); + str; type Point = [number, string]; const x: Point = [ 1, \"foo\" ]; @@ -269,8 +279,6 @@ try { // @flow try { throw \"foo\"; -} catch (e) { - -} +} catch (e) {} " `; diff --git a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap index 2c76d0e1..634ff438 100644 --- a/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-destructors/__snapshots__/jsfmt.spec.js.snap @@ -24,8 +24,11 @@ function foo(x: ?string): $NonMaybeType { } else return 0; } + (0: $NonMaybeType); + (0: $NonMaybeType); + (0: $NonMaybeType); " `; @@ -46,7 +49,9 @@ function foo(o: Obj): $PropertyType { type Malformed = $PropertyType; type Obj = { x: string }; type Obj_Prop_x = $PropertyType; + (42: Obj_Prop_x); + function foo(o: Obj): $PropertyType { if (false) return o.x; diff --git a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap index 772bb217..9491a465 100644 --- a/tests/type-printer/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type-printer/__snapshots__/jsfmt.spec.js.snap @@ -30,9 +30,11 @@ module.exports = printBinaryExpression; */ \"use babel\"; import type { BinaryExpression } from \"./types\"; + function printBinaryExpression(node: BinaryExpression) { console.log(node); } + module.exports = printBinaryExpression; " `; diff --git a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap index 2769d314..9da07f02 100644 --- a/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_nonstrict/__snapshots__/jsfmt.spec.js.snap @@ -109,6 +109,7 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; + this.y = y; } } @@ -124,6 +125,7 @@ class MySubclass extends MyClass { super(y); } } + function singleton(x: T): Array { return [ x ]; } diff --git a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap index 73e59e3a..a1eabb34 100644 --- a/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_args_strict/__snapshots__/jsfmt.spec.js.snap @@ -107,6 +107,7 @@ class MyClass2 { y: U; constructor(x: T, y: U) { this.x = x; + this.y = y; } } @@ -122,6 +123,7 @@ class MySubclass extends MyClass { super(y); } } + function singleton(x: T): Array { return [ x ]; } diff --git a/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap b/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap index 0d66c0ec..31e6adb2 100644 --- a/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_only_vars/__snapshots__/jsfmt.spec.js.snap @@ -19,6 +19,7 @@ module.exports = { */ class Foo {} class Bar {} + module.exports = { Foo: Foo, Bar: Bar }; " `; @@ -95,6 +96,7 @@ var n = Foo; var o = Baz; var a: Foo = new Foo(); var b: Foo = new A.Foo(); + (new A.Bar(): Baz); " `; @@ -130,6 +132,7 @@ var m = A; var n = Foo; var o = Baz; var a: Foo = new actualA.Foo(); + (new actualA.Bar(): Baz); " `; diff --git a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap index 913a7d62..eb1593aa 100644 --- a/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_defaults/__snapshots__/jsfmt.spec.js.snap @@ -98,17 +98,24 @@ var b_number: B = new B(123); var b_void: B = new B(); var b_default: B<> = new B(\"hello\"); var b_star: B<*> = new B(123); + (b_number.p: boolean); + (b_void.p: boolean); + (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(); var c_default: C<> = new C(\"hello\"); var c_star: C<*> = new C(\"hello\"); + (c_void.p: boolean); + (c_default.p: boolean); + (c_star.p: boolean); class D extends A {} var d_number: D = new D(123); @@ -117,14 +124,19 @@ var d_default: D = new D(\"hello\"); var d_too_few_args: D<> = new D(\"hello\"); var d_too_many: D = new D(\"hello\"); var d_star: D<*> = new D(10); + (d_number.p: boolean); + (d_void.p: boolean); + (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 {} diff --git a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap index 89ffdc8f..25e4e6a7 100644 --- a/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_scope/__snapshots__/jsfmt.spec.js.snap @@ -13,11 +13,10 @@ exports[`test class.js 1`] = ` class C { a(x: T, a: A) { this.b(x); + this.b(a); } - b(x: T) { - - } + b(x: T) {} } " `; @@ -45,17 +44,22 @@ f(0); // ok // ok function f(a: T) { function g(b: U, c: T = a) { - function h(d: U = b) { - - } + function h(d: U = b) {} + h(); + h(b); + h(c); } + g(0); + g(0, a); + g(0, 0); } + f(0); " `; @@ -153,8 +157,11 @@ class G { } } declare var g: G; + g.m(0); + g.m(true); + (g.m(\"\"): G); class H { 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 185e5603..7d9462fc 100644 --- a/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance/__snapshots__/jsfmt.spec.js.snap @@ -47,10 +47,13 @@ async function foo(x: boolean): Promise { return null; } } + async function run() { console.log(await foo(true)); + console.log(await foo(false)); } + run(); " `; diff --git a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap index adc9efec..82d1db30 100644 --- a/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap +++ b/tests/type_param_variance2/__snapshots__/jsfmt.spec.js.snap @@ -41,10 +41,13 @@ async function foo(x: boolean): Promise { return null; } } + async function run() { console.log(await foo(true)); + console.log(await foo(false)); } + run(); " `; diff --git a/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap b/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap index ac550c7e..a7f57617 100644 --- a/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typeapp_perf/__snapshots__/jsfmt.spec.js.snap @@ -35,6 +35,7 @@ type B = A & { +i: () => B }; declare var b: B; + (b: B); " `; @@ -76,6 +77,7 @@ type B = A & { +i: (x: B) => void }; declare var b: B; + (b: B); " `; diff --git a/tests/typecast/__snapshots__/jsfmt.spec.js.snap b/tests/typecast/__snapshots__/jsfmt.spec.js.snap index 28c07733..3113a4f9 100644 --- a/tests/typecast/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typecast/__snapshots__/jsfmt.spec.js.snap @@ -47,9 +47,7 @@ var tests = [ () => { var s: string = ((0: number), (\"hey\": string)); }, - () => { - - } + () => {} ]; " `; diff --git a/tests/unary/__snapshots__/jsfmt.spec.js.snap b/tests/unary/__snapshots__/jsfmt.spec.js.snap index 8caffa30..868c8c67 100644 --- a/tests/unary/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary/__snapshots__/jsfmt.spec.js.snap @@ -28,15 +28,19 @@ function x4(y: string): boolean { function x0(y: string): number { return +y; } + function x1(y: string): number { return -y; } + function x3(y: string) { return ~y; } + function x4(y: string): boolean { return !y; } + (-1: void); " `; @@ -94,13 +98,18 @@ let tests = [ let tests = [ function(y: number) { y++; + y--; + ++y; + --y; }, function(y: string) { y++; + (y: number); + y++; }, function(y: string) { @@ -114,7 +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 5eb70946..d1ae3105 100644 --- a/tests/undefined/__snapshots__/jsfmt.spec.js.snap +++ b/tests/undefined/__snapshots__/jsfmt.spec.js.snap @@ -19,13 +19,14 @@ function doSomethingAsync(): Promise { (resolve, reject) => { resolve(); var anotherVoidPromise: Promise = Promise.resolve(); + resolve(anotherVoidPromise); } ); } -function foo(x: void) { - -} + +function foo(x: void) {} + foo(); " `; @@ -45,16 +46,18 @@ function qux(x?: number, y:string = \"\", z) { } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ function foo() { var x; + x.foo(); } + function bar() { var x: ?{ bar(): void }; + if (x) x.bar(); } -function qux(x?: number, y: string = \"\", z) { - -} + +function qux(x?: number, y: string = \"\", z) {} " `; @@ -101,18 +104,23 @@ 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/unicode/__snapshots__/jsfmt.spec.js.snap b/tests/unicode/__snapshots__/jsfmt.spec.js.snap index b9fa1163..2c48b0b7 100644 --- a/tests/unicode/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unicode/__snapshots__/jsfmt.spec.js.snap @@ -62,6 +62,7 @@ function utf16Length(str, pos) { function inSurrogateRange(codeUnit) { return 55296 <= codeUnit && codeUnit <= 57343; } + function utf16Length(str, pos) { return 1 + inSurrogateRange(str.charCodeAt(pos)); } diff --git a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap index 2900ac4e..09dea7d4 100644 --- a/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union-intersection/__snapshots__/jsfmt.spec.js.snap @@ -5004,6 +5004,7 @@ type TAction = { type: \"a1\"; a1: number } | { type: \"a2\"; a1: number } | { type: \"a999\"; a100: number } | { type: \"a1000\"; a100: number }; + function foo(x: TAction): TAction { return x; } @@ -5031,18 +5032,22 @@ type A = { a: number }; type B = { b: number }; type C = { c: number }; 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 { return x; } diff --git a/tests/union/__snapshots__/jsfmt.spec.js.snap b/tests/union/__snapshots__/jsfmt.spec.js.snap index 58a4afe2..f877dc10 100644 --- a/tests/union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union/__snapshots__/jsfmt.spec.js.snap @@ -110,33 +110,10 @@ myclass.myfun([\"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function (ar) {} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ declare class Myclass { myfun(myarray: Array): any } declare var myclass: Myclass; -myclass.myfun( - [ - \"1\", - \"2\", - \"3\", - \"4\", - \"5\", - \"6\", - function(ar) { - - } - ] -); -myclass.myfun( - [ - \"1\", - \"2\", - \"3\", - \"4\", - \"5\", - \"6\", - \"7\", - function(ar) { - - } - ] -); + +myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", function(ar) {} ]); + +myclass.myfun([ \"1\", \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", function(ar) {} ]); " `; @@ -158,6 +135,7 @@ module.exports = Foo; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ class Foo {} + module.exports = Foo; " `; @@ -177,6 +155,7 @@ class Foo {} class Bar {} var foostr: Foo | string = new Foo(); var barstr: Bar | string = new Bar(); + foostr = barstr; " `; @@ -199,7 +178,7 @@ class Tag_ { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class Tag { constructor() { - var a1: Array = [ ]; + var a1: Array = []; var a2: Array = a1; } } @@ -336,20 +315,22 @@ bar(f); // workaround var C = require(\"test-lib\"); type Foo = Array; -var x: Array = [ ]; -var y: Array = [ ]; -function foo(x: Foo) { - -} +var x: Array = []; +var y: Array = []; + +function foo(x: Foo) {} + foo(x); + foo(y); type Bar = () => C | string; + function f() { return \"\"; } -function bar(x: Bar) { - -} + +function bar(x: Bar) {} + bar(f); " `; @@ -362,6 +343,7 @@ module.exports = C; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @providesModule test-lib */ class C {} + module.exports = C; " `; @@ -422,26 +404,27 @@ function corge(b) { // error, since E could be D, and D is not a subtype of C // this annotation is an error: is it C, or is it D? // OK -function bar(x: Document | string): void { - -} +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) { - - } + + 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); } " diff --git a/tests/union_new/__snapshots__/jsfmt.spec.js.snap b/tests/union_new/__snapshots__/jsfmt.spec.js.snap index 806ecbe0..e91e6baf 100644 --- a/tests/union_new/__snapshots__/jsfmt.spec.js.snap +++ b/tests/union_new/__snapshots__/jsfmt.spec.js.snap @@ -25,6 +25,7 @@ class VirtualNode { type T = A | B; class U {} declare var children: U; + (children: T | U); class A {} class B {} @@ -148,9 +149,9 @@ function node(content: ?Foobar | String | Array) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /* @flow */ import type { Foobar } from \"./issue-1455-helper\"; -function create(content: ?Foobar | String | Array) { - -} + +function create(content: ?Foobar | String | Array) {} + function node(content: ?Foobar | String | Array) { create(content); } @@ -196,9 +197,11 @@ type Common = {}; type A = Common & { type: \"A\"; foo: number }; type B = Common & { type: \"B\"; foo: Array }; type MyType = A | B; + function print(x: number) { console.log(x); } + function printAll(val: MyType) { print(val.foo); } @@ -238,9 +241,11 @@ type Common = {}; type A = { type: \"A\"; foo: number } & Common; type B = { type: \"B\"; foo: Array } & Common; type MyType = A | B; + function print(x: number) { console.log(x); } + function printAll(val: MyType) { if (val.type === \"A\") { print(val.foo); @@ -285,6 +290,7 @@ type UserData = DataBase & { kind: \"user\" }; type SystemData = DataBase & { kind: \"system\" }; type Data = UserData | SystemData; const data: Data = { id: \"\", name: \"\", kind: \"system\" }; + if (data.kind === \"system\") { (data: SystemData); } @@ -304,6 +310,7 @@ function hello(x:X): string { // @flow //type X = {a:true, b:string} | {a:false, c:string}; // this works. type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); + function hello(x: X): string { if (x.a === true) return x.b; @@ -344,6 +351,7 @@ type Entity = { id: T; name: string }; type StringEntity = Entity; type Foo = StringEntity & { bars: Object; kind: 1 }; type EmptyFoo = StringEntity & { bars: null; kind: 2 }; + function test(f: Foo | EmptyFoo) { if (f.kind === 1) { (f: Foo); @@ -441,7 +449,9 @@ type A1 = { x: B1 }; type A2 = { x: B2 }; type B1 = number; type B2 = string; + (obj_result: B1 | B2); + function fun(a: A3 | A4) { return a(); } @@ -450,12 +460,13 @@ type A3 = () => B3; type A4 = () => B4; type B3 = number; type B4 = string; + (fun_result: B3 | B4); -function inst(a: A5 | A6) { - -} + +function inst(a: A5 | A6) {} class B5 {} class B6 {} + inst([ new B6() ]); type A5 = B5[]; type A6 = B6[]; @@ -559,48 +570,43 @@ type B6 = string; ///////////////////////////////////////////// // class statics // tuples -function obj(a: { x: number } | { x: string }) { - -} +function obj(a: { x: number } | { x: string }) {} + obj(({ x: \"\" }: A1)); type A1 = { x: B1 }; type B1 = string; -function fun(a: (() => number) | (() => string)) { - -} + +function fun(a: (() => number) | (() => string)) {} + fun((() => \"\": A2)); type A2 = () => B2; type B2 = string; class C {} -function inst(a: C | 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) => { - - } -}); + +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 }) { - -} + +function stat(a: { x: number } | { x: string }) {} class D { static x: B5; } + stat(D); type B5 = string; -function tup(a: [number, boolean] | [string, boolean]) { - -} + +function tup(a: [number, boolean] | [string, boolean]) {} + tup(([ \"\", false ]: A6)); type A6 = [B6, boolean]; type B6 = string; @@ -648,20 +654,15 @@ type B2 = string; //////////////////////////// // example with array types //////////////////////////// -function fun(a: ((x: number) => void) | ((x: string) => void)) { - -} -fun( - (x => { - - }: A1) -); +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)); + +function arr(a: number[] | string[]) {} + +arr(([]: A2)); type A2 = B2[]; type B2 = string; " @@ -715,26 +716,26 @@ type B2 = string; //////////////////////////// // example with array types //////////////////////////// -function fun(a: ((x: number) => void) | ((x: string) => void)) { - -} -const a1 = (x => { - -}: A1); +function fun(a: ((x: number) => void) | ((x: string) => void)) {} +const a1 = (x => {}: A1); + 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); + +function arr(a: number[] | string[]) {} +const a2 = ([]: A2); + arr(a2); + function arr_set(x: string, i: number) { a2[i] = x; } + function arr_get(i: number): string { return a2[i]; } @@ -782,21 +783,23 @@ function arr_set(x: string, i: number) { a2[i] = x; } ///////////////////////////// // example with array types ///////////////////////////// -function fun(a: ((x: number) => number) | ((x: string) => string)) { - -} +function fun(a: ((x: number) => number) | ((x: string) => string)) {} + function a1(x) { return x; } + fun(a1); + function fun_call(x: string): string { return a1(x); } -function arr(a: number[] | string[]) { - -} -var a2 = [ ]; + +function arr(a: number[] | string[]) {} +var a2 = []; + arr(a2); + function arr_set(x: string, i: number) { a2[i] = x; } @@ -893,9 +896,8 @@ type PG = { x: X, y?: PG }; /////////////////////////////// // polymorphic recursive types /////////////////////////////// -function rec(x: F1 | F2) { - -} +function rec(x: F1 | F2) {} + rec({ x: 0 }); type F1 = G1; type F2 = G2; @@ -903,9 +905,9 @@ type G1 = { x: H1; y?: G1 }; type G2 = { x: H2; y?: G2 }; type H1 = string; type H2 = number; -function polyrec(x: PF | PF) { - -} + +function polyrec(x: PF | PF) {} + rec({ x: 0 }); type PF = PG; type PG = { x: X; y?: PG }; @@ -944,9 +946,8 @@ type H2_ = number; ////////////////////// // nested union types ////////////////////// -function rec(x: F1 | F2) { - -} +function rec(x: F1 | F2) {} + rec({ x: 0 }); type F1 = G1 | G1_; type F2 = G2 | G2_; @@ -989,9 +990,9 @@ foo((x): number => square(x)) function square(x? = 0) { return x * x; } -function foo(f: ((_: ?number) => ?number) | (() => void)) { - -} + +function foo(f: ((_: ?number) => ?number) | (() => void)) {} + foo((x): number => square(x)); " `; @@ -1102,36 +1103,40 @@ check_poly_inst(new P); function id(x: X): X { return x; } -function check_prim(_: number | string) { - -} + +function check_prim(_: number | string) {} + check_prim(\"\"); + check_prim(id(\"\")); class C {} class D {} -function check_inst(_: C | D) { - -} + +function check_inst(_: C | D) {} + check_inst(new D()); + check_inst(id(new C())); -function check_fun(_: ((_: number) => number) | ((_: string) => string)) { - -} + +function check_fun(_: ((_: number) => number) | ((_: string) => string)) {} + check_fun(x => x); -function check_obj(_: { x: number } | { x: string }) { - -} + +function check_obj(_: { x: number } | { x: string }) {} + check_obj({ x: \"\" }); + check_obj({ x: id(\"\") }); -function check_arr(_: number[] | string[]) { - -} + +function check_arr(_: number[] | string[]) {} + check_arr([ \"\" ]); + check_arr([ id(\"\") ]); class P {} -function check_poly_inst(_: P | P) { - -} + +function check_poly_inst(_: P | P) {} + check_poly_inst(new P()); " `; @@ -1166,9 +1171,13 @@ function length(list: List) { else return 0; } + length({ kind: \"nil\" }); + length({ kind: \"cons\" }); + length({ kind: \"cons\", next: { kind: \"nil\" } }); + length({ kind: \"empty\" }); type List = Nil | Cons; type Nil = { kind: \"nil\" }; @@ -1192,6 +1201,7 @@ function rec(x: F): G | H { return x; } type F = { f: F; x: X }; type G = { x: number }; type H = { x: string }; + function rec(x: F): G | H { return x; } @@ -1238,9 +1248,9 @@ function foo(c: C) { // @noflow // annotations declare class C { get(): X } -function union(o: { x: string } | { x: number }) { - -} + +function union(o: { x: string } | { x: number }) {} + function foo(c: C) { union({ x: c.get() }); } @@ -1277,12 +1287,7 @@ bar(() => { }); // functions as objects // example where globals are not yet resolved function foo(target: EventTarget) { - target.addEventListener( - \"click\", - e => { - - } - ); + target.addEventListener(\"click\", e => {}); } declare class EventTarget { addEventListener(type: \"foo\", listener: KeyboardEventHandler): void; @@ -1292,14 +1297,10 @@ declare class Event {} declare class KeyboardEvent {} type EventHandler = (event: Event) => mixed; type KeyboardEventHandler = (event: KeyboardEvent) => mixed; -function bar(x: (() => void) | { x: number }) { - -} -bar( - () => { - - } -); + +function bar(x: (() => void) | { x: number }) {} + +bar(() => {}); " `; @@ -1328,18 +1329,20 @@ x = \"\"; type T = number | (() => string); type Foo = T | (() => boolean); type Bar = number | (() => string) | (() => boolean); -function foo(x: Foo) { - -} + +function foo(x: Foo) {} + foo(() => qux()); -function bar(x: Bar) { - -} + +function bar(x: Bar) {} + bar(() => qux()); var x = false; + function qux() { return x; } + x = \"\"; " `; @@ -1355,8 +1358,9 @@ exports[`test test17.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @noflow // Array#concat -[ ].concat([ ]); -([ ].concat([ 0, 1 ])[1]: string); +[].concat([]); + +([].concat([ 0, 1 ])[1]: string); " `; @@ -1377,9 +1381,11 @@ new C().m(f()); // @noflow // method overloads declare class C { m(x: number): void; m(x: string): void } + function f() { return 0; } + new C().m(f()); " `; @@ -1426,12 +1432,14 @@ exports[`test test20.js 1`] = ` // @noflow // Array#reduce [ 0, 1 ].reduce((x, y, i) => y); + [ \"a\", \"b\" ].reduce( (regex, representation, index) => { return regex + ((index ? \"|\" : \"\")) + \"(\" + representation + \")\"; }, \"\" ); + [ \"\" ].reduce((acc, str) => acc * str.length); " `; @@ -1462,12 +1470,17 @@ function str() { // @noflow // annotations for disjoint unions type T = { type: \"FOO\"; x: number } | { type: \"BAR\"; x: string }; + ({ type: (bar(): \"BAR\"), x: str() }: T); + ({ type: bar(), x: str() }: T); + ({ type: bar(), x: (str(): string) }: T); + function bar() { return \"BAR\"; } + function str() { return \"hello\"; } @@ -1503,6 +1516,7 @@ type Empty = {}; type Success = { type: \"SUCCESS\"; result: string }; type Error = { type: \"ERROR\" } & Empty; export type T = Success | Error; + function foo(x: T) { if (x.type === \"SUCCESS\") return x.result; @@ -1532,8 +1546,10 @@ function foo(obj: Obj) { // should also be OK (the check above shouldn\'t affect anything) type NestedObj = {} & { dummy: SomeLibClass }; type Obj = NestedObj & { x: string }; + function foo(obj: Obj) { obj.x; + obj.x; } " @@ -1599,6 +1615,7 @@ declare class D extends C { ref(): D; unref(): D } + (0: D | number); " `; @@ -1655,14 +1672,17 @@ new Record().set(\'foo\', \"42\"); declare function foo(x: number): number; 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 } + new Record().set(\"foo\", \"42\"); " `; @@ -1692,18 +1712,21 @@ function hello4(x:X): string { // @noflow //type X = {a:true, b:string} | {a:false, c:string}; // this works. type X = ({ a: true } & { b: string }) | ({ a: false } & { c: string }); + function hello1(x: X): string { if (x.a === true) return x.b; else return x.c; } + function hello2(x: X): string { if (x.a === false) return x.c; else return x.b; } + function hello3(x: X): string { if (x.a) { return x.b; @@ -1711,6 +1734,7 @@ function hello3(x: X): string { return x.c; } } + function hello4(x: X): string { if (!x.a) { return x.c; @@ -1788,6 +1812,7 @@ type ActionType = // @noflow const Constants = require(\"./test30-helper\"); type ActionType = { type: \"foo\"; x: number } | { type: \"bar\"; x: number }; + ({ type: Constants.BAR, x: 0 }: ActionType); " `; @@ -1843,8 +1868,10 @@ declare class SomeMap { } declare class ImmutableMap {} 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 2d243973..cfaabf80 100644 --- a/tests/unreachable/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unreachable/__snapshots__/jsfmt.spec.js.snap @@ -30,13 +30,16 @@ function test2() { // error, n is number (EmptyT would work) function test1(): string { return bar(); + function bar() { return 0; } } + function test2() { const n = 0; return; + function f() { var x: typeof n = 0; var y: string = n; @@ -82,6 +85,7 @@ foo(1, 2); function foo(x, y) { \"use strict\"; return bar(x) + baz(y); + function bar(ecks) { return x + ecks; } @@ -91,6 +95,7 @@ function foo(x, y) { var x, y, z; var t, u = 5, v, w = 7; } + foo(1, 2); " `; diff --git a/tests/value/__snapshots__/jsfmt.spec.js.snap b/tests/value/__snapshots__/jsfmt.spec.js.snap index cb0d055f..8641e95d 100644 --- a/tests/value/__snapshots__/jsfmt.spec.js.snap +++ b/tests/value/__snapshots__/jsfmt.spec.js.snap @@ -7,9 +7,11 @@ var table: { [_: string]: number } = {}; table[\"x\"] = \"hello\"; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var o = {}; + o[\"x\"] = 4; var y: string = o[\"x\"]; var table: { [_: string]: number } = {}; + table[\"x\"] = \"hello\"; " `; diff --git a/tests/weakmode/__snapshots__/jsfmt.spec.js.snap b/tests/weakmode/__snapshots__/jsfmt.spec.js.snap index 3b30766d..4d9942af 100644 --- a/tests/weakmode/__snapshots__/jsfmt.spec.js.snap +++ b/tests/weakmode/__snapshots__/jsfmt.spec.js.snap @@ -15,6 +15,7 @@ function expects_an_int() { function returns_a_string() { return \"Hello\"; } + function expects_an_int() { return returns_a_string() * 10; } @@ -38,6 +39,7 @@ function expects_an_int() { function returns_a_string() { return \"Hello\"; } + function expects_an_int() { return returns_a_string() * 10; } diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap index 43e3bb65..9717ddc1 100644 --- a/tests/while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/while/__snapshots__/jsfmt.spec.js.snap @@ -32,6 +32,7 @@ function foo(x: boolean) { return; } } + function bar(x: boolean) { var ii = 0; while (ii > 0) { @@ -59,14 +60,15 @@ class C { return new C(); } } -function blah() { - -} + +function blah() {} var node: ?C = new C(); while (node) { var parent = node.m(); var cloneable: C = node; + blah(); + node = parent.m(); } " diff --git a/tests/x/__snapshots__/jsfmt.spec.js.snap b/tests/x/__snapshots__/jsfmt.spec.js.snap index 492f2dd0..c579fbbe 100644 --- a/tests/x/__snapshots__/jsfmt.spec.js.snap +++ b/tests/x/__snapshots__/jsfmt.spec.js.snap @@ -56,6 +56,7 @@ class XControllerURIBuilder { var tokenRegex = new RegExp(/^\\{(\\?)?(.+?)\\}$/); } } + module.exports = XControllerURIBuilder; " `;