on master help sign in
Fix errors in generated decoders for incoming JS values
2b86951Evan Czaplicki
src/Generate/JavaScript/Foreign.hs+10−11
@@ -177,8 +177,10 @@ toMaybe tipe =
177 Opt.Var (Var.inCore ["Maybe"] tag)
177 Opt.Var (Var.inCore ["Maybe"] tag)
178 in
178 in
179 to "oneOf" <==
179 to "oneOf" <==
180+ [ Opt.ExplicitList
180− [ to "null" <== [ maybe "Nothing" ]
181+ [ to "null" <== [ maybe "Nothing" ]
181− , to "map" <== [ maybe "Just", decode tipe ]
182+ , to "map" <== [ maybe "Just", decode tipe ]
183+ ]
182 ]
184 ]
183
185
184
186
@@ -199,16 +201,13 @@ toTuple types =
199toRecord :: [(String, T.Canonical)] -> Opt.Expr
201toRecord :: [(String, T.Canonical)] -> Opt.Expr
200toRecord fields =
202toRecord fields =
201 let
203 let
202− keys =
204+ toFieldExpr (key, _) =
203− map fst fields
204−
205− toField key =
206 (key, Opt.Var (Var.local key))
205 (key, Opt.Var (Var.local key))
207
206
208− rootExpr =
207+ finalDecoder =
209− to "succeed" <== [ Opt.Function keys (Opt.Record (map toField keys)) ]
208+ to "succeed" <== [ Opt.Record (map toFieldExpr fields) ]
210
209
211− andMap root (key, tipe) =
210+ andThen (key, tipe) decoder =
212− to "andMap" <== [ root, key =: decode tipe ]
211+ to "andThen" <== [ key =: decode tipe, Opt.Function [key] decoder ]
213 in
212 in
214− List.foldl' andMap rootExpr fields
213+ List.foldr andThen finalDecoder fields