Align empty module declaration with TS (#19568)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-07-09 12:57:47 +08:00
1 parent a4e6f7a026
commit 6394c73209
7 files changed
+38 -14

No files matched your search

+14
View File
@@ -0,0 +1,14 @@
#### Stop enforcing empty module declaration to break (#19568 by @fisker)
<!-- prettier-ignore -->
```flow
// Input
declare module "foo" {}
// Prettier stable
declare module "foo" {
}
// Prettier main
declare module "foo" {}
```
+1
View File
@@ -48,6 +48,7 @@ function printBlock(path, options, print) {
parent.type === "ModuleExpression" || parent.type === "ModuleExpression" ||
(parent.type === "CatchClause" && !parentParent.finalizer) || (parent.type === "CatchClause" && !parentParent.finalizer) ||
parent.type === "TSModuleDeclaration" || parent.type === "TSModuleDeclaration" ||
parent.type === "DeclareModule" ||
parent.type === "MatchStatementCase" || parent.type === "MatchStatementCase" ||
node.type === "StaticBlock" node.type === "StaticBlock"
)) { )) {
@@ -22,11 +22,9 @@ declare module bar {
// that we implicitly assume in type-at-pos and coverage implementations. In // that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes a crash with coverage --color. // particular, when unchecked it causes a crash with coverage --color.
declare module foo { declare module foo {}
}
declare module bar { declare module bar {}
}
// TODO // TODO
@@ -46,8 +44,7 @@ declare module foo {
=====================================output===================================== =====================================output=====================================
// check coverage of declare module // check coverage of declare module
declare module foo { declare module foo {}
}
================================================================================ ================================================================================
`; `;
@@ -92,11 +89,9 @@ declare class qux {
// that we implicitly assume in type-at-pos and coverage implementations. In // that we implicitly assume in type-at-pos and coverage implementations. In
// particular, when unchecked it causes non-termination with coverage --color. // particular, when unchecked it causes non-termination with coverage --color.
declare module foo { declare module foo {}
}
declare module bar { declare module bar {}
}
// TODO // TODO
@@ -44,8 +44,7 @@ declare module "foo" {
declare var bar: string declare var bar: string
} }
declare module baz { declare module baz {}
}
================================================================================ ================================================================================
`; `;
@@ -66,8 +65,7 @@ declare module "foo" {
declare var bar: string; declare var bar: string;
} }
declare module baz { declare module baz {}
}
================================================================================ ================================================================================
`; `;
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`empty.ts format 1`] = `
====================================options=====================================
parsers: ["typescript", "flow"]
printWidth: 80 (default) |
=====================================input======================================
declare module "foo" {}
=====================================output=====================================
declare module "foo" {}
================================================================================
`;
@@ -0,0 +1 @@
declare module "foo" {}
@@ -0,0 +1 @@
runFormatTest(import.meta, ["typescript", "flow"]);