diff --git a/src/printer.js b/src/printer.js index 23ad6afb1..0558c7929 100644 --- a/src/printer.js +++ b/src/printer.js @@ -340,12 +340,12 @@ function genericPrintNoParens(path, options, print) { if (n.id) { parts.push( " ", - path.call(print, "id"), - path.call(print, "typeParameters") + path.call(print, "id") ); } parts.push( + path.call(print, "typeParameters"), group(concat([ "(", indent(options.tabWidth, diff --git a/tests/annot/__snapshots__/jsfmt.spec.js.snap b/tests/annot/__snapshots__/jsfmt.spec.js.snap index 4054561fb..130fa1686 100644 --- a/tests/annot/__snapshots__/jsfmt.spec.js.snap +++ b/tests/annot/__snapshots__/jsfmt.spec.js.snap @@ -265,7 +265,7 @@ function insertMany( } class Foo { bar() { - return function(a: A, b: B, c: C): void { + return function(a: A, b: B, c: C): void { ([ a, b, c ]: [A, B, C]); }; } diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 3cd1397c9..33c166b7a 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -187,7 +187,7 @@ class C { var e = async function() { }; -var et = async function(a: T) { +var et = async function(a: T) { }; var n = new async function() { @@ -487,7 +487,7 @@ class C { var e = async function() { await 1; }; -var et = async function(a: T) { +var et = async function(a: T) { await 1; }; var n = new async function() { diff --git a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap index f2f9d49ac..eb4a019d4 100644 --- a/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async_iteration/__snapshots__/jsfmt.spec.js.snap @@ -78,7 +78,7 @@ async function* readLines(path) { } async function f() { - for await (const line of readLines(\"/path/to/file\")) { + for await (const line of readLines("/path/to/file")) { (line: void); // error: string ~> void } } @@ -97,7 +97,7 @@ async function* readLines(path) { } } async function f() { - for await (const line of readLines(\"/path/to/file\")) { + for await (const line of readLines("/path/to/file")) { (line: void); } } @@ -107,13 +107,13 @@ async function f() { exports[`test return.js 1`] = ` "declare var gen: AsyncGenerator; -// You can pass whatever you like to return, it doesn\'t need to be related to -// the AsyncGenerator\'s return type +// You can pass whatever you like to return, it doesn't need to be related to +// the AsyncGenerator's return type gen.return(0).then(result => { (result.value: void); // error: string | number ~> void }); -// However, a generator can \"refuse\" the return by catching an exception and +// However, a generator can "refuse" the return by catching an exception and // yielding or returning internally. async function *refuse_return() { try { @@ -122,16 +122,16 @@ async function *refuse_return() { return 0; } } -refuse_return().return(\"string\").then(result => { +refuse_return().return("string").then(result => { if (result.done) { (result.value: string); // error: number | void ~> string } }); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -// You can pass whatever you like to return, it doesn\'t need to be related to -// the AsyncGenerator\'s return type +// You can pass whatever you like to return, it doesn't need to be related to +// the AsyncGenerator's return type // error: string | number ~> void -// However, a generator can \"refuse\" the return by catching an exception and +// However, a generator can "refuse" the return by catching an exception and // yielding or returning internally. // error: number | void ~> string declare var gen: AsyncGenerator; @@ -147,7 +147,7 @@ async function* refuse_return() { return 0; } } -refuse_return().return(\"string\").then( +refuse_return().return("string").then( result => { if (result.done) { (result.value: string); @@ -167,7 +167,7 @@ exports[`test throw.js 1`] = ` } (async () => { - catch_return().throw(\"\").then(({value}) => { + catch_return().throw("").then(({value}) => { if (value !== undefined) { (value: void); // error: number ~> void } @@ -184,7 +184,7 @@ async function *yield_return() { } (async () => { - yield_return().throw(\"\").then(({value}) => { + yield_return().throw("").then(({value}) => { if (value !== undefined) { (value: void); // error: number ~> void } @@ -201,7 +201,7 @@ async function* catch_return() { } } async () => { - catch_return().throw(\"\").then( + catch_return().throw("").then( ({ value }) => { if (value !== undefined) { (value: void); @@ -218,7 +218,7 @@ async function* yield_return() { } } async () => { - yield_return().throw(\"\").then( + yield_return().throw("").then( ({ value }) => { if (value !== undefined) { (value: void); diff --git a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap index fd73b9172..1388e9404 100644 --- a/tests/more_generics/__snapshots__/jsfmt.spec.js.snap +++ b/tests/more_generics/__snapshots__/jsfmt.spec.js.snap @@ -38,13 +38,13 @@ function foo8(x:U,y):U { /* foo8(0,void 0); */ -var foo1 = function(x: T): T { +var foo1 = function(x: T): T { return x; }; function foo2(x: T): S { return x; } -var foo3 = function(x: T): T { +var foo3 = function(x: T): T { return foo3(x); }; function foo4(x: T): S { @@ -54,7 +54,7 @@ var x = [ ]; function foo5(): Array { return x; } -var foo6 = function(x: R): R { +var foo6 = function(x: R): R { return foo1(x); }; function foo7(x: R): R { diff --git a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap index c89941b61..af35dd379 100644 --- a/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/predicates-abstract/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,7 @@ const barr = my_filter(arr, is_string); (barr: Array); function is_string(x): %checks { - return typeof x === \"string\"; + return typeof x === "string"; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow @@ -21,7 +21,7 @@ declare var arr: Array; const barr = my_filter(arr, is_string); (barr: Array); function is_string(x): %checks { - return typeof x === \"string\"; + return typeof x === "string"; } " `; @@ -34,16 +34,16 @@ exports[`test filter-union.js 1`] = ` declare function my_filter>(v: Array, cb: P): Array<$Refine>; -type A = { kind: \'A\', u: number } -type B = { kind: \'B\', v: string } -type C = { kind: \'C\', y: boolean } -type D = { kind: \'D\', x: boolean } -type E = { kind: \'E\', y: boolean } +type A = { kind: 'A', u: number } +type B = { kind: 'B', v: string } +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); // OK -(my_filter(ab, (x): %checks => x.kind !== \'A\'): Array); // OK +(my_filter(ab, (x): %checks => x.kind === 'A'): Array); // OK +(my_filter(ab, (x): %checks => x.kind !== 'A'): Array); // OK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow // Filter the contents of an array @@ -51,14 +51,14 @@ declare var ab: Array; // OK declare function my_filter>(v: Array, cb: P): Array<$Refine>; -type A = { kind: \"A\"; u: number }; -type B = { kind: \"B\"; v: string }; -type C = { kind: \"C\"; y: boolean }; -type D = { kind: \"D\"; x: boolean }; -type E = { kind: \"E\"; y: boolean }; +type A = { kind: "A"; u: number }; +type B = { kind: "B"; v: string }; +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); +(my_filter(ab, (x): %checks => x.kind === "A"): Array); +(my_filter(ab, (x): %checks => x.kind !== "A"): Array); " `; @@ -66,7 +66,7 @@ exports[`test refine.js 1`] = ` "// @flow /* - $Pred is an \"abstract predicate type\", i.e. denotes a (function) type that + $Pred is an "abstract predicate type", i.e. denotes a (function) type that refines N variables. So if \`cb\` is a function, then it should be refining exactly N argument. It is abstract in that we do not need to specify: (a) which variables are going to be refined (just the number), or (b) what @@ -103,16 +103,16 @@ declare function refine2>(v: T, w: T, cb: P): $Refine; // { if (cb(v, w)) { return w; } else { throw new Error(); } } function is_string(x): boolean %checks { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_and_number(x, y): %checks { - return typeof x === \"string\" && typeof y === \"number\"; + return typeof x === "string" && typeof y === "number"; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow /* - $Pred is an \"abstract predicate type\", i.e. denotes a (function) type that + $Pred is an "abstract predicate type", i.e. denotes a (function) type that refines N variables. So if \`cb\` is a function, then it should be refining exactly N argument. It is abstract in that we do not need to specify: (a) which variables are going to be refined (just the number), or (b) what @@ -143,10 +143,10 @@ 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\"; + return typeof x === "string"; } function is_string_and_number(x, y): %checks { - return typeof x === \"string\" && typeof y === \"number\"; + return typeof x === "string" && typeof y === "number"; } " `; @@ -168,11 +168,11 @@ const d = my_filter(c, is_string_regular); (d: Array); function is_string(x): boolean %checks { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_regular(x): boolean { - return typeof x === \"string\"; + return typeof x === "string"; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow @@ -187,10 +187,10 @@ declare var c: Array; const d = my_filter(c, is_string_regular); (d: Array); function is_string(x): boolean %checks { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_regular(x): boolean { - return typeof x === \"string\"; + return typeof x === "string"; } " `; @@ -203,16 +203,16 @@ exports[`test sanity-filter-union.js 1`] = ` declare function my_filter>(v: Array, cb: P): Array<$Refine>; -type A = { kind: \'A\', u: number } -type B = { kind: \'B\', v: string } -type C = { kind: \'C\', y: boolean } -type D = { kind: \'D\', x: boolean } -type E = { kind: \'E\', y: boolean } +type A = { kind: 'A', u: number } +type B = { kind: 'B', v: string } +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); // ERROR -(my_filter(ab, (x): %checks => x.kind !== \'A\'): Array); // ERROR +(my_filter(ab, (x): %checks => x.kind === 'A'): Array); // ERROR +(my_filter(ab, (x): %checks => x.kind !== 'A'): Array); // ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow // Filter the contents of an array @@ -220,14 +220,14 @@ declare var ab: Array; // ERROR declare function my_filter>(v: Array, cb: P): Array<$Refine>; -type A = { kind: \"A\"; u: number }; -type B = { kind: \"B\"; v: string }; -type C = { kind: \"C\"; y: boolean }; -type D = { kind: \"D\"; x: boolean }; -type E = { kind: \"E\"; y: boolean }; +type A = { kind: "A"; u: number }; +type B = { kind: "B"; v: string }; +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); +(my_filter(ab, (x): %checks => x.kind === "A"): Array); +(my_filter(ab, (x): %checks => x.kind !== "A"): Array); " `; @@ -254,7 +254,7 @@ 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\"; + return typeof x === "string" && typeof y === "number"; } @@ -266,15 +266,15 @@ var e = refine(a, is_string_regular); // ERROR: is_string_regular is not a //////////////////////////////////////////////////////////////////////////////// function is_string(x): %checks { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_regular(x) { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_and_number(x, y): %checks { - return typeof x === \"string\" && typeof y === \"number\"; + return typeof x === "string" && typeof y === "number"; } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // @flow @@ -300,18 +300,18 @@ 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\"; + 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\"; + return typeof x === "string"; } function is_string_regular(x) { - return typeof x === \"string\"; + return typeof x === "string"; } function is_string_and_number(x, y): %checks { - return typeof x === \"string\" && typeof y === \"number\"; + return typeof x === "string" && typeof y === "number"; } " `; diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index 3968a14a1..aa82cec7e 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -11,7 +11,7 @@ function run_spec(dirname) { if (!RUN_AST_TESTS) { const source = read(path); - const output = prettyprint(source); + const output = prettyprint(source, path); test(filename, () => { expect(source + '~'.repeat(80) + '\n' + output).toMatchSnapshot(); }); @@ -24,7 +24,7 @@ function run_spec(dirname) { let ppast; let pperr = null; try { - ppast = parse(prettyprint(source)); + ppast = parse(prettyprint(source, path)); } catch(e) { pperr = e.stack; @@ -68,8 +68,8 @@ function parse(string) { return stripLocation(flowParser.parse(string)); } -function prettyprint(src) { - return jscodefmt.format(src); +function prettyprint(src, filename) { + return jscodefmt.format(src, { filename }); } function read(filename) {