Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypopp committed Sep 6, 2024
1 parent 516c379 commit 9f283ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions ppx/browser/ppx_deriving_json_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,19 @@ module To_json = struct
let loc = t.rcd_loc in
let fs =
List.map2 t.rcd_fields es ~f:(fun ld x ->
let k = ld.pld_name in
let k = Option.value ~default:k (ld_attr_json_key ld) in
let v = derive ld.pld_type x in
let k =
let k = ld.pld_name in
Option.value ~default:k (ld_attr_json_key ld)
in
let v =
let v = derive ld.pld_type x in
match ld_drop_default ld with
| `No -> v
| `Drop_option ->
[%expr
match [%e x] with
| None -> Js.Undefined.empty
| Some _ -> Js.Undefined.return [%e v]]
| Stdlib.Option.None -> Js.Undefined.empty
| Stdlib.Option.Some _ -> Js.Undefined.return [%e v]]
in
map_loc lident k, v)
in
Expand Down
5 changes: 3 additions & 2 deletions ppx/native/ppx_deriving_json_native.ml
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,9 @@ module To_json = struct
| `Drop_option ->
[%expr
match [%e x] with
| None -> [%e ebnds]
| Some _ -> ([%e k], [%e v]) :: [%e ebnds]]
| Stdlib.Option.None -> [%e ebnds]
| Stdlib.Option.Some _ ->
([%e k], [%e v]) :: [%e ebnds]]
in
[%expr
let [%p pbnds] = [%e ebnds] in
Expand Down
4 changes: 2 additions & 2 deletions ppx/test/ppx_deriving_json_js.t
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,8 @@
a = int_to_json x_a;
b_opt =
(match x_b_opt with
| None -> Js.Undefined.empty
| Some _ ->
| Stdlib.Option.None -> Js.Undefined.empty
| Stdlib.Option.Some _ ->
Js.Undefined.return
((option_to_json int_to_json) x_b_opt));
}]
Expand Down
4 changes: 2 additions & 2 deletions ppx/test/ppx_deriving_json_native.t
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,8 @@
(let bnds__001_ = [] in
let bnds__001_ =
match x_b_opt with
| None -> bnds__001_
| Some _ ->
| Stdlib.Option.None -> bnds__001_
| Stdlib.Option.Some _ ->
("b_opt", (option_to_json int_to_json) x_b_opt)
:: bnds__001_
in
Expand Down

0 comments on commit 9f283ca

Please sign in to comment.