git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix escaping for reserved name props in externs
commit5183422f274e5c4808efba21d010da3560c1dcf4 authorGary Burgess <gary.burgess@gmail.com> dateThu 1 May 2014, 21:42 (13 years ago) parent9d7e05b
3 files changed+11−3
src/Language/PureScript/Pretty/Common.hs+8 src/Language/PureScript/Pretty/Types.hs+1−1 src/Language/PureScript/Pretty/Values.hs+2−2
src/Language/PureScript/Pretty/Common.hs+8
@@ -17,6 +17,7 @@ module Language.PureScript.Pretty.Common where
1717
1818import Control.Monad.State
1919import Data.List (intercalate)
20+import Language.PureScript.Parser.Common (reservedPsNames)
2021
2122-- |
2223-- Wrap a string in parentheses
@@ -58,3 +59,10 @@ prettyPrintMany f xs = do
5859 ss <- mapM f xs
5960 indentString <- currentIndent
6061 return $ intercalate "\n" $ map (indentString ++) ss
62+
63+-- |
64+-- Prints an object key, escaping reserved names.
65+--
66+prettyPrintObjectKey :: String -> String
67+prettyPrintObjectKey s | s `elem` reservedPsNames = show s
68+ | otherwise = s
src/Language/PureScript/Pretty/Types.hs+1−1
@@ -51,7 +51,7 @@ prettyPrintRow :: Type -> String
5151prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs) tys) ++ tailToPs rest) . toList []
5252 where
5353 nameAndTypeToPs :: String -> Type -> String
54− nameAndTypeToPs name ty = name ++ " :: " ++ prettyPrintType ty
54+ nameAndTypeToPs name ty = prettyPrintObjectKey name ++ " :: " ++ prettyPrintType ty
5555 tailToPs :: Type -> String
5656 tailToPs REmpty = ""
5757 tailToPs other = " | " ++ prettyPrintType other
src/Language/PureScript/Pretty/Values.hs+2−2
@@ -215,12 +215,12 @@ matchConsBinder = mkPattern match'
215215
216216prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
217217prettyPrintObjectPropertyBinder (key, binder) = fmap concat $ sequence
218− [ return $ key ++ ": "
218+ [ return $ prettyPrintObjectKey key ++ ": "
219219 , prettyPrintBinder' binder
220220 ]
221221
222222prettyPrintObjectProperty :: (String, Value) -> StateT PrinterState Maybe String
223223prettyPrintObjectProperty (key, value) = fmap concat $ sequence
224− [ return $ key ++ ": "
224+ [ return $ prettyPrintObjectKey key ++ ": "
225225 , prettyPrintValue' value
226226 ]