@@ -68,12 +68,25 @@ let prim_stmt = "js_pure_stmt"
6868let prim_debugger = " js_debugger"
6969
7070(* TODO should be renamed in to {!Js.fn} *)
71- let curry_type_id = Longident. Ldot (Lident " Pervasives" , " uncurry" )
71+ (* TODO should be moved into {!Js.t} Later *)
72+ let pervasives_js_obj = Longident. Ldot (Lident " Pervasives" , " js_obj" )
73+ let pervasives_uncurry = Longident. Ldot (Lident " Pervasives" , " uncurry" )
74+ let js_obj = Longident. Ldot (Lident " Js" , " t" )
75+ let js_fn = Longident. Ldot (Lident " Js" , " fn" )
76+ let js_obj_type_id () =
77+ if Js_config. get_env () = Browser then
78+ pervasives_js_obj
79+ else js_obj
80+
81+ let curry_type_id () =
82+ if Js_config. get_env () = Browser then
83+ pervasives_uncurry
84+ else
85+ js_fn
86+
7287let ignore_id = Longident. Ldot (Lident " Pervasives" , " ignore" )
73- let js_unsafe_downgrade_id = Longident. Ldot (Ldot (Lident " Js" , " Unsafe" ), " !" )
7488
75- (* TODO should be moved into {!Js.t} Later *)
76- let js_obj_type_id = Longident. Ldot (Lident " Pervasives" , " js_obj" )
89+
7790
7891(* note we first declare its type is [unit],
7992 then [ignore] it, [ignore] is necessary since
@@ -167,7 +180,7 @@ let handle_record_as_js_object
167180
168181 let result_type =
169182 {Parsetree. ptyp_desc =
170- Ptyp_constr ({txt = js_obj_type_id ; loc},
183+ Ptyp_constr ({txt = js_obj_type_id () ; loc},
171184 [{ Parsetree. ptyp_desc =
172185 Ptyp_object (List. map2 (fun x y -> x ,[] , y) labels tyvars, Closed );
173186 ptyp_attributes = [] ;
@@ -206,7 +219,7 @@ let gen_fn_run loc arity args : Parsetree.expression_desc =
206219 in
207220 let uncurry_fn =
208221 {ptyp_desc =
209- Ptyp_constr ({txt = curry_type_id; loc},
222+ Ptyp_constr ({txt = curry_type_id () ; loc},
210223 [{ptyp_desc = tuple_type_desc ;
211224 ptyp_attributes;
212225 ptyp_loc = loc }]);
@@ -243,7 +256,7 @@ let gen_fn_mk loc arity args : Parsetree.expression_desc =
243256 in
244257 let uncurry_fn =
245258 {ptyp_desc =
246- Ptyp_constr ({txt = curry_type_id; loc},
259+ Ptyp_constr ({txt = curry_type_id () ; loc},
247260 [{ptyp_desc = tuple_type_desc ;
248261 ptyp_attributes;
249262 ptyp_loc = loc }]);
@@ -322,7 +335,7 @@ let uncurry_fn_type loc ty ptyp_attributes
322335 ptyp_attributes }
323336 in
324337 { ty with ptyp_desc =
325- Ptyp_constr ({txt = curry_type_id ; loc},
338+ Ptyp_constr ({txt = curry_type_id () ; loc},
326339 [ fn_type]);
327340 ptyp_attributes = []
328341 }
@@ -383,7 +396,7 @@ let handle_typ
383396 {ty with ptyp_desc = Ptyp_object (methods, closed_flag)}
384397 | Some _ , ptyp_attributes ->
385398 {ptyp_desc =
386- Ptyp_constr ({ txt = js_obj_type_id ; loc},
399+ Ptyp_constr ({ txt = js_obj_type_id () ; loc},
387400 [{ ty with ptyp_desc = Ptyp_object (methods, closed_flag);
388401 ptyp_attributes }]);
389402 ptyp_attributes = [] ;
@@ -482,7 +495,7 @@ let handle_obj_property loc obj name e
482495 ~pval_type: ({ptyp_desc =
483496 Ptyp_arrow (" " ,
484497 {ptyp_desc =
485- Ptyp_constr ({txt = js_obj_type_id ; loc},
498+ Ptyp_constr ({txt = js_obj_type_id () ; loc},
486499 [{ptyp_desc = Ptyp_var " a" ;
487500 ptyp_loc = loc;
488501 ptyp_attributes = [] }]);
@@ -545,7 +558,7 @@ let handle_obj_method loc (obj : Parsetree.expression)
545558 ~pval_type: ({ptyp_desc =
546559 Ptyp_arrow (" " ,
547560 {ptyp_desc =
548- Ptyp_constr ({txt = js_obj_type_id ; loc},
561+ Ptyp_constr ({txt = js_obj_type_id () ; loc},
549562 [{ptyp_desc = Ptyp_var " a" ;
550563 ptyp_loc = loc;
551564 ptyp_attributes = [] }]);
0 commit comments