Skip to content

Commit

Permalink
Keep parentheses around dynamic operator ident, fixes #476
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Sep 13, 2019
1 parent b050a8e commit df6f31d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/Fantomas.Tests/DynamicOperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,20 @@ let ``Remove () when dynamic operator is string``() =
formatSourceString false "let memoEquals x = x?k" config
|> should equal """let memoEquals x = x?k
"""

[<Test>]
let ``keep () when dynamic operator inside boolean expr, #476`` () =
formatSourceString false """let fieldColor (fieldNameX: string) =
if f.errors?(fieldNameY) && f.touched?(fieldNameZ) then
IsDanger
else
NoColor
|> Input.Color
""" config
|> prepend newline
|> should equal """
let fieldColor (fieldNameX: string) =
if f.errors?(fieldNameY) && f.touched?(fieldNameZ) then IsDanger
else NoColor
|> Input.Color
"""
9 changes: 7 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,13 @@ and genInfixApps astContext hasNewLine synExprs =
| (s, opE, e)::es when(hasNewLine) ->
(sepNln +> tok opE.Range s +> sepSpace +> genExpr astContext e)
+> genInfixApps astContext (hasNewLine || checkNewLine e es) es
| (s, opE, e)::es when(NoSpaceInfixOps.Contains s) ->
(tok opE.Range s +> autoNln (genExpr astContext e))
| (s, opE, e)::es when(NoSpaceInfixOps.Contains s) ->
let wrapExpr f =
match synExprs with
| ("?", SynExpr.Ident(Ident("op_Dynamic")), SynExpr.Ident(_))::_ ->
sepOpenT +> f +> sepCloseT
| _ -> f
(tok opE.Range s +> autoNln (wrapExpr (genExpr astContext e)))
+> genInfixApps astContext (hasNewLine || checkNewLine e es) es
| (s, opE, e)::es ->
(sepSpace +> autoNln (tok opE.Range s +> sepSpace +> genCommentsAfterInfix (Some opE.Range) +> genExpr astContext e))
Expand Down

0 comments on commit df6f31d

Please sign in to comment.