@@ -13,6 +13,38 @@ module Api = RescriptCompilerApi
13
13
14
14
type layout = Column | Row
15
15
type tab = JavaScript | Output | Problems | Settings
16
+
17
+ module JsxCompilation = {
18
+ type t =
19
+ | Plain
20
+ | PreserveJsx
21
+
22
+ let getLabel = (mode : t ): string =>
23
+ switch mode {
24
+ | Plain => "Plain JS functions"
25
+ | PreserveJsx => "Preserve JSX"
26
+ }
27
+
28
+ let toBool = (mode : t ): bool =>
29
+ switch mode {
30
+ | Plain => false
31
+ | PreserveJsx => true
32
+ }
33
+
34
+ let fromBool = (bool ): t => bool ? PreserveJsx : Plain
35
+ }
36
+
37
+ module ExperimentalFeatures = {
38
+ type t = LetUnwrap
39
+
40
+ let getLabel = (feature : t ): string =>
41
+ switch feature {
42
+ | LetUnwrap => "let?"
43
+ }
44
+
45
+ let list = [LetUnwrap ]
46
+ }
47
+
16
48
let breakingPoint = 1024
17
49
18
50
module DropdownSelect = {
@@ -31,23 +63,23 @@ module DropdownSelect = {
31
63
}
32
64
}
33
65
34
- module ToggleSelection = {
35
- module SelectionOption = {
36
- @react.component
37
- let make = (~label , ~isActive , ~disabled , ~onClick ) => {
38
- <button
39
- className = {"mr-1 px-2 py-1 rounded inline-block " ++ if isActive {
40
- "bg-fire text-white font-bold"
41
- } else {
42
- "bg-gray-80 opacity-50 hover:opacity-80"
43
- }}
44
- onClick
45
- disabled >
46
- {React .string (label )}
47
- </button >
48
- }
66
+ module SelectionOption = {
67
+ @react.component
68
+ let make = (~label , ~isActive , ~disabled , ~onClick ) => {
69
+ <button
70
+ className = {"mr-1 px-2 py-1 rounded inline-block " ++ if isActive {
71
+ "bg-fire text-white font-bold"
72
+ } else {
73
+ "bg-gray-80 opacity-50 hover:opacity-80"
74
+ }}
75
+ onClick
76
+ disabled >
77
+ {React .string (label )}
78
+ </button >
49
79
}
80
+ }
50
81
82
+ module ToggleSelection = {
51
83
@react.component
52
84
let make = (
53
85
~onChange : 'a => unit ,
@@ -867,6 +899,25 @@ module Settings = {
867
899
setConfig (config )
868
900
}
869
901
902
+ let onJsxPreserveModeUpdate = compilation => {
903
+ let jsx_preserve_mode = JsxCompilation .toBool (compilation )
904
+ let config = {... config , jsx_preserve_mode }
905
+ setConfig (config )
906
+ }
907
+
908
+ let onExperimentalFeaturesUpdate = feature => {
909
+ let features = config .experimental_features -> Option .getOr ([])
910
+
911
+ let experimental_features = if features -> Array .includes (feature ) {
912
+ features -> Array .filter (x => x !== feature )
913
+ } else {
914
+ [... features , feature ]
915
+ }
916
+
917
+ let config = {... config , experimental_features }
918
+ setConfig (config )
919
+ }
920
+
870
921
let warnFlagTokens = WarningFlagDescription .Parser .parse (warn_flags )-> Result .getOr ([])
871
922
872
923
let onWarningFlagsResetClick = _evt => {
@@ -1000,6 +1051,40 @@ module Settings = {
1000
1051
onChange = onModuleSystemUpdate
1001
1052
/>
1002
1053
</div >
1054
+ {switch readyState .selected .apiVersion {
1055
+ | V1 | V2 | V3 | V4 | V5 | UnknownVersion (_ ) => React .null
1056
+ | V6 =>
1057
+ <>
1058
+ <div className = "mt-6" >
1059
+ <div className = titleClass > {React .string ("JSX" )} </div >
1060
+ <ToggleSelection
1061
+ values = [JsxCompilation .Plain , PreserveJsx ]
1062
+ toLabel = JsxCompilation .getLabel
1063
+ selected = {config .jsx_preserve_mode -> Option .getOr (false )-> JsxCompilation .fromBool }
1064
+ onChange = onJsxPreserveModeUpdate
1065
+ />
1066
+ </div >
1067
+ <div className = "mt-6" >
1068
+ <div className = titleClass > {React .string ("Experimental Features" )} </div >
1069
+ {ExperimentalFeatures .list
1070
+ -> Array .map (feature => {
1071
+ let key = (feature :> string )
1072
+
1073
+ <SelectionOption
1074
+ key
1075
+ disabled = false
1076
+ label = {feature -> ExperimentalFeatures .getLabel }
1077
+ isActive = {config .experimental_features
1078
+ -> Option .getOr ([])
1079
+ -> Array .includes (key )}
1080
+ onClick = {_evt => onExperimentalFeaturesUpdate (key )}
1081
+ />
1082
+ })
1083
+ -> React .array }
1084
+ </div >
1085
+ </>
1086
+ }}
1087
+
1003
1088
<div className = "mt-6" >
1004
1089
<div className = titleClass > {React .string ("Loaded Libraries" )} </div >
1005
1090
<ul >
@@ -1440,7 +1525,7 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1440
1525
| [v ] => Some (v ) // only single version available. maybe local dev.
1441
1526
| versions => {
1442
1527
let lastStableVersion = versions -> Array .find (version => version .preRelease -> Option .isNone )
1443
- switch Dict .get (router .query , "version" ) {
1528
+ switch Dict .get (router .query , ( CompilerManagerHook . Version :> string ) ) {
1444
1529
| Some (version ) => version -> Semver .parse
1445
1530
| None =>
1446
1531
switch Url .getVersionFromStorage (Playground ) {
@@ -1451,14 +1536,20 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1451
1536
}
1452
1537
}
1453
1538
1454
- let initialLang = switch Dict .get (router .query , "ext" ) {
1539
+ let initialLang = switch Dict .get (router .query , ( CompilerManagerHook . Ext :> string ) ) {
1455
1540
| Some ("re" ) => Api .Lang .Reason
1456
1541
| _ => Api .Lang .Res
1457
1542
}
1458
1543
1459
- let initialModuleSystem = Dict .get (router .query , "module" )
1544
+ let initialModuleSystem = Dict .get (router .query , (Module :> string ))
1545
+ let initialJsxPreserveMode = Dict .get (router .query , (JsxPreserve :> string ))-> Option .isSome
1546
+
1547
+ let initialExperimentalFeatures =
1548
+ Dict .get (router .query , (Experiments :> string ))-> Option .mapOr ([], str =>
1549
+ str -> String .split ("," )-> Array .map (String .trim )
1550
+ )
1460
1551
1461
- let initialContent = switch (Dict .get (router .query , "code" ), initialLang ) {
1552
+ let initialContent = switch (Dict .get (router .query , ( Code :> string ) ), initialLang ) {
1462
1553
| (Some (compressedCode ), _ ) => LzString .decompressToEncodedURIComponent (compressedCode )
1463
1554
| (None , Reason ) => initialReContent
1464
1555
| (None , Res ) =>
@@ -1477,6 +1568,8 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1477
1568
~bundleBaseUrl ,
1478
1569
~initialVersion ?,
1479
1570
~initialModuleSystem ?,
1571
+ ~initialJsxPreserveMode ,
1572
+ ~initialExperimentalFeatures ,
1480
1573
~initialLang ,
1481
1574
~onAction ,
1482
1575
~versions ,
0 commit comments