Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow: Print trailing comma in type parameters when --trailing-comma=es5 #14085

Merged
merged 7 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions changelog_unreleased/flow/14085.md
@@ -0,0 +1,40 @@
#### [BREAKING] Print trailing comma in type parameters and tuple types when `--trailing-comma=es5` (#14086, #14085 by @fisker)

<!-- prettier-ignore -->
```js
// Input
type Foo = [
{
from: string,
to: string,
}, // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }, // <- 2
>;

// Prettier stable
type Foo = [
{
from: string,
to: string,
} // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType } // <- 2
>;

// Prettier main
type Foo = [
{
from: string,
to: string,
}, // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }, // <- 2
>;
```
2 changes: 1 addition & 1 deletion src/language-js/print/type-parameters.js
Expand Up @@ -79,7 +79,7 @@ function printTypeParameters(path, options, print, paramsKey) {
!node[paramsKey][0].constraint &&
path.parent.type === "ArrowFunctionExpression"
? ","
: shouldPrintComma(options, "all")
: shouldPrintComma(options)
? ifBreak(",")
: "";

Expand Down
Expand Up @@ -69,7 +69,7 @@ const selectorByPath:
const selectorByPath: (Path) => SomethingSelector<
SomethingUEditorContextType,
SomethingUEditorContextType,
SomethingBulkValue<string>
SomethingBulkValue<string>,
> = memoizeWithArgs(/* ... */);
================================================================================
Expand Down
6 changes: 3 additions & 3 deletions tests/format/flow/generic/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -63,7 +63,7 @@ var X = {
E,
F,
G,
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren
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 {},
};
Expand Down Expand Up @@ -316,7 +316,7 @@ type State = {
type State = {
errors: Immutable.Map<
Ahohohhohohohohohohohohohohooh,
Fbt | Immutable.Map<ErrorIndex, Fbt>
Fbt | Immutable.Map<ErrorIndex, Fbt>,
>,
shouldValidate: boolean,
};
Expand Down Expand Up @@ -398,7 +398,7 @@ type Foo = Promise<
=====================================output=====================================
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType },
>;
================================================================================
Expand Down