git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Rename `isIdent` to be more meaningful
commit06bd87e13b6f9578bfea988d28f9c115ae915178 authorGary Burgess <gary.burgess@gmail.com> dateFri 18 Jul 2014, 21:18 (12 years ago) parent7050984
3 files changed+12−12
src/Language/PureScript/CodeGen/Common.hs+6−6 src/Language/PureScript/CodeGen/JS.hs+3−3 src/Language/PureScript/Pretty/JS.hs+3−3
src/Language/PureScript/CodeGen/Common.hs+6−6
@@ -33,6 +33,12 @@ identToJs (Ident name) | nameIsJsReserved name = "$$" ++ name
3333identToJs (Ident name) = concatMap identCharToString name
3434identToJs (Op op) = concatMap identCharToString op
3535
36+-- |
37+-- Test if a string is a valid JS identifier without escaping.
38+--
39+identNeedsEscaping :: String -> Bool
40+identNeedsEscaping s = s /= identToJs (Ident s)
41+
3642-- |
3743-- Attempts to find a human-readable name for a symbol, if none has been specified returns the
3844-- ordinal value.
@@ -130,11 +136,5 @@ nameIsJsReserved name =
130136 , "with"
131137 , "yield" ]
132138
133−-- |
134−-- Test if a string is a valid JS identifier.
135−--
136−isIdent :: String -> Bool
137−isIdent s = identToJs (Ident s) == s
138−
139139moduleNameToJs :: ModuleName -> String
140140moduleNameToJs (ModuleName pns) = intercalate "_" (runProperName `map` pns)
src/Language/PureScript/CodeGen/JS.hs+3−3
@@ -20,7 +20,7 @@ module Language.PureScript.CodeGen.JS (
2020 ModuleType(..),
2121 declToJs,
2222 moduleToJs,
23− isIdent
23+ identNeedsEscaping
2424) where
2525
2626import Data.Maybe (catMaybes, fromJust, fromMaybe)
@@ -179,8 +179,8 @@ accessor (Ident prop) = accessorString prop
179179accessor (Op op) = JSIndexer (JSStringLiteral op)
180180
181181accessorString :: String -> JS -> JS
182−accessorString prop | isIdent prop = JSAccessor prop
183− | otherwise = JSIndexer (JSStringLiteral prop)
182+accessorString prop | identNeedsEscaping prop = JSIndexer (JSStringLiteral prop)
183+ | otherwise = JSAccessor prop
184184
185185-- |
186186-- Generate code in the simplified Javascript intermediate representation for a value or expression.
src/Language/PureScript/Pretty/JS.hs+3−3
@@ -18,7 +18,7 @@ module Language.PureScript.Pretty.JS (
1818) where
1919
2020import Language.PureScript.Pretty.Common
21−import Language.PureScript.CodeGen.JS (isIdent)
21+import Language.PureScript.CodeGen.JS (identNeedsEscaping)
2222import Language.PureScript.CodeGen.JS.AST
2323
2424import Data.List
@@ -56,8 +56,8 @@ literals = mkPattern' match
5656 ]
5757 where
5858 objectPropertyToString :: String -> String
59− objectPropertyToString s | isIdent s = s
60− | otherwise = show s
59+ objectPropertyToString s | identNeedsEscaping s = show s
60+ | otherwise = s
6161 match (JSBlock sts) = fmap concat $ sequence
6262 [ return "{\n"
6363 , withIndent $ prettyStatements sts