escape some javascript keywords

This commit is contained in:
2024-10-26 08:02:57 -07:00
parent e1ef6b5ee5
commit 3379e6ba3f

View File

@@ -159,9 +159,15 @@ termToJS env (CCase t alts) f =
jsString : String -> Doc jsString : String -> Doc
jsString str = text (show str) jsString str = text (show str)
keywords : List String
keywords = [
"var", "true", "false", "let", "case", "switch", "if", "then", "else",
"function", "void", "undefined", "null", "await", "async", "return", "const"
]
||| escape identifiers for js ||| escape identifiers for js
jsIdent : String -> Doc jsIdent : String -> Doc
jsIdent id = text $ pack $ fix (unpack id) jsIdent id = if elem id keywords then text ("$" ++ id) else text $ pack $ fix (unpack id)
where where
chars : List Char chars : List Char
chars = unpack "0123456789ABCDEF" chars = unpack "0123456789ABCDEF"