From 7ae29ada0e760e92dee700c712e74dfcb8c74a50 Mon Sep 17 00:00:00 2001 From: Florian Verdonck Date: Mon, 10 Aug 2020 08:42:17 +0200 Subject: [PATCH] Don't add extra parenthesis for DotGet(Paren(_)) (#991) * Don't add extra parenthesis for DotGet(Paren(_)), fixes #989 * Added regression test for #921. --- src/Fantomas.Tests/LongIdentWithDotsTests.fs | 25 ++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 3 +-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/LongIdentWithDotsTests.fs b/src/Fantomas.Tests/LongIdentWithDotsTests.fs index d40b1bbc36..5be6758a4f 100644 --- a/src/Fantomas.Tests/LongIdentWithDotsTests.fs +++ b/src/Fantomas.Tests/LongIdentWithDotsTests.fs @@ -199,3 +199,28 @@ module Client = then JS.Alert(sprintf "Your email is %s" e.Vars.Email.Value) e.Event.PreventDefault()).Bind() """ + +[] +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 +""" + +[] +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 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 3d32659f3d..be90c8a4b0 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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, _) ->