From c0a0bf46bc4ea845e1580b17e54b97ed6c27924e Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Fri, 21 Apr 2017 15:57:21 -0500 Subject: [PATCH] Fix missing trailing commas on flow generics (#1381) --- src/printer.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 65 +++++++++++++++++++ tests/flow_generic/jsfmt.spec.js | 1 + tests/flow_generic/trailing.js | 7 ++ 4 files changed, 74 insertions(+) create mode 100644 tests/flow_generic/trailing.js diff --git a/src/printer.js b/src/printer.js index 03793f87..25a5440f 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1864,6 +1864,7 @@ function genericPrintNoParens(path, options, print, args) { join(concat([",", line]), path.map(print, "params")) ]) ), + ifBreak(shouldPrintComma(options, "all") ? "," : ""), softline, ">" ]) diff --git a/tests/flow_generic/__snapshots__/jsfmt.spec.js.snap b/tests/flow_generic/__snapshots__/jsfmt.spec.js.snap index 33bfbda8..eecfba4a 100644 --- a/tests/flow_generic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow_generic/__snapshots__/jsfmt.spec.js.snap @@ -26,3 +26,68 @@ var X = { }; `; + +exports[`break.js 2`] = ` +var X = { + perform: function< + A, B, C, D, E, F, G, + T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren + >( + method: T, scope: any, + a: A, b: B, c: C, d: D, e: E, f: F, + ): G { + } +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +var X = { + perform: function< + A, + B, + C, + D, + E, + F, + G, + T: (a: A, b: B, c: C, d: D, e: E, f: F) => G, // eslint-disable-line space-before-function-paren + >(method: T, scope: any, a: A, b: B, c: C, d: D, e: E, f: F): G {}, +}; + +`; + +exports[`trailing.js 1`] = ` +type State = { + errors: Immutable.Map< + Ahohohhohohohohohohohohohohooh, + Fbt | Immutable.Map + >, + shouldValidate: boolean, +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type State = { + errors: Immutable.Map< + Ahohohhohohohohohohohohohohooh, + Fbt | Immutable.Map + >, + shouldValidate: boolean +}; + +`; + +exports[`trailing.js 2`] = ` +type State = { + errors: Immutable.Map< + Ahohohhohohohohohohohohohohooh, + Fbt | Immutable.Map + >, + shouldValidate: boolean, +}; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type State = { + errors: Immutable.Map< + Ahohohhohohohohohohohohohohooh, + Fbt | Immutable.Map, + >, + shouldValidate: boolean, +}; + +`; diff --git a/tests/flow_generic/jsfmt.spec.js b/tests/flow_generic/jsfmt.spec.js index 989047bc..220f446b 100644 --- a/tests/flow_generic/jsfmt.spec.js +++ b/tests/flow_generic/jsfmt.spec.js @@ -1 +1,2 @@ run_spec(__dirname); +run_spec(__dirname, { trailingComma: 'all' }); diff --git a/tests/flow_generic/trailing.js b/tests/flow_generic/trailing.js new file mode 100644 index 00000000..7ca16693 --- /dev/null +++ b/tests/flow_generic/trailing.js @@ -0,0 +1,7 @@ +type State = { + errors: Immutable.Map< + Ahohohhohohohohohohohohohohooh, + Fbt | Immutable.Map + >, + shouldValidate: boolean, +};