From 8d4151c49363e4059d3dc29780abeceeb8551962 Mon Sep 17 00:00:00 2001 From: Javier Chavarri Date: Mon, 26 Aug 2024 15:52:42 +0000 Subject: [PATCH] ppx: qualify usages of stdlib infix operators --- ppx/browser/ppx_deriving_json_js.ml | 29 +++--- ppx/test/ppx_deriving_json_js.t | 136 ++++++++++++++++------------ 2 files changed, 95 insertions(+), 70 deletions(-) diff --git a/ppx/browser/ppx_deriving_json_js.ml b/ppx/browser/ppx_deriving_json_js.ml index 4be4695..e28a060 100644 --- a/ppx/browser/ppx_deriving_json_js.ml +++ b/ppx/browser/ppx_deriving_json_js.ml @@ -55,9 +55,11 @@ module Of_json = struct let eis_json_object ~loc x = [%expr - Js.typeof [%e x] = "object" - && (not (Js.Array.isArray [%e x])) - && not ((Obj.magic [%e x] : 'a Js.null) == Js.null)] + Stdlib.( && ) + (Js.typeof [%e x] = "object") + (Stdlib.( && ) + (not (Js.Array.isArray [%e x])) + (not (Stdlib.( == ) (Obj.magic [%e x] : 'a Js.null) Js.null)))] let ensure_json_object ~loc x = [%expr @@ -67,7 +69,7 @@ module Of_json = struct let ensure_json_array_len ~loc n len = [%expr - if [%e len] <> [%e eint ~loc n] then + if Stdlib.( <> ) [%e len] [%e eint ~loc n] then Ppx_deriving_json_runtime.of_json_error [%e estring ~loc (sprintf "expected a JSON array of length %i" n)]] @@ -77,9 +79,11 @@ module Of_json = struct let n = List.length t.tpl_types in [%expr if - Js.Array.isArray [%e x] - && Js.Array.length (Obj.magic [%e x] : Js.Json.t array) - = [%e eint ~loc n] + Stdlib.( && ) + (Js.Array.isArray [%e x]) + (Stdlib.( = ) + (Js.Array.length (Obj.magic [%e x] : Js.Json.t array)) + [%e eint ~loc n]) then let es = (Obj.magic [%e x] : Js.Json.t array) in [%e build_tuple ~loc derive 0 t.tpl_types [%expr es]] @@ -113,7 +117,7 @@ module Of_json = struct if Js.Array.isArray [%e x] then let array = (Obj.magic [%e x] : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in @@ -135,13 +139,14 @@ module Of_json = struct let loc = n.loc in let n = Option.value ~default:n (vcs_attr_json_as ctx) in [%expr - if tag = [%e estring ~loc:n.loc n.txt] then [%e make None] + if Stdlib.( = ) tag [%e estring ~loc:n.loc n.txt] then + [%e make None] else [%e next]] | Vcs_record (n, r) -> let loc = n.loc in let n = Option.value ~default:n (vcs_attr_json_as r.rcd_ctx) in [%expr - if tag = [%e estring ~loc:n.loc n.txt] then ( + if Stdlib.( = ) tag [%e estring ~loc:n.loc n.txt] then ( [%e ensure_json_array_len ~loc 2 [%expr len]]; let fs = Js.Array.unsafe_get array 1 in [%e ensure_json_object ~loc [%expr fs]]; @@ -154,10 +159,10 @@ module Of_json = struct let n = Option.value ~default:n (vcs_attr_json_as t.tpl_ctx) in let arity = List.length t.tpl_types in [%expr - if tag = [%e estring ~loc:n.loc n.txt] then ( + if Stdlib.( = ) tag [%e estring ~loc:n.loc n.txt] then ( [%e ensure_json_array_len ~loc (arity + 1) [%expr len]]; [%e - if arity = 0 then make None + if Stdlib.( = ) arity 0 then make None else make (Some diff --git a/ppx/test/ppx_deriving_json_js.t b/ppx/test/ppx_deriving_json_js.t index 70fc2f2..584de4e 100644 --- a/ppx/test/ppx_deriving_json_js.t +++ b/ppx/test/ppx_deriving_json_js.t @@ -78,8 +78,10 @@ let rec tuple_of_json = (fun x -> if - Js.Array.isArray x - && Js.Array.length (Obj.magic x : Js.Json.t array) = 2 + Stdlib.( && ) (Js.Array.isArray x) + (Stdlib.( = ) + (Js.Array.length (Obj.magic x : Js.Json.t array)) + 2) then let es = (Obj.magic x : Js.Json.t array) in ( int_of_json (Js.Array.unsafe_get es 0), @@ -118,9 +120,11 @@ (fun x -> if not - (Js.typeof x = "object" - && (not (Js.Array.isArray x)) - && not ((Obj.magic x : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof x = "object") + (Stdlib.( && ) + (not (Js.Array.isArray x)) + (not (Stdlib.( == ) (Obj.magic x : 'a Js.null) Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object"; let fs = @@ -180,9 +184,11 @@ (fun x -> if not - (Js.typeof x = "object" - && (not (Js.Array.isArray x)) - && not ((Obj.magic x : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof x = "object") + (Stdlib.( && ) + (not (Js.Array.isArray x)) + (not (Stdlib.( == ) (Obj.magic x : 'a Js.null) Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object"; let fs = @@ -239,9 +245,11 @@ (fun x -> if not - (Js.typeof x = "object" - && (not (Js.Array.isArray x)) - && not ((Obj.magic x : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof x = "object") + (Stdlib.( && ) + (not (Js.Array.isArray x)) + (not (Stdlib.( == ) (Obj.magic x : 'a Js.null) Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object"; let fs = (Obj.magic x : < k : Js.Json.t Js.undefined > Js.t) in @@ -283,30 +291,35 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 1 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 1 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 1"; A) - else if tag = "B" then ( - if len <> 2 then + else if Stdlib.( = ) tag "B" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; B (int_of_json (Js.Array.unsafe_get array 1))) - else if tag = "C" then ( - if len <> 2 then + else if Stdlib.( = ) tag "C" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; let fs = Js.Array.unsafe_get array 1 in if not - (Js.typeof fs = "object" - && (not (Js.Array.isArray fs)) - && not ((Obj.magic fs : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof fs = "object") + (Stdlib.( && ) + (not (Js.Array.isArray fs)) + (not + (Stdlib.( == ) + (Obj.magic fs : 'a Js.null) + Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object"; @@ -372,7 +385,7 @@ let rec other_of_json_poly = (fun x -> let tag = Ppx_deriving_json_runtime.Primitives.string_of_json x in - if tag = "C" then Some `C else None + if Stdlib.( = ) tag "C" then Some `C else None : Js.Json.t -> other option) and other_of_json = @@ -407,17 +420,17 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 1 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 1 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 1"; Some `A) - else if tag = "B" then ( - if len <> 2 then + else if Stdlib.( = ) tag "B" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; Some (`B (int_of_json (Js.Array.unsafe_get array 1)))) @@ -477,12 +490,12 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "C" then ( - if len <> 2 then + if Stdlib.( = ) tag "C" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; Some (`C (a_of_json (Js.Array.unsafe_get array 1)))) @@ -532,17 +545,17 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 1 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 1 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 1"; A) - else if tag = "Fix" then ( - if len <> 2 then + else if Stdlib.( = ) tag "Fix" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; Fix (recur_of_json (Js.Array.unsafe_get array 1))) @@ -590,17 +603,17 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 1 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 1 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 1"; Some `A) - else if tag = "Fix" then ( - if len <> 2 then + else if Stdlib.( = ) tag "Fix" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; Some @@ -655,8 +668,8 @@ let rec evar_of_json = (fun x -> let tag = Ppx_deriving_json_runtime.Primitives.string_of_json x in - if tag = "A" then A - else if tag = "b_aliased" then B + if Stdlib.( = ) tag "A" then A + else if Stdlib.( = ) tag "b_aliased" then B else Ppx_deriving_json_runtime.of_json_error "invalid JSON" : Js.Json.t -> evar) @@ -687,8 +700,8 @@ let rec epoly_of_json_poly = (fun x -> let tag = Ppx_deriving_json_runtime.Primitives.string_of_json x in - if tag = "A_aliased" then Some `a - else if tag = "b" then Some `b + if Stdlib.( = ) tag "A_aliased" then Some `a + else if Stdlib.( = ) tag "b" then Some `b else None : Js.Json.t -> epoly option) @@ -729,17 +742,17 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 2 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; A (a_of_json (Js.Array.unsafe_get array 1))) - else if tag = "B" then ( - if len <> 2 then + else if Stdlib.( = ) tag "B" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; B (b_of_json (Js.Array.unsafe_get array 1))) @@ -784,9 +797,11 @@ (fun x -> if not - (Js.typeof x = "object" - && (not (Js.Array.isArray x)) - && not ((Obj.magic x : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof x = "object") + (Stdlib.( && ) + (not (Js.Array.isArray x)) + (not (Stdlib.( == ) (Obj.magic x : 'a Js.null) Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object"; let fs = (Obj.magic x : < a : Js.Json.t Js.undefined > Js.t) in @@ -830,20 +845,25 @@ if Js.Array.isArray x then let array = (Obj.magic x : Js.Json.t array) in let len = Js.Array.length array in - if len > 0 then + if Stdlib.( > ) len 0 then let tag = Js.Array.unsafe_get array 0 in if Js.typeof tag = "string" then let tag = (Obj.magic tag : string) in - if tag = "A" then ( - if len <> 2 then + if Stdlib.( = ) tag "A" then ( + if Stdlib.( <> ) len 2 then Ppx_deriving_json_runtime.of_json_error "expected a JSON array of length 2"; let fs = Js.Array.unsafe_get array 1 in if not - (Js.typeof fs = "object" - && (not (Js.Array.isArray fs)) - && not ((Obj.magic fs : 'a Js.null) == Js.null)) + (Stdlib.( && ) + (Js.typeof fs = "object") + (Stdlib.( && ) + (not (Js.Array.isArray fs)) + (not + (Stdlib.( == ) + (Obj.magic fs : 'a Js.null) + Js.null)))) then Ppx_deriving_json_runtime.of_json_error "expected a JSON object";