git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix escaping for reserved name props in externs
5183422Gary Burgess
src/Language/PureScript/Pretty/Common.hs+8
@@ -17,6 +17,7 @@ module Language.PureScript.Pretty.Common where
17
17
18import Control.Monad.State
18import Control.Monad.State
19import Data.List (intercalate)
19import Data.List (intercalate)
20+import Language.PureScript.Parser.Common (reservedPsNames)
20
21
21-- |
22-- |
22-- Wrap a string in parentheses
23-- Wrap a string in parentheses
@@ -58,3 +59,10 @@ prettyPrintMany f xs = do
58 ss <- mapM f xs
59 ss <- mapM f xs
59 indentString <- currentIndent
60 indentString <- currentIndent
60 return $ intercalate "\n" $ map (indentString ++) ss
61 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
51prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs) tys) ++ tailToPs rest) . toList []
51prettyPrintRow = (\(tys, rest) -> intercalate ", " (map (uncurry nameAndTypeToPs) tys) ++ tailToPs rest) . toList []
52 where
52 where
53 nameAndTypeToPs :: String -> Type -> String
53 nameAndTypeToPs :: String -> Type -> String
54− nameAndTypeToPs name ty = name ++ " :: " ++ prettyPrintType ty
54+ nameAndTypeToPs name ty = prettyPrintObjectKey name ++ " :: " ++ prettyPrintType ty
55 tailToPs :: Type -> String
55 tailToPs :: Type -> String
56 tailToPs REmpty = ""
56 tailToPs REmpty = ""
57 tailToPs other = " | " ++ prettyPrintType other
57 tailToPs other = " | " ++ prettyPrintType other
src/Language/PureScript/Pretty/Values.hs+2−2
@@ -215,12 +215,12 @@ matchConsBinder = mkPattern match'
215
215
216prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
216prettyPrintObjectPropertyBinder :: (String, Binder) -> StateT PrinterState Maybe String
217prettyPrintObjectPropertyBinder (key, binder) = fmap concat $ sequence
217prettyPrintObjectPropertyBinder (key, binder) = fmap concat $ sequence
218− [ return $ key ++ ": "
218+ [ return $ prettyPrintObjectKey key ++ ": "
219 , prettyPrintBinder' binder
219 , prettyPrintBinder' binder
220 ]
220 ]
221
221
222prettyPrintObjectProperty :: (String, Value) -> StateT PrinterState Maybe String
222prettyPrintObjectProperty :: (String, Value) -> StateT PrinterState Maybe String
223prettyPrintObjectProperty (key, value) = fmap concat $ sequence
223prettyPrintObjectProperty (key, value) = fmap concat $ sequence
224− [ return $ key ++ ": "
224+ [ return $ prettyPrintObjectKey key ++ ": "
225 , prettyPrintValue' value
225 , prettyPrintValue' value
226 ]
226 ]