From 1fc2e53dcd89e37a2fe3ce7e02d3632c38925b4b Mon Sep 17 00:00:00 2001 From: nojaf Date: Fri, 13 Nov 2020 18:25:15 +0100 Subject: [PATCH] Respect the order of keyword in a letbinding. Fixes #1250. --- src/Fantomas.Tests/LetBindingTests.fs | 23 +++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/LetBindingTests.fs b/src/Fantomas.Tests/LetBindingTests.fs index 5260671301..28dc33cffc 100644 --- a/src/Fantomas.Tests/LetBindingTests.fs +++ b/src/Fantomas.Tests/LetBindingTests.fs @@ -1161,3 +1161,26 @@ printfn "%s" (lookupMonth 12) printfn "%s" (lookupMonth 1) printfn "%s" (lookupMonth 13) // Throws an exception! """ + +[] +let ``print inline before private, 1250`` () = + formatSourceString false """ + let inline private isIdentifier t = t.CharClass = FSharpTokenCharKind.Identifier + let inline private isOperator t = t.CharClass = FSharpTokenCharKind.Operator + let inline private isKeyword t = t.ColorClass = FSharpTokenColorKind.Keyword + let inline private isPunctuation t = t.ColorClass = FSharpTokenColorKind.Punctuation +""" config + |> prepend newline + |> should equal """ +let inline private isIdentifier t = + t.CharClass = FSharpTokenCharKind.Identifier + +let inline private isOperator t = + t.CharClass = FSharpTokenCharKind.Operator + +let inline private isKeyword t = + t.ColorClass = FSharpTokenColorKind.Keyword + +let inline private isPunctuation t = + t.ColorClass = FSharpTokenColorKind.Punctuation +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index c935f1c832..cd9bf4fbe8 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -4352,9 +4352,9 @@ and getLetBindingFunction (astContext: ASTContext) else (!-pref +> genOnelinerAttributes astContext ats) let afterLetKeyword = - opt sepSpace ao genAccess - +> ifElse isMutable (!- "mutable ") sepNone + ifElse isMutable (!- "mutable ") sepNone +> ifElse isInline (!- "inline ") sepNone + +> opt sepSpace ao genAccess let genFunctionName = getIndentBetweenTicksFromSynPat patRange functionName