4949 `config.uncurried` to the BundleConfig.
5050 * v4: Added `config.open_modules` to the BundleConfig to enable implicitly opened
5151 * modules in the playground.
52+ * v5: Removed .ml support.
53+ * v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig.
5254 * *)
53- let api_version = " 5 "
55+ let api_version = " 6 "
5456
5557module Js = Js_of_ocaml. Js
5658
@@ -73,6 +75,8 @@ module BundleConfig = struct
7375 mutable filename : string option ;
7476 mutable warn_flags : string ;
7577 mutable open_modules : string list ;
78+ mutable experimental_features : string list ;
79+ mutable jsx_preserve_mode : bool ;
7680 }
7781
7882 let make () =
@@ -81,6 +85,8 @@ module BundleConfig = struct
8185 filename = None ;
8286 warn_flags = Bsc_warnings. defaults_w;
8387 open_modules = [] ;
88+ experimental_features = [] ;
89+ jsx_preserve_mode = false ;
8490 }
8591
8692 let default_filename (lang : Lang.t ) = " playground." ^ Lang. to_string lang
@@ -372,6 +378,7 @@ module Compile = struct
372378 (* Responsible for resetting all compiler state as if it were a new instance *)
373379 let reset_compiler () =
374380 warning_infos := [||];
381+ Experimental_features. reset () ;
375382 flush_warning_buffer () |> ignore;
376383 Warnings. reset_fatal () ;
377384 Env. reset_cache_toplevel ()
@@ -467,7 +474,15 @@ module Compile = struct
467474 Js. array (! acc |> Array. of_list)
468475
469476 let implementation ~(config : BundleConfig.t ) ~lang str =
470- let {BundleConfig. module_system; warn_flags; open_modules} = config in
477+ let {
478+ BundleConfig. module_system;
479+ warn_flags;
480+ open_modules;
481+ experimental_features;
482+ jsx_preserve_mode;
483+ } =
484+ config
485+ in
471486 try
472487 reset_compiler () ;
473488 Warnings. parse_options false warn_flags;
@@ -485,6 +500,9 @@ module Compile = struct
485500 (* let finalenv = ref Env.empty in *)
486501 let types_signature = ref [] in
487502 Js_config. jsx_version := Some Js_config. Jsx_v4 ;
503+ Js_config. jsx_preserve := jsx_preserve_mode;
504+ experimental_features
505+ |> List. iter Experimental_features. enable_from_string;
488506 (* default *)
489507 let ast = impl str in
490508 let ast = Ppx_entry. rewrite_implementation ast in
@@ -606,6 +624,14 @@ module Export = struct
606624 config.open_modules < - value;
607625 true
608626 in
627+ let set_experimental_features value =
628+ config.experimental_features < - value;
629+ true
630+ in
631+ let set_jsx_preserve_mode value =
632+ config.jsx_preserve_mode < - value;
633+ true
634+ in
609635 let convert_syntax ~(from_lang : string ) ~(to_lang : string ) (src : string )
610636 =
611637 let open Lang in
@@ -653,6 +679,17 @@ module Export = struct
653679 (set_open_modules
654680 (value |> Js. to_array |> Array. map Js. to_string
655681 |> Array. to_list))) );
682+ ( " setExperimentalFeatures" ,
683+ inject
684+ @@ Js. wrap_meth_callback (fun _ value ->
685+ Js. bool
686+ (set_experimental_features
687+ (value |> Js. to_array |> Array. map Js. to_string
688+ |> Array. to_list))) );
689+ ( " setJsxPreserveMode" ,
690+ inject
691+ @@ Js. wrap_meth_callback (fun _ value ->
692+ Js. bool (set_jsx_preserve_mode (Js. to_bool value))) );
656693 ( " getConfig" ,
657694 inject
658695 @@ Js. wrap_meth_callback (fun _ ->
@@ -665,6 +702,12 @@ module Export = struct
665702 |> BundleConfig. string_of_module_system
666703 |> Js. string ) );
667704 (" warn_flags" , inject @@ Js. string config.warn_flags);
705+ ( " jsx_preserve_mode" ,
706+ inject @@ (config.jsx_preserve_mode |> Js. bool ) );
707+ ( " experimental_features" ,
708+ inject
709+ @@ (config.experimental_features |> Array. of_list
710+ |> Js. array ) );
668711 ( " open_modules" ,
669712 inject
670713 @@ (config.open_modules |> Array. of_list |> Js. array )
0 commit comments