diff --git a/src/Fantomas.Tests/ElmishTests.fs b/src/Fantomas.Tests/ElmishTests.fs index e8c1c7cdaa..27655fad91 100644 --- a/src/Fantomas.Tests/ElmishTests.fs +++ b/src/Fantomas.Tests/ElmishTests.fs @@ -1324,3 +1324,119 @@ let Dashboard () = ] ] """ + +[] +let ``block comment in elmish expression with two lists, 1601`` () = + formatSourceString + false + """ +module CapitalGuardian.App + +open Fable.Core.JsInterop +open Fable.React +open Feliz + +[] +let private App () = + div [] [ + str "meh 2000k" + (* + {small && } + + {!small &&
} + {!small && } + {routeResult || } + + + *) + ] + +exportDefault App +""" + config + |> prepend newline + |> should + equal + """ +module CapitalGuardian.App + +open Fable.Core.JsInterop +open Fable.React +open Feliz + +[] +let private App () = + div [] [ + str "meh 2000k" + (* + {small && } + + {!small &&
} + {!small && } + {routeResult || } + + + *) + ] + +exportDefault App +""" + +[] +let ``block comment in elmish expression with two lists, two children`` () = + formatSourceString + false + """ +module CapitalGuardian.App + +open Fable.Core.JsInterop +open Fable.React +open Feliz + +[] +let private App () = + div [] [ + str "meh 2000k" + str "other meh" + (* + {small && } + + {!small &&
} + {!small && } + {routeResult || } + + + *) + ] + +exportDefault App +""" + config + |> prepend newline + |> should + equal + """ +module CapitalGuardian.App + +open Fable.Core.JsInterop +open Fable.React +open Feliz + +[] +let private App () = + div [] [ + str "meh 2000k" + str "other meh" + (* + {small && } + + {!small &&
} + {!small && } + {routeResult || } + + + *) + ] + +exportDefault App +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index d35bea5dd2..9af4d30a52 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1080,6 +1080,20 @@ and genExpr astContext synExpr ctx = (not ctx.Config.DisableElmishSyntax) -> let genChildren isShort = + let tokenSize = if isArray then 2 else 1 + + let openingTokenRange, openTokenType = + ctx.MkRangeWith + (childrenRange.Start.Line, childrenRange.Start.Column) + (childrenRange.Start.Line, (childrenRange.Start.Column + tokenSize)), + (if isArray then LBRACK_BAR else LBRACK) + + let closingTokenRange, closingTokenType = + ctx.MkRangeWith + (childrenRange.End.Line, (childrenRange.End.Column - tokenSize)) + (childrenRange.End.Line, childrenRange.End.Column), + (if isArray then BAR_RBRACK else RBRACK) + match children with | [] when (not isArray) -> sepOpenLFixed @@ -1088,39 +1102,31 @@ and genExpr astContext synExpr ctx = | [] when isArray -> sepOpenAFixed +> sepCloseAFixed | [ singleChild ] -> if isShort then - ifElse isArray sepOpenA sepOpenL + tokN openingTokenRange openTokenType (ifElse isArray sepOpenA sepOpenL) +> genExpr astContext singleChild - +> ifElse - isArray - sepCloseA - (sepCloseL - +> leaveNodeTokenByName childrenRange RBRACK) + +> tokN closingTokenRange closingTokenType (ifElse isArray sepCloseA sepCloseL) else - ifElse isArray sepOpenA sepOpenL + tokN openingTokenRange openTokenType (ifElse isArray sepOpenA sepOpenL) +> indent +> sepNln +> genExpr astContext singleChild +> unindent +> sepNln - +> ifElse - isArray - sepCloseAFixed - (sepCloseLFixed - +> leaveNodeTokenByName childrenRange RBRACK) + +> tokN closingTokenRange closingTokenType (ifElse isArray sepCloseAFixed sepCloseLFixed) | children -> if isShort then - ifElse isArray sepOpenA sepOpenL + tokN openingTokenRange openTokenType (ifElse isArray sepOpenA sepOpenL) +> col sepSemi children (genExpr astContext) - +> ifElse isArray sepCloseA sepCloseL + +> tokN closingTokenRange closingTokenType (ifElse isArray sepCloseA sepCloseL) else - ifElse isArray sepOpenA sepOpenL + tokN openingTokenRange openTokenType (ifElse isArray sepOpenA sepOpenL) +> indent +> sepNln +> col sepNln children (genExpr astContext) +> unindent +> sepNln - +> ifElse isArray sepCloseAFixed sepCloseLFixed + +> tokN closingTokenRange closingTokenType (ifElse isArray sepCloseAFixed sepCloseLFixed) let shortExpression = !-identifier