on master help sign in
update for lack of OverloadedStrings on Json.String type

That was taken away so that more awareness is needed. This way it is less likely that something sneaks into the Json.String type without proper escaping.

commitb1f765c7c18a3148e35cfef12a13824e3079f773 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 3 Jun 2019, 11:07 (7 years ago) parent9da3c61
1 file changed+26−27
compiler/src/Elm/Compiler/Type.hs+26−27
compiler/src/Elm/Compiler/Type.hs+26−27
@@ -15,9 +15,12 @@ module Elm.Compiler.Type
1515
1616
1717import qualified Data.Name as Name
18−import qualified Data.Utf8 as Utf8
1918
2019import qualified AST.Source as Src
20+import qualified Json.Decode as D
21+import qualified Json.Encode as E
22+import Json.Encode ((==>))
23+import qualified Json.String as Json
2124import qualified Parse.Primitives as P
2225import qualified Parse.Type as Type
2326import qualified Reporting.Annotation as A
@@ -25,10 +28,6 @@ import qualified Reporting.Doc as D
2528import qualified Reporting.Render.Type as RT
2629import qualified Reporting.Render.Type.Localizer as L
2730
28−import qualified Json.Decode as D
29−import qualified Json.Encode as E
30−import Json.Encode ((==>))
31−
3231
3332
3433-- TYPES
@@ -114,18 +113,16 @@ collectLambdas tipe =
114113
115114encode :: Type -> E.Value
116115encode tipe =
117− E.string $ Utf8.fromChars $ D.toLine (toDoc L.empty RT.None tipe)
116+ E.chars $ D.toLine (toDoc L.empty RT.None tipe)
118117
119118
120119decoder :: D.Decoder () Type
121120decoder =
122− do str <- D.string
123− case P.fromByteString Type.expression (error "TODO turn Utf8 to something that can be parsed" str) of
124− P.Ok (tipe, _, _) _ ->
125− return (fromRawType tipe)
126−
127− P.Err _ _ _ _ ->
128− D.failure ()
121+ let
122+ parser =
123+ P.specialize (\_ _ _ -> ()) (fromRawType . fst <$> Type.expression)
124+ in
125+ D.customString parser (\_ _ -> ())
129126
130127
131128fromRawType :: Src.Type -> Type
@@ -167,29 +164,31 @@ encodeMetadata :: DebugMetadata -> E.Value
167164encodeMetadata (DebugMetadata msg aliases unions) =
168165 E.object
169166 [ "message" ==> encode msg
170− , "aliases" ==> E.object (map toAliasField aliases)
171− , "unions" ==> E.object (map toUnionField unions)
167+ , "aliases" ==> E.object (map toTypeAliasField aliases)
168+ , "unions" ==> E.object (map toCustomTypeField unions)
172169 ]
173170
174171
175−toAliasField :: Alias -> ( Utf8.String, E.Value )
176−toAliasField (Alias name args tipe) =
177− Name.toUtf8 name ==>
178− E.object
172+toTypeAliasField :: Alias -> ( Json.String, E.Value )
173+toTypeAliasField (Alias name args tipe) =
174+ ( Json.fromName name
175+ , E.object
179176 [ "args" ==> E.list E.name args
180177 , "type" ==> encode tipe
181178 ]
179+ )
182180
183181
184−toUnionField :: Union -> ( Utf8.String, E.Value )
185−toUnionField (Union name args constructors) =
186− Name.toUtf8 name ==>
187− E.object
182+toCustomTypeField :: Union -> ( Json.String, E.Value )
183+toCustomTypeField (Union name args constructors) =
184+ ( Json.fromName name
185+ , E.object
188186 [ "args" ==> E.list E.name args
189− , "tags" ==> E.object (map toCtorObject constructors)
187+ , "tags" ==> E.object (map toVariantObject constructors)
190188 ]
189+ )
191190
192191
193−toCtorObject :: (Name.Name, [Type]) -> ( Utf8.String, E.Value )
194−toCtorObject (name, args) =
195− Name.toUtf8 name ==> E.list encode args
192+toVariantObject :: (Name.Name, [Type]) -> ( Json.String, E.Value )
193+toVariantObject (name, args) =
194+ ( Json.fromName name, E.list encode args )