Skip to content

Commit

Permalink
Don't add extra parenthesis for DotGet(Paren(_)) (#991)
Browse files Browse the repository at this point in the history
* Don't add extra parenthesis for DotGet(Paren(_)), fixes #989

* Added regression test for #921.
  • Loading branch information
nojaf committed Aug 10, 2020
1 parent 44a2059 commit 7ae29ad
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
25 changes: 25 additions & 0 deletions src/Fantomas.Tests/LongIdentWithDotsTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,28 @@ module Client =
then JS.Alert(sprintf "Your email is %s" e.Vars.Email.Value)
e.Event.PreventDefault()).Bind()
"""

[<Test>]
let ``don't repeat parenthesis for DotGet Paren, 989`` () =
formatSourceString false """(something_really_long
+ another_thing_thats_really_long).A
""" config
|> prepend newline
|> should equal """
(something_really_long
+ another_thing_thats_really_long).A
"""

[<Test>]
let ``infix expression inside DotGet, 921`` () =
formatSourceString false """let variable =
(DataAccess.getById moduleName.readData
{ Id = createObject.Id }
|> Result.okValue).Value
""" config
|> prepend newline
|> should equal """
let variable =
(DataAccess.getById moduleName.readData { Id = createObject.Id }
|> Result.okValue).Value
"""
3 changes: 1 addition & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,8 +1864,7 @@ and genExpr astContext synExpr =
| DotNamedIndexedPropertySet(e, ident, e1, e2) ->
genExpr astContext e -- "." -- ident +> genExpr astContext e1 -- " <- " +> genExpr astContext e2
| DotGet(e, (s,_)) ->
let exprF = genExpr { astContext with IsInsideDotGet = true }
addParenIfAutoNln e exprF -- (sprintf ".%s" s)
genExpr { astContext with IsInsideDotGet = true } e -- (sprintf ".%s" s)
| DotSet(e1, s, e2) -> addParenIfAutoNln e1 (genExpr astContext) -- sprintf ".%s <- " s +> genExpr astContext e2

| SynExpr.Set(e1,e2, _) ->
Expand Down

0 comments on commit 7ae29ad

Please sign in to comment.