Skip to content

Commit 6394c73

Browse files
authored
Align empty module declaration with TS (#19568)
1 parent a4e6f7a commit 6394c73

7 files changed

Lines changed: 38 additions & 14 deletions

File tree

‎changelog_unreleased/flow/19568.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#### Stop enforcing empty module declaration to break (#19568 by @fisker)
2+
3+
<!-- prettier-ignore -->
4+
```flow
5+
// Input
6+
declare module "foo" {}
7+
8+
// Prettier stable
9+
declare module "foo" {
10+
}
11+
12+
// Prettier main
13+
declare module "foo" {}
14+
```

‎src/language-js/print/block.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function printBlock(path, options, print) {
4848
parent.type === "ModuleExpression" ||
4949
(parent.type === "CatchClause" && !parentParent.finalizer) ||
5050
parent.type === "TSModuleDeclaration" ||
51+
parent.type === "DeclareModule" ||
5152
parent.type === "MatchStatementCase" ||
5253
node.type === "StaticBlock"
5354
)) {

‎tests/format/flow/flow-repo/coverage/__snapshots__/format.test.js.snap‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ declare module bar {
2222
// that we implicitly assume in type-at-pos and coverage implementations. In
2323
// particular, when unchecked it causes a crash with coverage --color.
2424
25-
declare module foo {
26-
}
25+
declare module foo {}
2726
28-
declare module bar {
29-
}
27+
declare module bar {}
3028
3129
// TODO
3230
@@ -46,8 +44,7 @@ declare module foo {
4644
=====================================output=====================================
4745
// check coverage of declare module
4846
49-
declare module foo {
50-
}
47+
declare module foo {}
5148
5249
================================================================================
5350
`;
@@ -92,11 +89,9 @@ declare class qux {
9289
// that we implicitly assume in type-at-pos and coverage implementations. In
9390
// particular, when unchecked it causes non-termination with coverage --color.
9491
95-
declare module foo {
96-
}
92+
declare module foo {}
9793
98-
declare module bar {
99-
}
94+
declare module bar {}
10095
10196
// TODO
10297

‎tests/format/flow/type-declarations/__snapshots__/format.test.js.snap‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ declare module "foo" {
4444
declare var bar: string
4545
}
4646
47-
declare module baz {
48-
}
47+
declare module baz {}
4948
5049
================================================================================
5150
`;
@@ -66,8 +65,7 @@ declare module "foo" {
6665
declare var bar: string;
6766
}
6867
69-
declare module baz {
70-
}
68+
declare module baz {}
7169
7270
================================================================================
7371
`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`empty.ts format 1`] = `
4+
====================================options=====================================
5+
parsers: ["typescript", "flow"]
6+
printWidth: 80 (default) |
7+
=====================================input======================================
8+
declare module "foo" {}
9+
10+
=====================================output=====================================
11+
declare module "foo" {}
12+
13+
================================================================================
14+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module "foo" {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runFormatTest(import.meta, ["typescript", "flow"]);

0 commit comments

Comments
 (0)