@@ -66,9 +66,15 @@ let predef_val_unit =
66
66
let prim = " js_pure_expr"
67
67
let prim_stmt = " js_pure_stmt"
68
68
let prim_debugger = " js_debugger"
69
- let curry_type_id = Longident. Ldot (Lident " Js" , " fn" )
69
+
70
+ (* TODO should be renamed in to {!Js.fn} *)
71
+ let curry_type_id = Longident. Ldot (Lident " Pervasives" , " uncurry" )
70
72
let ignore_id = Longident. Ldot (Lident " Pervasives" , " ignore" )
71
73
let js_unsafe_downgrade_id = Longident. Ldot (Ldot (Lident " Js" , " Unsafe" ), " !" )
74
+
75
+ (* TODO should be moved into {!Js.t} Later *)
76
+ let js_obj_type_id = Longident. Ldot (Lident " Pervasives" , " js_obj" )
77
+
72
78
(* note we first declare its type is [unit],
73
79
then [ignore] it, [ignore] is necessary since
74
80
the js value maybe not be of type [unit] and
@@ -161,7 +167,7 @@ let handle_record_as_js_object
161
167
162
168
let result_type =
163
169
{Parsetree. ptyp_desc =
164
- Ptyp_constr ({txt = Ldot ( Lident " Js " , " t " ) ; loc},
170
+ Ptyp_constr ({txt = js_obj_type_id ; loc},
165
171
[{ Parsetree. ptyp_desc =
166
172
Ptyp_object (List. map2 (fun x y -> x ,[] , y) labels tyvars, Closed );
167
173
ptyp_attributes = [] ;
@@ -358,16 +364,31 @@ let handle_typ
358
364
uncurry_fn_type loc ty ptyp_attributes args body
359
365
else {ty with ptyp_desc = Ptyp_arrow (" " , args, body)}
360
366
end
361
- | {ptyp_desc = Ptyp_object ( methods , closed_flag ) } ->
367
+ | {
368
+ ptyp_desc = Ptyp_object ( methods, closed_flag) ;
369
+ ptyp_attributes ;
370
+ ptyp_loc = loc
371
+ } ->
362
372
let methods = List. map (fun (label , ptyp_attrs , core_type ) ->
363
373
match find_uncurry_attrs_and_remove ptyp_attrs with
364
374
| None , _ -> label, ptyp_attrs , self.typ self core_type
365
375
| Some v , ptyp_attrs ->
366
376
label , ptyp_attrs, self.typ self
367
377
{ core_type with ptyp_attributes = v :: core_type .ptyp_attributes}
368
378
) methods in
369
- {ty with ptyp_desc = Ptyp_object (methods, closed_flag)}
370
-
379
+ begin match Ext_list. exclude_with_fact (function
380
+ | {Location. txt = "bs.obj" ; _} , _ -> true
381
+ | _ -> false ) ptyp_attributes with
382
+ | None , _ ->
383
+ {ty with ptyp_desc = Ptyp_object (methods, closed_flag)}
384
+ | Some _ , ptyp_attributes ->
385
+ {ptyp_desc =
386
+ Ptyp_constr ({ txt = js_obj_type_id ; loc},
387
+ [{ ty with ptyp_desc = Ptyp_object (methods, closed_flag);
388
+ ptyp_attributes }]);
389
+ ptyp_attributes = [] ;
390
+ ptyp_loc = loc }
391
+ end
371
392
| _ -> super.typ self ty
372
393
373
394
let handle_debugger loc payload =
@@ -455,16 +476,29 @@ let handle_obj_property loc obj name e
455
476
(mapper : Ast_mapper.mapper ) : Parsetree.expression =
456
477
(* ./dumpast -e ' (Js.Unsafe.(!) obj) # property ' *)
457
478
let obj = mapper.expr mapper obj in
479
+
480
+ let down = create_local_external loc
481
+ ~pval_prim: " js_unsafe_downgrade"
482
+ ~pval_type: ({ptyp_desc =
483
+ Ptyp_arrow (" " ,
484
+ {ptyp_desc =
485
+ Ptyp_constr ({txt = js_obj_type_id ; loc},
486
+ [{ptyp_desc = Ptyp_var " a" ;
487
+ ptyp_loc = loc;
488
+ ptyp_attributes = [] }]);
489
+ ptyp_attributes = [] ;
490
+ ptyp_loc = loc},
491
+ {ptyp_desc = Ptyp_var " a" ;
492
+ ptyp_loc = loc;
493
+ ptyp_attributes = [] });
494
+ ptyp_loc = loc;
495
+ ptyp_attributes = [] })
496
+ ~pval_attributes: []
497
+ " Tmp"
498
+ " cast" [" " , obj] in
458
499
{ e with pexp_desc =
459
500
Pexp_send
460
- ({pexp_desc =
461
- Pexp_apply
462
- ({pexp_desc =
463
- Pexp_ident {txt = js_unsafe_downgrade_id;
464
- loc};
465
- pexp_loc = loc;
466
- pexp_attributes = [] },
467
- [(" " , obj)]);
501
+ ({pexp_desc = down ;
468
502
pexp_loc = loc;
469
503
pexp_attributes = [] },
470
504
name);
@@ -506,20 +540,30 @@ let handle_obj_method loc (obj : Parsetree.expression)
506
540
let len = List. length args in
507
541
let obj = mapper.expr mapper obj in
508
542
let args = List. map (mapper.expr mapper ) args in
509
-
543
+ let down = create_local_external loc
544
+ ~pval_prim: " js_unsafe_downgrade"
545
+ ~pval_type: ({ptyp_desc =
546
+ Ptyp_arrow (" " ,
547
+ {ptyp_desc =
548
+ Ptyp_constr ({txt = js_obj_type_id ; loc},
549
+ [{ptyp_desc = Ptyp_var " a" ;
550
+ ptyp_loc = loc;
551
+ ptyp_attributes = [] }]);
552
+ ptyp_attributes = [] ;
553
+ ptyp_loc = loc},
554
+ {ptyp_desc = Ptyp_var " a" ;
555
+ ptyp_loc = loc;
556
+ ptyp_attributes = [] });
557
+ ptyp_loc = loc;
558
+ ptyp_attributes = [] })
559
+ ~pval_attributes: []
560
+ " Tmp"
561
+ " cast" [" " , obj] in
510
562
{e with pexp_desc = gen_fn_run loc len
511
563
((" " ,
512
564
{pexp_desc =
513
565
Pexp_send
514
- ({pexp_desc =
515
- Pexp_apply
516
- ({pexp_desc =
517
- Pexp_ident {
518
- txt = js_unsafe_downgrade_id;
519
- loc };
520
- pexp_loc = loc ;
521
- pexp_attributes = [] },
522
- [(" " , obj)]);
566
+ ({pexp_desc = down ;
523
567
pexp_loc = loc ;
524
568
pexp_attributes = [] },
525
569
name);
0 commit comments