Skip to content

Commit

Permalink
Preserve back ticks for ident after dynamic operator. Fixes fsproject…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Aug 16, 2020
1 parent ee6dd12 commit 7dfd6b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Fantomas.Tests/DynamicOperatorTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ let fieldColor (fieldNameX: string) =
then IsDanger
else NoColor
|> Input.Color
"""
"""

[<Test>]
let ``preserve back ticks from checked keyword, 937`` () =
formatSourceString false "let toggle = unbox<bool> (e.target?``checked``)" config
|> prepend newline
|> should equal """
let toggle = unbox<bool> (e.target?``checked``)
"""
3 changes: 3 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,9 @@ and genConst (c:SynConst) (r:range) =
!- stringContent
| None, Some({ ContentBefore = [Keyword({TokenInfo = { TokenName = "KEYWORD_STRING"; }; Content = kw})] }) ->
!- kw
| None, Some({ ContentBefore = [Keyword({TokenInfo = { TokenName = "QMARK" }})]
ContentItself = Some (IdentBetweenTicks ibt) }) ->
!- ibt
| None, Some({ ContentBefore = [Keyword({TokenInfo = { TokenName = "QMARK" }})] }) ->
!- s
| _ ->
Expand Down
3 changes: 2 additions & 1 deletion src/Fantomas/Trivia.fs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ let private addTriviaToTriviaNode
| MainNode("SynExpr.Ident")
| MainNode("SynPat.Named")
| MainNode("SynPat.LongIdent")
| MainNode("Ident") -> true
| MainNode("Ident")
| MainNode("SynExpr.Const") -> true
| _ -> false
isIdent && (t.Range.StartColumn = range.StartColumn || t.Range.StartColumn = range.StartColumn + 1) && t.Range.StartLine = range.StartLine
)
Expand Down

0 comments on commit 7dfd6b5

Please sign in to comment.