Skip to content

Commit 9f94d3a

Browse files
Playground: implicitly opened modules
1 parent ab39e10 commit 9f94d3a

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

jscomp/jsoo/jsoo_playground_main.ml

+17-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@
4848
* v3: Switched to Uncurried mode by default (requires third party packages
4949
to be built with uncurried: true in bsconfig.json). Also added
5050
`config.uncurried` to the BundleConfig.
51+
* v4: Added `config.open_modules` to the BundleConfig to enable implicitly opened
52+
* modules in the playground.
5153
* *)
52-
let apiVersion = "3"
54+
let apiVersion = "4"
5355

5456
module Js = Js_of_ocaml.Js
5557

@@ -75,6 +77,7 @@ module BundleConfig = struct
7577
mutable module_system: Js_packages_info.module_system;
7678
mutable filename: string option;
7779
mutable warn_flags: string;
80+
mutable open_modules: string list;
7881

7982
(* This one can't be mutated since we only provide
8083
third-party packages that were compiled for uncurried
@@ -86,6 +89,7 @@ module BundleConfig = struct
8689
module_system=Js_packages_info.NodeJS;
8790
filename=None;
8891
warn_flags=Bsc_warnings.defaults_w;
92+
open_modules=[];
8993
uncurried=(!Config.uncurried = Uncurried);
9094
}
9195

@@ -462,7 +466,7 @@ module Compile = struct
462466
Js.array (!acc |> Array.of_list)
463467

464468
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
466470
try
467471
reset_compiler ();
468472
Warnings.parse_options false warn_flags;
@@ -472,6 +476,7 @@ module Compile = struct
472476
| Lang.OCaml -> ocaml_parse ~filename
473477
| Res -> rescript_parse ~filename
474478
in
479+
Clflags.open_modules := open_modules;
475480
(* let env = !Toploop.toplevel_env in *)
476481
(* Res_compmisc.init_path (); *)
477482
(* let modulename = module_of_filename ppf sourcefile outputprefix in *)
@@ -613,6 +618,9 @@ module Export = struct
613618
let set_warn_flags value =
614619
config.warn_flags <- value; true
615620
in
621+
let set_open_modules value =
622+
config.open_modules <- value; true
623+
in
616624
let convert_syntax ~(fromLang: string) ~(toLang: string) (src: string) =
617625
let open Lang in
618626
match (fromString fromLang, fromString toLang) with
@@ -658,6 +666,12 @@ module Export = struct
658666
(fun _ value ->
659667
(Js.bool (set_warn_flags (Js.to_string value)))
660668
);
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+
);
661675
"getConfig",
662676
inject @@
663677
Js.wrap_meth_callback
@@ -673,6 +687,7 @@ module Export = struct
673687
"warn_flags",
674688
inject @@ (Js.string config.warn_flags);
675689
"uncurried", inject @@ (Js.bool config.uncurried);
690+
"open_modules", inject @@ (config.open_modules |> Array.of_list |> Js.array);
676691
|]))
677692
);
678693
|])

playground/playground_test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ require("./packages/@rescript/core/cmij.js")
55

66
let compiler = rescript_compiler.make()
77

8+
compiler.setOpenModules(["RescriptCore"])
9+
810
let result = compiler.rescript.compile(`
911
@@jsxConfig({ version: 4, mode: "automatic" })
1012
11-
open RescriptCore
12-
1313
module A = {
1414
@react.component
1515
let make = (~a) => {

0 commit comments

Comments
 (0)