Allow raw JavaScript values through ports (experiment)
commitcc9c97b3e6112395551e624cb29c825a4369cac8
authorEvan Czaplicki <info@elm-lang.org>
dateSun 9 Nov 2014, 01:35 (12 years ago)
parentc28b9df
compiler/AST/Variable.hs+3
@@ -32,6 +32,9 @@ is :: [String] -> String -> Canonical -> Bool
3232is home name var =
3333 var == Canonical (Module home) name
3434
35+isJavaScript :: Canonical -> Bool
36+isJavaScript = is ["JavaScript"] "Value"
37+
3538isJson :: Canonical -> Bool
3639isJson = is ["Json"] "Value"
3740
compiler/Generate/JavaScript/Ports.hs+11−3
@@ -73,9 +73,17 @@ inc tipe x =
7373 from checks = check x checks x
7474
7575 Type name
76− | Var.isJson name -> V.value ["Native","Json"] "fromJS" <| x
77− | Var.isTuple name -> incomingTuple [] x
78− | otherwise -> error "bad type got to incoming port generation code"
76+ | Var.isJavaScript name ->
77+ x
78+
79+ | Var.isJson name ->
80+ V.value ["Native","Json"] "fromJS" <| x
81+
82+ | Var.isTuple name ->
83+ incomingTuple [] x
84+
85+ | otherwise ->
86+ error "bad type got to incoming port generation code"
7987
8088 App f args ->
8189 case f : args of
compiler/Type/ExtraChecks.hs+4−5
@@ -62,11 +62,10 @@ portTypes expr =
6262 case tipe of
6363 ST.Aliased _ t -> valid t
6464
65− ST.Type v
66− | V.isJson v -> return ()
67− | V.isPrimitive v -> return ()
68− | V.isTuple v -> return ()
69− | otherwise -> err "an unsupported type"
65+ ST.Type v ->
66+ case any ($ v) [ V.isJson, V.isPrimitive, V.isTuple, V.isJavaScript ] of
67+ True -> return ()
68+ False -> err "an unsupported type"
7069
7170 ST.App t [] -> valid t
7271