on master help sign in
Allow Json.Value through ports
commit32b7c18b1c4906317f4dd18ed6c46d6f85e29601 authorEvan Czaplicki <info@elm-lang.org> dateThu 27 Mar 2014, 18:34 (13 years ago) parentdfd14a1
3 files changed+14−5
compiler/Generate/JavaScript/Ports.hs+7−2 compiler/Metadata/Prelude.hs+3−1 compiler/Type/ExtraChecks.hs+4−2
compiler/Generate/JavaScript/Ports.hs+7−2
@@ -35,6 +35,10 @@ inc tipe x =
3535 case tipe of
3636 Lambda _ _ -> error "functions should not be allowed through input ports"
3737 Var _ -> error "type variables should not be allowed through input ports"
38+
39+ Data "Json.Value" [] ->
40+ obj "Native.Json.fromJS" <| x
41+
3842 Data ctor []
3943 | ctor == "Int" -> from JSNumber
4044 | ctor == "Float" -> from JSNumber
@@ -100,8 +104,9 @@ out tipe x =
100104
101105 Var _ -> error "type variables should not be allowed through input ports"
102106 Data ctor []
103− | ctor `elem` ["Int","Float","Bool","String"] ->
104− x
107+ | ctor `elem` ["Int","Float","Bool","String"] -> x
108+ | ctor == "Json.Value" ->
109+ obj "Native.Json.toJS" <| x
105110
106111 Data ctor [t]
107112 | ctor == "Maybe.Maybe" ->
compiler/Metadata/Prelude.hs+3−1
@@ -25,7 +25,9 @@ prelude = string ++ text ++ map (\n -> (n, Hiding [])) modules
2525 text = map ((,) "Text") [ As "Text", Hiding ["link", "color", "height"] ]
2626 string = map ((,) "String") [ As "String", Importing ["show"] ]
2727 modules = [ "Basics", "Signal", "List", "Maybe", "Time", "Color"
28− , "Graphics.Element", "Graphics.Collage", "Native.Ports" ]
28+ , "Graphics.Element", "Graphics.Collage"
29+ , "Native.Ports", "Native.Json"
30+ ]
2931
3032interfaces :: Bool -> IO Interfaces
3133interfaces noPrelude =
compiler/Type/ExtraChecks.hs+4−2
@@ -59,9 +59,11 @@ portTypes rules expr =
5959 | ctor == "Signal.Signal" -> handleSignal ts
6060 | otherwise -> err' True "an unsupported type"
6161 where
62+ primitives =
63+ ["Int","Float","String","Bool","Maybe.Maybe","_List","Json.Value"]
64+
6265 validConstructor =
63− ctor `elem` ["Int","Float","String","Bool","Maybe.Maybe","_List"]
64− || Help.isTuple ctor
66+ ctor `elem` primitives || Help.isTuple ctor
6567
6668 ST.Var _ -> err "free type variables"
6769