Skip to content

Commit

Permalink
Fix problem with empty nested module generation (#2729)
Browse files Browse the repository at this point in the history
  • Loading branch information
josh-degraw committed Jan 19, 2023
1 parent a6ecc25 commit 959e49b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
* Optional constructor arguments are lost. [#2718](https://github.com/fsprojects/fantomas/issues/2718)
* Empty nested module. [#2721](https://github.com/fsprojects/fantomas/issues/2721~~~~)

## [5.2.0-alpha-012] - 2023-01-14

Expand Down
17 changes: 17 additions & 0 deletions src/Fantomas.Core.Tests/ModuleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,20 @@ module Ionide.VSCode.FSharp
open global.Node.ChildProcess
"""

[<Test>]
let ``empty nested module, 2721`` () =
formatSourceString
true
"""
module Graph =
begin end
"""
config
|> prepend newline
|> should
equal
"""
module Graph =
begin end
"""
6 changes: 5 additions & 1 deletion src/Fantomas.Core/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3591,8 +3591,12 @@ let genModuleDecl (md: ModuleDecl) =
+> sepSpace
+> genSingleTextNode node.Equals
+> indentSepNlnUnindent (
colWithNlnWhenMappedNodeIsMultiline false ModuleDecl.Node genModuleDecl node.Declarations
ifElse
(List.isEmpty node.Declarations)
(!- "begin end")
(colWithNlnWhenMappedNodeIsMultiline false ModuleDecl.Node genModuleDecl node.Declarations)
)

|> genNode (ModuleDecl.Node md)
| ModuleDecl.TypeDefn td -> genTypeDefn td
| ModuleDecl.Val node -> genVal node None
Expand Down

0 comments on commit 959e49b

Please sign in to comment.