diff --git a/CHANGELOG.md b/CHANGELOG.md index 61dd38743d..0fe7020e8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Fixed +* Backticks in optional parameter gets removed [#2954](https://github.com/fsprojects/fantomas/issues/2954) + ## 6.2.0 - 2023-08-29 ### Changed diff --git a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs index 914d15faa0..a61e67990e 100644 --- a/src/Fantomas.Core.Tests/TypeDeclarationTests.fs +++ b/src/Fantomas.Core.Tests/TypeDeclarationTests.fs @@ -3593,6 +3593,23 @@ type ArrayBuffer = abstract slice: ``begin``: int * ?``end``: int -> ArrayBuffer """ +[] +let ``optional member parameter with ticks, 2954`` () = + formatSourceString + false + """ +type C() = + static member foo(?``type``) = ``type`` +""" + config + |> prepend newline + |> should + equal + """ +type C() = + static member foo(?``type``) = ``type`` +""" + [] let ``trivia before comma in primary constructor`` () = formatSourceString diff --git a/src/Fantomas.Core/ASTTransformer.fs b/src/Fantomas.Core/ASTTransformer.fs index 9e5ea201a8..a1b397ed7b 100644 --- a/src/Fantomas.Core/ASTTransformer.fs +++ b/src/Fantomas.Core/ASTTransformer.fs @@ -1630,7 +1630,9 @@ let mkPat (creationAide: CreationAide) (p: SynPat) = let patternRange = p.Range match p with - | SynPat.OptionalVal(ident, _) -> stn $"?{ident.idText}" patternRange |> Pattern.OptionalVal + | SynPat.OptionalVal(ident, _) -> + let identNode = mkIdent ident + SingleTextNode($"?{identNode.Text}", patternRange) |> Pattern.OptionalVal | PatParameter(ats, pat, t) -> PatParameterNode( mkAttributes creationAide ats,