Support Flow Enums with unknown members (#9432)

This commit is contained in:
George Zahariev authored and GitHub committed 2020-10-20 14:40:18 +08:00
1 parent 140cb14f3a
commit d59a107f4a
6 files changed
+97 -4

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#### Flow Enums with unknown members (#9432 by @gkz)
Previously, was not supported. Now, the following is formatted:
<!-- prettier-ignore -->
```jsx
// Input
enum E {
A,
B,
...
}
// Prettier stable: parse error
// Prettier master
enum E {
A,
B,
...
}
```
+11 -4
View File
@@ -2472,7 +2472,7 @@ function printPathNoParens(path, options, print, args) {
}
parts.push("of ", type, " ");
}
if (n.members.length === 0) {
if (n.members.length === 0 && !n.hasUnknownMembers) {
parts.push(
group(
concat([
@@ -2484,15 +2484,22 @@ function printPathNoParens(path, options, print, args) {
)
);
} else {
const members = n.members.length
? [
hardline,
printArrayItems(path, options, "members", print),
n.hasUnknownMembers || shouldPrintComma(options) ? "," : "",
]
: [];
parts.push(
group(
concat([
"{",
indent(
concat([
hardline,
printArrayItems(path, options, "members", print),
shouldPrintComma(options) ? "," : "",
...members,
...(n.hasUnknownMembers ? [hardline, "..."] : []),
])
),
comments.printDanglingComments(
@@ -0,0 +1,51 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`enum-unknown-members.js - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
// @flow
enum E {
A,
B,
...
}
=====================================output=====================================
// @flow
enum E {
A,
B,
...
}
================================================================================
`;
exports[`enum-unknown-members-empty.js - {"trailingComma":"all"} format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
// @flow
enum E {
...
}
=====================================output=====================================
// @flow
enum E {
...
}
================================================================================
`;
@@ -0,0 +1,5 @@
// @flow
enum E {
...
}
@@ -0,0 +1,7 @@
// @flow
enum E {
A,
B,
...
}
@@ -0,0 +1 @@
run_spec(__dirname, ["flow"], { trailingComma: "all" });