git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Refactor JS string prettyprinting
33cfbe7Gary Burgess
src/Language/PureScript/Pretty/JS.hs+4−1
@@ -60,7 +60,7 @@ literals = mkPattern' match
60 where
60 where
61 match :: JS -> StateT PrinterState Maybe String
61 match :: JS -> StateT PrinterState Maybe String
62 match (JSNumericLiteral n) = return $ either show show n
62 match (JSNumericLiteral n) = return $ either show show n
63− match (JSStringLiteral s) = return $ '"' : concatMap encodeChar s ++ "\""
63+ match (JSStringLiteral s) = return $ string s
64 match (JSBooleanLiteral True) = return "true"
64 match (JSBooleanLiteral True) = return "true"
65 match (JSBooleanLiteral False) = return "false"
65 match (JSBooleanLiteral False) = return "false"
66 match (JSArrayLiteral xs) = fmap concat $ sequence
66 match (JSArrayLiteral xs) = fmap concat $ sequence
@@ -141,6 +141,9 @@ literals = mkPattern' match
141 match (JSRaw js) = return js
141 match (JSRaw js) = return js
142 match _ = mzero
142 match _ = mzero
143
143
144+string :: String -> String
145+string s = '"' : concatMap encodeChar s ++ "\""
146+ where
144 encodeChar :: Char -> String
147 encodeChar :: Char -> String
145 encodeChar '\b' = "\\b"
148 encodeChar '\b' = "\\b"
146 encodeChar '\t' = "\\t"
149 encodeChar '\t' = "\\t"