@@ -13,6 +13,38 @@ module Api = RescriptCompilerApi
1313
1414type layout = Column | Row
1515type 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+
1648let breakingPoint = 1024
1749
1850module DropdownSelect = {
@@ -31,23 +63,23 @@ module DropdownSelect = {
3163 }
3264}
3365
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 >
4979 }
80+ }
5081
82+ module ToggleSelection = {
5183 @react.component
5284 let make = (
5385 ~onChange : 'a => unit ,
@@ -842,7 +874,7 @@ module Settings = {
842874 ~config : Api .Config .t ,
843875 ~keyMapState : (CodeMirror .KeyMap .t , (CodeMirror .KeyMap .t => CodeMirror .KeyMap .t ) => unit ),
844876 ) => {
845- let {Api .Config .warn_flags : warn_flags } = config
877+ let {Api .Config .warnFlags : warnFlags } = config
846878 let (keyMap , setKeyMap ) = keyMapState
847879
848880 let availableTargetLangs = Api .Version .availableLanguages (readyState .selected .apiVersion )
@@ -857,22 +889,41 @@ module Settings = {
857889 }
858890 let config = {
859891 ... config ,
860- warn_flags : flags -> normalizeEmptyFlags -> WarningFlagDescription .Parser .tokensToString ,
892+ warnFlags : flags -> normalizeEmptyFlags -> WarningFlagDescription .Parser .tokensToString ,
861893 }
862894 setConfig (config )
863895 }
864896
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 }
867918 setConfig (config )
868919 }
869920
870- let warnFlagTokens = WarningFlagDescription .Parser .parse (warn_flags )-> Result .getOr ([])
921+ let warnFlagTokens = WarningFlagDescription .Parser .parse (warnFlags )-> Result .getOr ([])
871922
872923 let onWarningFlagsResetClick = _evt => {
873924 setConfig ({
874925 ... 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" ,
876927 })
877928 }
878929
@@ -996,10 +1047,42 @@ module Settings = {
9961047 <ToggleSelection
9971048 values = ["commonjs" , "esmodule" ]
9981049 toLabel = {value => value }
999- selected = config .module_system
1050+ selected = config .moduleSystem
10001051 onChange = onModuleSystemUpdate
10011052 />
10021053 </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+
10031086 <div className = "mt-6" >
10041087 <div className = titleClass > {React .string ("Loaded Libraries" )} </div >
10051088 <ul >
@@ -1440,7 +1523,7 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14401523 | [v ] => Some (v ) // only single version available. maybe local dev.
14411524 | versions => {
14421525 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 ) ) {
14441527 | Some (version ) => version -> Semver .parse
14451528 | None =>
14461529 switch Url .getVersionFromStorage (Playground ) {
@@ -1451,14 +1534,20 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14511534 }
14521535 }
14531536
1454- let initialLang = switch Dict .get (router .query , "ext" ) {
1537+ let initialLang = switch Dict .get (router .query , ( CompilerManagerHook . Ext :> string ) ) {
14551538 | Some ("re" ) => Api .Lang .Reason
14561539 | _ => Api .Lang .Res
14571540 }
14581541
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+ )
14601549
1461- let initialContent = switch (Dict .get (router .query , "code" ), initialLang ) {
1550+ let initialContent = switch (Dict .get (router .query , ( Code :> string ) ), initialLang ) {
14621551 | (Some (compressedCode ), _ ) => LzString .decompressToEncodedURIComponent (compressedCode )
14631552 | (None , Reason ) => initialReContent
14641553 | (None , Res ) =>
@@ -1477,6 +1566,8 @@ let make = (~bundleBaseUrl: string, ~versions: array<string>) => {
14771566 ~bundleBaseUrl ,
14781567 ~initialVersion ?,
14791568 ~initialModuleSystem ?,
1569+ ~initialJsxPreserveMode ,
1570+ ~initialExperimentalFeatures ,
14801571 ~initialLang ,
14811572 ~onAction ,
14821573 ~versions ,
0 commit comments