48
48
* v3: Switched to Uncurried mode by default (requires third party packages
49
49
to be built with uncurried: true in bsconfig.json). Also added
50
50
`config.uncurried` to the BundleConfig.
51
+ * v4: Added `config.open_modules` to the BundleConfig to enable implicitly opened
52
+ * modules in the playground.
51
53
* *)
52
- let apiVersion = " 3 "
54
+ let apiVersion = " 4 "
53
55
54
56
module Js = Js_of_ocaml. Js
55
57
@@ -75,6 +77,7 @@ module BundleConfig = struct
75
77
mutable module_system : Js_packages_info .module_system ;
76
78
mutable filename : string option ;
77
79
mutable warn_flags : string ;
80
+ mutable open_modules : string list ;
78
81
79
82
(* This one can't be mutated since we only provide
80
83
third-party packages that were compiled for uncurried
@@ -86,6 +89,7 @@ module BundleConfig = struct
86
89
module_system= Js_packages_info. NodeJS ;
87
90
filename= None ;
88
91
warn_flags= Bsc_warnings. defaults_w;
92
+ open_modules= [] ;
89
93
uncurried= (! Config. uncurried = Uncurried );
90
94
}
91
95
@@ -462,7 +466,7 @@ module Compile = struct
462
466
Js. array (! acc |> Array. of_list)
463
467
464
468
let implementation ~(config : BundleConfig.t ) ~lang str =
465
- let {BundleConfig. module_system; warn_flags} = config in
469
+ let {BundleConfig. module_system; warn_flags; open_modules } = config in
466
470
try
467
471
reset_compiler () ;
468
472
Warnings. parse_options false warn_flags;
@@ -472,6 +476,7 @@ module Compile = struct
472
476
| Lang. OCaml -> ocaml_parse ~filename
473
477
| Res -> rescript_parse ~filename
474
478
in
479
+ Clflags. open_modules := open_modules;
475
480
(* let env = !Toploop.toplevel_env in *)
476
481
(* Res_compmisc.init_path (); *)
477
482
(* let modulename = module_of_filename ppf sourcefile outputprefix in *)
@@ -613,6 +618,9 @@ module Export = struct
613
618
let set_warn_flags value =
614
619
config.warn_flags < - value; true
615
620
in
621
+ let set_open_modules value =
622
+ config.open_modules < - value; true
623
+ in
616
624
let convert_syntax ~(fromLang : string ) ~(toLang : string ) (src : string ) =
617
625
let open Lang in
618
626
match (fromString fromLang, fromString toLang) with
@@ -658,6 +666,12 @@ module Export = struct
658
666
(fun _ value ->
659
667
(Js. bool (set_warn_flags (Js. to_string value)))
660
668
);
669
+ " setOpenModules" ,
670
+ inject @@
671
+ Js. wrap_meth_callback
672
+ (fun _ (value ) ->
673
+ (Js. bool (set_open_modules (value |> Js. to_array |> Array. map Js. to_string |> Array. to_list)))
674
+ );
661
675
" getConfig" ,
662
676
inject @@
663
677
Js. wrap_meth_callback
@@ -673,6 +687,7 @@ module Export = struct
673
687
" warn_flags" ,
674
688
inject @@ (Js. string config.warn_flags);
675
689
" uncurried" , inject @@ (Js. bool config.uncurried);
690
+ " open_modules" , inject @@ (config.open_modules |> Array. of_list |> Js. array );
676
691
|]))
677
692
);
678
693
|])
0 commit comments