Skip to content

Commit f279079

Browse files
committed
Merge pull request #394 from bloomberg/make_playground_work_again
2 parents cb77b1c + 360ed60 commit f279079

File tree

4 files changed

+71
-27
lines changed

4 files changed

+71
-27
lines changed

jscomp/ppx_entry.ml

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,15 @@ let predef_val_unit =
6666
let prim = "js_pure_expr"
6767
let prim_stmt = "js_pure_stmt"
6868
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")
7072
let ignore_id = Longident.Ldot (Lident "Pervasives", "ignore")
7173
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+
7278
(* note we first declare its type is [unit],
7379
then [ignore] it, [ignore] is necessary since
7480
the js value maybe not be of type [unit] and
@@ -161,7 +167,7 @@ let handle_record_as_js_object
161167

162168
let result_type =
163169
{Parsetree.ptyp_desc =
164-
Ptyp_constr ({txt = Ldot(Lident "Js", "t"); loc},
170+
Ptyp_constr ({txt = js_obj_type_id ; loc},
165171
[{ Parsetree.ptyp_desc =
166172
Ptyp_object (List.map2 (fun x y -> x ,[], y) labels tyvars, Closed);
167173
ptyp_attributes = [];
@@ -358,16 +364,31 @@ let handle_typ
358364
uncurry_fn_type loc ty ptyp_attributes args body
359365
else {ty with ptyp_desc = Ptyp_arrow("", args, body)}
360366
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+
} ->
362372
let methods = List.map (fun (label, ptyp_attrs, core_type ) ->
363373
match find_uncurry_attrs_and_remove ptyp_attrs with
364374
| None, _ -> label, ptyp_attrs , self.typ self core_type
365375
| Some v, ptyp_attrs ->
366376
label , ptyp_attrs, self.typ self
367377
{ core_type with ptyp_attributes = v :: core_type.ptyp_attributes}
368378
) 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
371392
| _ -> super.typ self ty
372393

373394
let handle_debugger loc payload =
@@ -455,16 +476,29 @@ let handle_obj_property loc obj name e
455476
(mapper : Ast_mapper.mapper) : Parsetree.expression =
456477
(* ./dumpast -e ' (Js.Unsafe.(!) obj) # property ' *)
457478
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
458499
{ e with pexp_desc =
459500
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 ;
468502
pexp_loc = loc;
469503
pexp_attributes = []},
470504
name);
@@ -506,20 +540,30 @@ let handle_obj_method loc (obj : Parsetree.expression)
506540
let len = List.length args in
507541
let obj = mapper.expr mapper obj in
508542
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
510562
{e with pexp_desc = gen_fn_run loc len
511563
(("",
512564
{pexp_desc =
513565
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 ;
523567
pexp_loc = loc ;
524568
pexp_attributes = []},
525569
name);

jscomp/runtime/js.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424

2525

2626

27-
type +'a t (** Js object type *)
28-
type +'a fn (** Js uncurried function *)
27+
type +'a t = 'a Pervasives.js_obj(** Js object type *)
28+
type +'a fn = 'a Pervasives.uncurry (** Js uncurried function *)
2929

3030
module Unsafe = struct
3131
external (!) : 'a t -> 'a = "js_unsafe_downgrade"

lib/js/test/demo.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
'use strict';
33

44
var Runtime = require("@runtime");
5-
var BUI = require("@blp/ui");
65
var UI = require("@ui");
76
var Curry = require("../curry");
7+
var BUI = require("@blp/ui");
88

99
var data = /* array */[
1010
/* record */[

lib/js/test/test_react.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// GENERATED CODE BY BUCKLESCRIPT VERSION 0.4.2 , PLEASE EDIT WITH CARE
22
'use strict';
33

4-
var ReactDom = require("react-dom");
54
var React = require("react");
5+
var ReactDom = require("react-dom");
66

77
console.log("hey");
88

0 commit comments

Comments
 (0)