on master help sign in
Get Elm.Compiler.Module working again
102ed8cEvan Czaplicki
src/Elm/Compiler/Module.hs+22−31
@@ -2,14 +2,13 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Module
3module Elm.Compiler.Module
4 -- interfaces
4 -- interfaces
5− ( Module.Interface
5+ ( I.Interface
6− , Module.Interfaces
6+ , I.Interfaces
7− , Module.privatize
8 , interfaceAliasedTypes
7 , interfaceAliasedTypes
9 , programTypes
8 , programTypes
10
9
11 -- module names
10 -- module names
12− , ModuleName.Raw
11+ , Raw
13 , nameToPath
12 , nameToPath
14 , nameToString
13 , nameToString
15 , nameFromText
14 , nameFromText
@@ -20,7 +19,6 @@ module Elm.Compiler.Module
20
19
21 -- canonical names
20 -- canonical names
22 , ModuleName.Canonical(..)
21 , ModuleName.Canonical(..)
23− , canonicalToMain
24 )
22 )
25 where
23 where
26
24
@@ -28,14 +26,13 @@ import qualified Data.Char as Char
28import qualified Data.List as List
26import qualified Data.List as List
29import qualified Data.Map as Map
27import qualified Data.Map as Map
30import qualified Data.Text as Text
28import qualified Data.Text as Text
31−import Data.Text (Text)
32import System.FilePath ((</>))
29import System.FilePath ((</>))
33
30
34−import qualified AST.Module as Module
35import qualified AST.Module.Name as ModuleName
31import qualified AST.Module.Name as ModuleName
36−import qualified Elm.Compiler.Type as PublicType
32+import qualified Elm.Compiler.Type as Type
37import qualified Elm.Compiler.Type.Extract as Extract
33import qualified Elm.Compiler.Type.Extract as Extract
38−import qualified Generate.JavaScript.Variable as JS
34+import qualified Elm.Interface as I
35+import qualified Elm.Name as N
39import qualified Json.Decode as Decode
36import qualified Json.Decode as Decode
40import qualified Json.Encode as Encode
37import qualified Json.Encode as Encode
41
38
@@ -44,46 +41,49 @@ import qualified Json.Encode as Encode
44-- INTERFACES
41-- INTERFACES
45
42
46
43
47−interfaceAliasedTypes :: Module.Interface -> Map.Map Text PublicType.Type
44+interfaceAliasedTypes :: I.Interface -> Map.Map N.Name Type.Type
48interfaceAliasedTypes interface =
45interfaceAliasedTypes interface =
49− Map.map Extract.extract (Module.iTypes interface)
46+ Map.map Extract.fromAnnotation (I._types interface)
50
47
51
48
52−programTypes :: Module.Interfaces -> ModuleName.Canonical -> Maybe PublicType.Program
49+programTypes :: I.Interfaces -> ModuleName.Canonical -> Maybe Type.Program
53programTypes =
50programTypes =
54− Extract.extractProgram
51+ Extract.fromProgram
55
52
56
53
57
54
58-- NAMES
55-- NAMES
59
56
60
57
58+type Raw = N.Name
59+
60+
61−nameToPath :: ModuleName.Raw -> FilePath
61+nameToPath :: Raw -> FilePath
62nameToPath name =
62nameToPath name =
63 List.foldl1 (</>) (map Text.unpack (Text.splitOn "." name))
63 List.foldl1 (</>) (map Text.unpack (Text.splitOn "." name))
64
64
65
65
66−nameToString :: ModuleName.Raw -> String
66+nameToString :: Raw -> String
67nameToString name =
67nameToString name =
68 Text.unpack name
68 Text.unpack name
69
69
70
70
71−nameFromText :: Text -> Maybe ModuleName.Raw
71+nameFromText :: Text.Text -> Maybe Raw
72nameFromText =
72nameFromText =
73 fromText '.'
73 fromText '.'
74
74
75
75
76−hyphenate :: ModuleName.Raw -> Text
76+hyphenate :: Raw -> Text.Text
77hyphenate name =
77hyphenate name =
78 Text.replace "." "-" name
78 Text.replace "." "-" name
79
79
80
80
81−dehyphenate :: Text -> Maybe ModuleName.Raw
81+dehyphenate :: Text.Text -> Maybe Raw
82dehyphenate =
82dehyphenate =
83 fromText '-'
83 fromText '-'
84
84
85
85
86−fromText :: Char -> Text -> Maybe ModuleName.Raw
86+fromText :: Char -> Text.Text -> Maybe Raw
87fromText sep name =
87fromText sep name =
88 let
88 let
89 chunks =
89 chunks =
@@ -92,7 +92,7 @@ fromText sep name =
92 if all isGoodChunk chunks then Just name else Nothing
92 if all isGoodChunk chunks then Just name else Nothing
93
93
94
94
95−isGoodChunk :: Text -> Bool
95+isGoodChunk :: Text.Text -> Bool
96isGoodChunk chunk =
96isGoodChunk chunk =
97 case Text.uncons chunk of
97 case Text.uncons chunk of
98 Nothing ->
98 Nothing ->
@@ -111,12 +111,12 @@ isGoodChar char =
111-- JSON
111-- JSON
112
112
113
113
114−encode :: ModuleName.Raw -> Encode.Value
114+encode :: Raw -> Encode.Value
115encode =
115encode =
116 Encode.text
116 Encode.text
117
117
118
118
119−decoder :: Decode.Decoder ModuleName.Raw
119+decoder :: Decode.Decoder Raw
120decoder =
120decoder =
121 do txt <- Decode.text
121 do txt <- Decode.text
122 case nameFromText txt of
122 case nameFromText txt of
@@ -125,12 +125,3 @@ decoder =
125
125
126 Just name ->
126 Just name ->
127 Decode.succeed name
127 Decode.succeed name
128−
129−
130−
131−-- CANONICAL TO MAIN
132−
133−
134−canonicalToMain :: ModuleName.Canonical -> Text
135−canonicalToMain home =
136− JS.globalToName home "main"