Skip to content

Commit 71ebb7b

Browse files
committed
Generate proper name for names involving tick characters purescript#133
1 parent 5e3f09c commit 71ebb7b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

examples/passing/Tick.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Tick where
2+
3+
test' x = x
4+
5+
module Main where
6+
7+
main = Trace.trace "Done"

src/Language/PureScript/Pretty/Common.hs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import Control.Arrow ((***), (<+>))
2626
import Language.PureScript.Names
2727

2828
identToJs :: Ident -> String
29-
identToJs (Ident name) = name
30-
identToJs (Op op) = concatMap opCharToString op
31-
where
32-
opCharToString :: Char -> String
33-
opCharToString = (:) '$'. show . ord
29+
identToJs (Ident name) = concatMap identCharToString name
30+
identToJs (Op op) = concatMap identCharToString op
31+
32+
identCharToString :: Char -> String
33+
identCharToString c | isAlphaNum c = [c]
34+
identCharToString '_' = "_"
35+
identCharToString c = '$' : show (ord c)
3436

3537
newtype Pattern u a b = Pattern { runPattern :: A.Kleisli (StateT u Maybe) a b } deriving (C.Category, A.Arrow, A.ArrowZero, A.ArrowPlus)
3638

0 commit comments

Comments
 (0)