on master help sign in
Merge pull request #439 from maxsnew/safeNames
56c4fb9Evan Czaplicki
compiler/Generate/JavaScript.hs+2−2
@@ -311,7 +311,7 @@ generate unsafeModule =
311
311
312 jsImport modul = setup Nothing path ++ [ include ]
312 jsImport modul = setup Nothing path ++ [ include ]
313 where
313 where
314− path = split modul
314+ path = Help.splitDots modul
315 include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
315 include = assign path $ dotSep ("Elm" : path ++ ["make"]) <| ref "_elm"
316
316
317 setup namespace path = map create paths
317 setup namespace path = map create paths
@@ -351,7 +351,7 @@ binop span op e1 e2 =
351 func | Help.isOp operator = BracketRef () (dotSep (init parts ++ ["_op"])) (string operator)
351 func | Help.isOp operator = BracketRef () (dotSep (init parts ++ ["_op"])) (string operator)
352 | otherwise = dotSep parts
352 | otherwise = dotSep parts
353 where
353 where
354− parts = split op
354+ parts = Help.splitDots op
355 operator = last parts
355 operator = last parts
356
356
357 opDict = Map.fromList (infixOps ++ specialOps)
357 opDict = Map.fromList (infixOps ++ specialOps)
compiler/SourceSyntax/Helpers.hs+9
@@ -3,6 +3,15 @@ module SourceSyntax.Helpers where
3
3
4import qualified Data.Char as Char
4import qualified Data.Char as Char
5
5
6+splitDots :: String -> [String]
7+splitDots = go []
8+ where
9+ go vars str =
10+ case break (=='.') str of
11+ (x,_:rest) | isOp x -> vars ++ [x ++ '.' : rest]
12+ | otherwise -> go (vars ++ [x]) rest
13+ (x,[]) -> vars ++ [x]
14+
6brkt :: String -> String
15brkt :: String -> String
7brkt s = "{ " ++ s ++ " }"
16brkt s = "{ " ++ s ++ " }"
8
17
compiler/Transform/SafeNames.hs+8−4
@@ -1,16 +1,20 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Transform.SafeNames (metadataModule) where
2module Transform.SafeNames (metadataModule) where
3
3
4−import Control.Arrow (first, (***))
4+import Control.Arrow (first, (***))
5+import Data.List (intercalate)
6+
7+import qualified Data.Set as Set
8+
9+import qualified Parse.Helpers as PHelp
5import SourceSyntax.Expression
10import SourceSyntax.Expression
11+import qualified SourceSyntax.Helpers as SHelp
6import SourceSyntax.Location
12import SourceSyntax.Location
7import SourceSyntax.Module
13import SourceSyntax.Module
8import SourceSyntax.Pattern
14import SourceSyntax.Pattern
9−import qualified Data.Set as Set
10−import qualified Parse.Helpers as PHelp
11
15
12var :: String -> String
16var :: String -> String
13−var = dereserve . deprime
17+var = intercalate "." . map (dereserve . deprime) . SHelp.splitDots
14 where
18 where
15 deprime = map (\c -> if c == '\'' then '$' else c)
19 deprime = map (\c -> if c == '\'' then '$' else c)
16 dereserve x = case Set.member x PHelp.jsReserveds of
20 dereserve x = case Set.member x PHelp.jsReserveds of