From 3379e6ba3ff5777082ef9b184a9e5f98e1662693 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Sat, 26 Oct 2024 08:02:57 -0700 Subject: [PATCH] escape some javascript keywords --- src/Lib/Compile.idr | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Lib/Compile.idr b/src/Lib/Compile.idr index 16ca295..fea793f 100644 --- a/src/Lib/Compile.idr +++ b/src/Lib/Compile.idr @@ -159,9 +159,15 @@ termToJS env (CCase t alts) f = jsString : String -> Doc 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 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 chars : List Char chars = unpack "0123456789ABCDEF"