Skip to content

Commit

Permalink
Fix: print trivia for infix app. (#522)
Browse files Browse the repository at this point in the history
* Fix: print trivia for infix app.

* Added test for both code branches
  • Loading branch information
nojaf authored and jindraivanek committed Oct 19, 2019
1 parent 97adf4f commit c2338f3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,44 @@ try
()
#endif
with _ -> ()
"""

[<Test>]
let ``preserve compile directive between piped functions (DEBUG), 512`` () =
formatSourceStringWithDefines ["DEBUG"] """let foo = [ 1 ]
|> List.sort
#if DEBUG
|> List.rev
#endif
|> List.sort
""" config
|> prepend newline
|> should equal """
let foo =
[ 1 ]
|> List.sort
#if DEBUG
|> List.rev
#endif
|> List.sort
"""

[<Test>]
let ``preserve compile directive between piped functions, 512`` () =
formatSourceString false """let foo = [ 1 ]
|> List.sort
#if DEBUG
|> List.rev
#endif
|> List.sort
""" config
|> prepend newline
|> should equal """
let foo =
[ 1 ]
|> List.sort
#if DEBUG
|> List.rev
#endif
|> List.sort
"""
2 changes: 1 addition & 1 deletion src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1229,7 +1229,7 @@ and genInfixApps astContext hasNewLine synExprs =
genExpr ctx))
+> genInfixApps astContext (hasNewLine || checkNewLine e es) es
| (s, opE, e)::es when(hasNewLine) ->
(sepNln +> tok opE.Range s +> sepSpace +> genExpr astContext e)
(sepNln +> (tok opE.Range s |> genTrivia opE.Range) +> sepSpace +> genExpr astContext e)
+> genInfixApps astContext (hasNewLine || checkNewLine e es) es
| (s, opE, e)::es when(NoSpaceInfixOps.Contains s) ->
let wrapExpr f =
Expand Down

0 comments on commit c2338f3

Please sign in to comment.