49
49
`config.uncurried` to the BundleConfig.
50
50
* v4: Added `config.open_modules` to the BundleConfig to enable implicitly opened
51
51
* modules in the playground.
52
+ * v5: Removed .ml support.
53
+ * v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig.
52
54
* *)
53
- let api_version = " 5 "
55
+ let api_version = " 6 "
54
56
55
57
module Js = Js_of_ocaml. Js
56
58
@@ -73,6 +75,8 @@ module BundleConfig = struct
73
75
mutable filename : string option ;
74
76
mutable warn_flags : string ;
75
77
mutable open_modules : string list ;
78
+ mutable experimental_features : string list ;
79
+ mutable jsx_preserve_mode : bool ;
76
80
}
77
81
78
82
let make () =
@@ -81,6 +85,8 @@ module BundleConfig = struct
81
85
filename = None ;
82
86
warn_flags = Bsc_warnings. defaults_w;
83
87
open_modules = [] ;
88
+ experimental_features = [] ;
89
+ jsx_preserve_mode = false ;
84
90
}
85
91
86
92
let default_filename (lang : Lang.t ) = " playground." ^ Lang. to_string lang
@@ -467,7 +473,15 @@ module Compile = struct
467
473
Js. array (! acc |> Array. of_list)
468
474
469
475
let implementation ~(config : BundleConfig.t ) ~lang str =
470
- let {BundleConfig. module_system; warn_flags; open_modules} = config in
476
+ let {
477
+ BundleConfig. module_system;
478
+ warn_flags;
479
+ open_modules;
480
+ experimental_features;
481
+ jsx_preserve_mode;
482
+ } =
483
+ config
484
+ in
471
485
try
472
486
reset_compiler () ;
473
487
Warnings. parse_options false warn_flags;
@@ -485,6 +499,9 @@ module Compile = struct
485
499
(* let finalenv = ref Env.empty in *)
486
500
let types_signature = ref [] in
487
501
Js_config. jsx_version := Some Js_config. Jsx_v4 ;
502
+ Js_config. jsx_preserve := jsx_preserve_mode;
503
+ experimental_features
504
+ |> List. iter Experimental_features. enable_from_string;
488
505
(* default *)
489
506
let ast = impl str in
490
507
let ast = Ppx_entry. rewrite_implementation ast in
@@ -606,6 +623,14 @@ module Export = struct
606
623
config.open_modules < - value;
607
624
true
608
625
in
626
+ let set_experimental_features value =
627
+ config.experimental_features < - value;
628
+ true
629
+ in
630
+ let set_jsx_preserve_mode value =
631
+ config.jsx_preserve_mode < - value;
632
+ true
633
+ in
609
634
let convert_syntax ~(from_lang : string ) ~(to_lang : string ) (src : string )
610
635
=
611
636
let open Lang in
@@ -653,6 +678,17 @@ module Export = struct
653
678
(set_open_modules
654
679
(value |> Js. to_array |> Array. map Js. to_string
655
680
|> Array. to_list))) );
681
+ ( " setExperimentalFeatures" ,
682
+ inject
683
+ @@ Js. wrap_meth_callback (fun _ value ->
684
+ Js. bool
685
+ (set_experimental_features
686
+ (value |> Js. to_array |> Array. map Js. to_string
687
+ |> Array. to_list))) );
688
+ ( " setJsxPreserveMode" ,
689
+ inject
690
+ @@ Js. wrap_meth_callback (fun _ value ->
691
+ Js. bool (set_jsx_preserve_mode (Js. to_bool value))) );
656
692
( " getConfig" ,
657
693
inject
658
694
@@ Js. wrap_meth_callback (fun _ ->
@@ -665,6 +701,12 @@ module Export = struct
665
701
|> BundleConfig. string_of_module_system
666
702
|> Js. string ) );
667
703
(" warn_flags" , inject @@ Js. string config.warn_flags);
704
+ ( " jsx_preserve_mode" ,
705
+ inject @@ (config.jsx_preserve_mode |> Js. bool ) );
706
+ ( " experimental_features" ,
707
+ inject
708
+ @@ (config.experimental_features |> Array. of_list
709
+ |> Js. array ) );
668
710
( " open_modules" ,
669
711
inject
670
712
@@ (config.open_modules |> Array. of_list |> Js. array )
0 commit comments