@@ -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 ,
@@ -842,7 +874,7 @@ module Settings = {
842
874
~config : Api .Config .t ,
843
875
~keyMapState : (CodeMirror .KeyMap .t , (CodeMirror .KeyMap .t => CodeMirror .KeyMap .t ) => unit ),
844
876
) => {
845
- let {Api .Config .warn_flags : warn_flags } = config
877
+ let {Api .Config .warnFlags : warnFlags } = config
846
878
let (keyMap , setKeyMap ) = keyMapState
847
879
848
880
let availableTargetLangs = Api .Version .availableLanguages (readyState .selected .apiVersion )
@@ -857,22 +889,41 @@ module Settings = {
857
889
}
858
890
let config = {
859
891
... config ,
860
- warn_flags : flags -> normalizeEmptyFlags -> WarningFlagDescription .Parser .tokensToString ,
892
+ warnFlags : flags -> normalizeEmptyFlags -> WarningFlagDescription .Parser .tokensToString ,
861
893
}
862
894
setConfig (config )
863
895
}
864
896
865
- let onModuleSystemUpdate = module_system => {
866
- let config = {... config , module_system }
897
+ let onModuleSystemUpdate = moduleSystem => {
898
+ let config = {... config , moduleSystem }
899
+ setConfig (config )
900
+ }
901
+
902
+ let onJsxPreserveModeUpdate = compilation => {
903
+ let jsxPreserveMode = JsxCompilation .toBool (compilation )
904
+ let config = {... config , jsxPreserveMode }
905
+ setConfig (config )
906
+ }
907
+
908
+ let onExperimentalFeaturesUpdate = feature => {
909
+ let features = config .experimentalFeatures -> Option .getOr ([])
910
+
911
+ let experimentalFeatures = if features -> Array .includes (feature ) {
912
+ features -> Array .filter (x => x !== feature )
913
+ } else {
914
+ [... features , feature ]
915
+ }
916
+
917
+ let config = {... config , experimentalFeatures }
867
918
setConfig (config )
868
919
}
869
920
870
- let warnFlagTokens = WarningFlagDescription .Parser .parse (warn_flags )-> Result .getOr ([])
921
+ let warnFlagTokens = WarningFlagDescription .Parser .parse (warnFlags )-> Result .getOr ([])
871
922
872
923
let onWarningFlagsResetClick = _evt => {
873
924
setConfig ({
874
925
... config ,
875
- warn_flags : "+a-4-9-20-40-41-42-50-61-102-109" ,
926
+ warnFlags : "+a-4-9-20-40-41-42-50-61-102-109" ,
876
927
})
877
928
}
878
929
@@ -996,10 +1047,42 @@ module Settings = {
996
1047
<ToggleSelection
997
1048
values = ["commonjs" , "esmodule" ]
998
1049
toLabel = {value => value }
999
- selected = config .module_system
1050
+ selected = config .moduleSystem
1000
1051
onChange = onModuleSystemUpdate
1001
1052
/>
1002
1053
</div >
1054
+ {readyState .selected .apiVersion -> RescriptCompilerApi .Version .isMinimumVersion (V6 )
1055
+ ? <>
1056
+ <div className = "mt-6" >
1057
+ <div className = titleClass > {React .string ("JSX" )} </div >
1058
+ <ToggleSelection
1059
+ values = [JsxCompilation .Plain , PreserveJsx ]
1060
+ toLabel = JsxCompilation .getLabel
1061
+ selected = {config .jsxPreserveMode -> Option .getOr (false )-> JsxCompilation .fromBool }
1062
+ onChange = onJsxPreserveModeUpdate
1063
+ />
1064
+ </div >
1065
+ <div className = "mt-6" >
1066
+ <div className = titleClass > {React .string ("Experimental Features" )} </div >
1067
+ {ExperimentalFeatures .list
1068
+ -> Array .map (feature => {
1069
+ let key = (feature :> string )
1070
+
1071
+ <SelectionOption
1072
+ key
1073
+ disabled = false
1074
+ label = {feature -> ExperimentalFeatures .getLabel }
1075
+ isActive = {config .experimentalFeatures
1076
+ -> Option .getOr ([])
1077
+ -> Array .includes (key )}
1078
+ onClick = {_evt => onExperimentalFeaturesUpdate (key )}
1079
+ />
1080
+ })
1081
+ -> React .array }
1082
+ </div >
1083
+ </>
1084
+ : React .null }
1085
+
1003
1086
<div className = "mt-6" >
1004
1087
<div className = titleClass > {React .string ("Loaded Libraries" )} </div >
1005
1088
<ul >
@@ -1440,7 +1523,7 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1440
1523
| [v ] => Some (v ) // only single version available. maybe local dev.
1441
1524
| versions => {
1442
1525
let lastStableVersion = versions -> Array .find (version => version .preRelease -> Option .isNone )
1443
- switch Dict .get (router .query , "version" ) {
1526
+ switch Dict .get (router .query , ( CompilerManagerHook . Version :> string ) ) {
1444
1527
| Some (version ) => version -> Semver .parse
1445
1528
| None =>
1446
1529
switch Url .getVersionFromStorage (Playground ) {
@@ -1451,14 +1534,20 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1451
1534
}
1452
1535
}
1453
1536
1454
- let initialLang = switch Dict .get (router .query , "ext" ) {
1537
+ let initialLang = switch Dict .get (router .query , ( CompilerManagerHook . Ext :> string ) ) {
1455
1538
| Some ("re" ) => Api .Lang .Reason
1456
1539
| _ => Api .Lang .Res
1457
1540
}
1458
1541
1459
- let initialModuleSystem = Dict .get (router .query , "module" )
1542
+ let initialModuleSystem = Dict .get (router .query , (Module :> string ))
1543
+ let initialJsxPreserveMode = Dict .get (router .query , (JsxPreserve :> string ))-> Option .isSome
1544
+
1545
+ let initialExperimentalFeatures =
1546
+ Dict .get (router .query , (Experiments :> string ))-> Option .mapOr ([], str =>
1547
+ str -> String .split ("," )-> Array .map (String .trim )
1548
+ )
1460
1549
1461
- let initialContent = switch (Dict .get (router .query , "code" ), initialLang ) {
1550
+ let initialContent = switch (Dict .get (router .query , ( Code :> string ) ), initialLang ) {
1462
1551
| (Some (compressedCode ), _ ) => LzString .decompressToEncodedURIComponent (compressedCode )
1463
1552
| (None , Reason ) => initialReContent
1464
1553
| (None , Res ) =>
@@ -1477,6 +1566,8 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
1477
1566
~bundleBaseUrl ,
1478
1567
~initialVersion ?,
1479
1568
~initialModuleSystem ?,
1569
+ ~initialJsxPreserveMode ,
1570
+ ~initialExperimentalFeatures ,
1480
1571
~initialLang ,
1481
1572
~onAction ,
1482
1573
~versions ,
0 commit comments