Skip to content

Commit

Permalink
Keep comment after opening bracket in ElmishReactWithoutChildren expr…
Browse files Browse the repository at this point in the history
…ession. Fixes fsprojects#2037. (fsprojects#2039)
  • Loading branch information
nojaf authored and jindraivanek committed Mar 30, 2022
1 parent 1d25e2f commit e5bbaad
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Fantomas.Tests/ElmishTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1444,3 +1444,23 @@ a [] [
// def
]
"""

[<Test>]
let ``comment after opening bracket in Elmish expression without children, 2037`` () =
formatSourceString
false
"""
ReactDom.render (React.strictMode [ // comment
App() ], root)
"""
config
|> prepend newline
|> should
equal
"""
ReactDom.render (
React.strictMode [ // comment
App() ],
root
)
"""
3 changes: 2 additions & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,8 @@ and genExpr astContext synExpr ctx =
openingTokenRange
(ifElse isArray sepOpenA sepOpenL)
+> atCurrentColumn (
col sepNln children (genExpr astContext)
sepNlnWhenWriteBeforeNewlineNotEmpty sepNone
+> col sepNln children (genExpr astContext)
+> onlyIf
(TriviaHelpers.``has content before that matches``
(fun tn -> RangeHelpers.rangeEq tn.Range closingTokenRange)
Expand Down

0 comments on commit e5bbaad

Please sign in to comment.