diff --git a/compiler/jsoo/dune b/compiler/jsoo/dune index af24cc17d1..62a7d127d6 100644 --- a/compiler/jsoo/dune +++ b/compiler/jsoo/dune @@ -7,4 +7,4 @@ (= %{profile} browser)) (flags (:standard -w +a-4-9-40-42-44-45)) - (libraries core syntax ml js_of_ocaml)) + (libraries core syntax ml gentype js_of_ocaml)) diff --git a/compiler/jsoo/jsoo_playground_main.ml b/compiler/jsoo/jsoo_playground_main.ml index 0a750bdda6..b01378e5e4 100644 --- a/compiler/jsoo/jsoo_playground_main.ml +++ b/compiler/jsoo/jsoo_playground_main.ml @@ -51,7 +51,8 @@ * modules in the playground. * v5: Removed .ml support. * v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig. - * v7: Added debug dump output APIs for developer playground tooling. + * v7: Added debug dump output APIs for developer playground tooling, + * including gentype output. * *) let api_version = "7" @@ -78,6 +79,7 @@ module BundleConfig = struct mutable open_modules: string list; mutable experimental_features: string list; mutable jsx_preserve_mode: bool; + mutable gentype_enabled: bool; } let make () = @@ -88,6 +90,7 @@ module BundleConfig = struct open_modules = []; experimental_features = []; jsx_preserve_mode = false; + gentype_enabled = false; } let default_filename (lang : Lang.t) = "playground." ^ Lang.to_string lang @@ -475,6 +478,72 @@ module Compile = struct List.iter Iter.iter_structure_item structure.str_items; Js.array (!acc |> Array.of_list) + let gentype_output ~module_system ~modulename ~sourcefile structure env = + let cmt_annots = Cmt_format.Implementation structure in + let input_cmt = + { + Cmt_format.cmt_modname = modulename; + cmt_annots; + cmt_value_dependencies = []; + cmt_comments = []; + cmt_args = [||]; + cmt_sourcefile = Some sourcefile; + cmt_builddir = Sys.getcwd (); + cmt_loadpath = !Config.load_path; + cmt_source_digest = None; + cmt_initial_env = env; + cmt_imports = []; + cmt_interface_digest = None; + cmt_use_summaries = false; + cmt_extra_info = {Cmt_utils.deprecated_used = []}; + } + in + let has_gentype_annotations = + GenTypeMain.cmt_check_annotations input_cmt + ~check_annotation:(fun ~loc:_ attributes -> + attributes + |> Annotation.get_attribute_payload + Annotation.tag_is_one_of_the_gentype_annotations + <> None) + in + if has_gentype_annotations then + let module_ = + match module_system with + | Ext_module_system.Commonjs -> GenTypeConfig.CommonJS + | Esmodule -> ESModule + in + let project_root = Sys.getcwd () in + let config = + { + GenTypeConfig.default with + module_; + platform_lib = "rescript"; + project_root; + bsb_project_root = project_root; + } + in + let source_file = sourcefile in + let output_file_relative = + source_file |> Paths.get_output_file_relative ~config + in + let file_name = modulename |> ModuleName.from_string_unsafe in + let resolver = + ModuleResolver.create_lazy_resolver ~config + ~extensions:[".res"; ".shim.ts"] ~exclude_file:(fun fname -> + fname = "React.res" || fname = "ReasonReact.res") + in + let code_text = + input_cmt + |> GenTypeMain.translate_c_m_t ~config ~output_file_relative ~resolver + |> EmitJs.emit_translation_as_string ~config ~file_name + ~output_file_relative ~resolver + ~input_cmt_translate_type_declarations: + GenTypeMain.input_cmt_translate_type_declarations + in + EmitType.file_header ~source_file:(Filename.basename source_file) + ^ "\n" ^ code_text ^ "\n" + else "No @gentype annotations found." + let implementation ?(include_debug_outputs = false) ~(config : BundleConfig.t) ~lang str = let { @@ -483,6 +552,7 @@ module Compile = struct open_modules; experimental_features; jsx_preserve_mode; + gentype_enabled; } = config in @@ -551,6 +621,26 @@ module Compile = struct let lambda = Printer.to_string Printlambda.lambda lam in let lam, _ = Lam_convert.convert export_ident_sets lam in let lam = Lam_print.lambda_to_string lam in + let gentype_attrs = + if gentype_enabled then + let structure, _ = typed_tree in + Js.Unsafe. + [| + ( "gentype", + inject + @@ Js.string + (gentype_output ~module_system ~modulename + ~sourcefile:filename structure env) ); + |] + else [||] + in + (* TODO(sourcemap PR): The developer playground already knows how to + show an optional "source_map" debug tab. Add optional instance + setters named "setSourceMapMode", "setSourceMapSourcesContent", + and "setSourceMapRoot", matching getConfig fields named + "source_map_mode", "source_map_sources_content", and + "source_map_root", plus a compileWithDebug output field named + "source_map". *) let debug_attrs = Js.Unsafe. [| @@ -560,7 +650,7 @@ module Compile = struct ("lam", inject @@ Js.string lam); |] in - Js.Unsafe.obj (Array.append attrs debug_attrs) + Js.Unsafe.obj (Array.concat [attrs; debug_attrs; gentype_attrs]) else Js.Unsafe.obj attrs with e -> ( match e with @@ -661,6 +751,10 @@ module Export = struct config.jsx_preserve_mode <- value; true in + let set_gentype_enabled value = + config.gentype_enabled <- value; + true + in let convert_syntax ~(from_lang : string) ~(to_lang : string) (src : string) = let open Lang in @@ -719,6 +813,10 @@ module Export = struct inject @@ Js.wrap_meth_callback (fun _ value -> Js.bool (set_jsx_preserve_mode (Js.to_bool value))) ); + ( "setGentypeEnabled", + inject + @@ Js.wrap_meth_callback (fun _ value -> + Js.bool (set_gentype_enabled (Js.to_bool value))) ); ( "getConfig", inject @@ Js.wrap_meth_callback (fun _ -> @@ -733,6 +831,8 @@ module Export = struct ("warn_flags", inject @@ Js.string config.warn_flags); ( "jsx_preserve_mode", inject @@ (config.jsx_preserve_mode |> Js.bool) ); + ( "gentype_enabled", + inject @@ (config.gentype_enabled |> Js.bool) ); ( "experimental_features", inject @@ (config.experimental_features |> Array.of_list diff --git a/packages/dev-playground/src/Bindings.res b/packages/dev-playground/src/Bindings.res index 1b7f3f497f..a287f8b814 100644 --- a/packages/dev-playground/src/Bindings.res +++ b/packages/dev-playground/src/Bindings.res @@ -30,6 +30,12 @@ module Instance = { @send external setWarnFlags: (compilerInstance, string) => unit = "setWarnFlags" @send external setFilename: (compilerInstance, string) => unit = "setFilename" @send external setJsxPreserveMode: (compilerInstance, bool) => unit = "setJsxPreserveMode" + @send external setGentypeEnabled: (compilerInstance, bool) => unit = "setGentypeEnabled" + @send external setSourceMapMode: (compilerInstance, string) => unit = "setSourceMapMode" + @send + external setSourceMapSourcesContent: (compilerInstance, bool) => unit = + "setSourceMapSourcesContent" + @send external setSourceMapRoot: (compilerInstance, string) => unit = "setSourceMapRoot" @send external setExperimentalFeatures: (compilerInstance, array) => unit = "setExperimentalFeatures" @@ -51,6 +57,11 @@ module Config = { @get external jsxPreserveMode: compilerConfig => option = "jsx_preserve_mode" @get external experimentalFeatures: compilerConfig => option> = "experimental_features" + @get external gentypeEnabled: compilerConfig => option = "gentype_enabled" + @get external sourceMapMode: compilerConfig => option = "source_map_mode" + @get + external sourceMapSourcesContent: compilerConfig => option = "source_map_sources_content" + @get external sourceMapRoot: compilerConfig => option = "source_map_root" } module Diagnostic = { @@ -70,6 +81,8 @@ module CompileResult = { @get external typedtree: compileResult => option = "typedtree" @get external lambda: compileResult => option = "lambda" @get external lam: compileResult => option = "lam" + @get external gentype: compileResult => option = "gentype" + @get external sourceMap: compileResult => option = "source_map" @get external errors: compileResult => option> = "errors" @get external warnings: compileResult => option> = "warnings" @get external msg: compileResult => option = "msg" diff --git a/packages/dev-playground/src/CompilerApi.res b/packages/dev-playground/src/CompilerApi.res index 7464ee94b0..b44371ec85 100644 --- a/packages/dev-playground/src/CompilerApi.res +++ b/packages/dev-playground/src/CompilerApi.res @@ -50,6 +50,10 @@ type info = { warnFlags: string, jsxPreserveMode: bool, experimentalFeatures: array, + gentypeEnabled: bool, + sourceMapMode: PlaygroundConfig.sourceMapMode, + sourceMapSourcesContent: bool, + sourceMapRoot: string, libraries: array, } @@ -59,6 +63,8 @@ type success = { typedtree: string, lambda: string, lam: string, + gentype: option, + sourceMap: option, warnings: array, time: float, } @@ -78,6 +84,10 @@ type normalizedConfig = { warnFlags: string, jsxPreserveMode: bool, experimentalFeatures: array, + gentypeEnabled: bool, + sourceMapMode: PlaygroundConfig.sourceMapMode, + sourceMapSourcesContent: bool, + sourceMapRoot: string, } let defaultWarnFlags = "+a-4-9-20-40-41-42-50-61-102-109" @@ -90,6 +100,10 @@ let defaultConfig: PlaygroundConfig.t = { warnFlags: defaultWarnFlags, jsxPreserveMode: false, experimentalFeatures: [], + gentypeEnabled: false, + sourceMapMode: Disabled, + sourceMapSourcesContent: true, + sourceMapRoot: "", } let pathFromBase = relativePath => { @@ -207,6 +221,10 @@ let applyConfig = ( ~moduleSystem: PlaygroundConfig.moduleSystem, ~warnFlags, ~jsxPreserveMode, + ~gentypeEnabled, + ~sourceMapMode: PlaygroundConfig.sourceMapMode, + ~sourceMapSourcesContent, + ~sourceMapRoot, ~experimentalFeatures: array, ) => { if hasFunction(instance, "setModuleSystem") { @@ -221,6 +239,18 @@ let applyConfig = ( if hasFunction(instance, "setJsxPreserveMode") { instance->Instance.setJsxPreserveMode(jsxPreserveMode) } + if hasFunction(instance, "setGentypeEnabled") { + instance->Instance.setGentypeEnabled(gentypeEnabled) + } + if hasFunction(instance, "setSourceMapMode") { + instance->Instance.setSourceMapMode(sourceMapMode->PlaygroundConfig.sourceMapModeCompilerValue) + } + if hasFunction(instance, "setSourceMapSourcesContent") { + instance->Instance.setSourceMapSourcesContent(sourceMapSourcesContent) + } + if hasFunction(instance, "setSourceMapRoot") { + instance->Instance.setSourceMapRoot(sourceMapRoot) + } if hasFunction(instance, "setExperimentalFeatures") { instance->Instance.setExperimentalFeatures( experimentalFeatures->Array.map(feature => (feature :> string)), @@ -245,6 +275,16 @@ let experimentalFeaturesFromConfig = configValue => | None => [] } +let sourceMapModeFromConfig = configValue => + switch configValue->Config.sourceMapMode { + | Some(sourceMapMode) => + switch sourceMapMode->PlaygroundConfig.parseSourceMapMode { + | Some(sourceMapMode) => sourceMapMode + | None => defaultConfig.sourceMapMode + } + | None => defaultConfig.sourceMapMode + } + let normalizeConfig = (configValue: option): normalizedConfig => switch configValue { | None => { @@ -252,6 +292,10 @@ let normalizeConfig = (configValue: option): normalizedConfig => warnFlags: defaultConfig.warnFlags, jsxPreserveMode: false, experimentalFeatures: [], + gentypeEnabled: defaultConfig.gentypeEnabled, + sourceMapMode: defaultConfig.sourceMapMode, + sourceMapSourcesContent: defaultConfig.sourceMapSourcesContent, + sourceMapRoot: defaultConfig.sourceMapRoot, } | Some(configValue) => { moduleSystem: configValue->moduleSystemFromConfig, @@ -264,6 +308,19 @@ let normalizeConfig = (configValue: option): normalizedConfig => | None => false }, experimentalFeatures: configValue->experimentalFeaturesFromConfig, + gentypeEnabled: switch configValue->Config.gentypeEnabled { + | Some(gentypeEnabled) => gentypeEnabled + | None => defaultConfig.gentypeEnabled + }, + sourceMapMode: configValue->sourceMapModeFromConfig, + sourceMapSourcesContent: switch configValue->Config.sourceMapSourcesContent { + | Some(sourceMapSourcesContent) => sourceMapSourcesContent + | None => defaultConfig.sourceMapSourcesContent + }, + sourceMapRoot: switch configValue->Config.sourceMapRoot { + | Some(sourceMapRoot) => sourceMapRoot + | None => defaultConfig.sourceMapRoot + }, } } @@ -351,7 +408,10 @@ let normalize = (compileOutput, elapsedMs): compileResult => { | None => "" } - Ok({jsCode, parsetree, typedtree, lambda, lam, warnings, time: elapsedMs}) + let gentype = compileOutput->CompileResult.gentype + let sourceMap = compileOutput->CompileResult.sourceMap + + Ok({jsCode, parsetree, typedtree, lambda, lam, gentype, sourceMap, warnings, time: elapsedMs}) | _ => Error(failureFromCompileOutput(compileOutput, elapsedMs)) } @@ -418,6 +478,10 @@ let ensureCompiler = async version => { ~moduleSystem=Esmodule, ~warnFlags=defaultConfig.warnFlags, ~jsxPreserveMode=false, + ~gentypeEnabled=defaultConfig.gentypeEnabled, + ~sourceMapMode=defaultConfig.sourceMapMode, + ~sourceMapSourcesContent=defaultConfig.sourceMapSourcesContent, + ~sourceMapRoot=defaultConfig.sourceMapRoot, ~experimentalFeatures=[], ) @@ -470,6 +534,10 @@ let init = async version => { warnFlags: config.warnFlags, jsxPreserveMode: config.jsxPreserveMode, experimentalFeatures: config.experimentalFeatures, + gentypeEnabled: config.gentypeEnabled, + sourceMapMode: config.sourceMapMode, + sourceMapSourcesContent: config.sourceMapSourcesContent, + sourceMapRoot: config.sourceMapRoot, libraries, } } @@ -483,6 +551,10 @@ let compile = async (source, config: PlaygroundConfig.t) => { ~moduleSystem=config.moduleSystem, ~warnFlags=config.warnFlags, ~jsxPreserveMode=config.jsxPreserveMode, + ~gentypeEnabled=config.gentypeEnabled, + ~sourceMapMode=config.sourceMapMode, + ~sourceMapSourcesContent=config.sourceMapSourcesContent, + ~sourceMapRoot=config.sourceMapRoot, ~experimentalFeatures=config.experimentalFeatures, ) @@ -507,6 +579,10 @@ let format = async (source, config: PlaygroundConfig.t) => { ~moduleSystem=config.moduleSystem, ~warnFlags=config.warnFlags, ~jsxPreserveMode=config.jsxPreserveMode, + ~gentypeEnabled=config.gentypeEnabled, + ~sourceMapMode=config.sourceMapMode, + ~sourceMapSourcesContent=config.sourceMapSourcesContent, + ~sourceMapRoot=config.sourceMapRoot, ~experimentalFeatures=config.experimentalFeatures, ) diff --git a/packages/dev-playground/src/CompilerApi.resi b/packages/dev-playground/src/CompilerApi.resi index 45c4c7c540..6271924b2c 100644 --- a/packages/dev-playground/src/CompilerApi.resi +++ b/packages/dev-playground/src/CompilerApi.resi @@ -13,6 +13,10 @@ type info = { warnFlags: string, jsxPreserveMode: bool, experimentalFeatures: array, + gentypeEnabled: bool, + sourceMapMode: PlaygroundConfig.sourceMapMode, + sourceMapSourcesContent: bool, + sourceMapRoot: string, libraries: array, } @@ -22,6 +26,8 @@ type success = { typedtree: string, lambda: string, lam: string, + gentype: option, + sourceMap: option, warnings: array, time: float, } diff --git a/packages/dev-playground/src/Main.res b/packages/dev-playground/src/Main.res index 91ffae6b5b..882bf3737c 100644 --- a/packages/dev-playground/src/Main.res +++ b/packages/dev-playground/src/Main.res @@ -6,6 +6,8 @@ type tab = | Lambda | Lam | JavaScript + | GenType + | SourceMap | Settings type compilerStatus = @@ -19,8 +21,23 @@ type sourcePosition = { col: int, } -let tabs: array = [Parsetree, Typedtree, Lambda, Lam, JavaScript, Settings] +let baseTabs: array = [Parsetree, Typedtree, Lambda, Lam, JavaScript] let moduleSystems: array = [Esmodule, Commonjs] +let sourceMapModes: array = [Disabled, Linked, Inline, Hidden] + +let tabIsVisible = (config: PlaygroundConfig.t, tab) => + switch tab { + | GenType => config.gentypeEnabled + | SourceMap => config.sourceMapMode !== Disabled + | Parsetree | Typedtree | Lambda | Lam | JavaScript | Settings => true + } + +let tabsForConfig = (config: PlaygroundConfig.t) => { + let withGentype = config.gentypeEnabled ? Array.concat(baseTabs, [GenType]) : baseTabs + let withSourceMap = + config.sourceMapMode !== Disabled ? Array.concat(withGentype, [SourceMap]) : withGentype + Array.concat(withSourceMap, [Settings]) +} let defaultSource = `type person = { name: string, @@ -43,6 +60,8 @@ let tabLabel = tab => | Lambda => "lambda" | Lam => "lam" | JavaScript => "js" + | GenType => "gentype" + | SourceMap => "source map" | Settings => "settings" } @@ -141,6 +160,12 @@ let toggleFeature = (features: array, feature: experimental ? features->Array.filter(item => item !== feature) : Array.concat(features, [feature]) +let optionalOutput = (output, fallback) => + switch output { + | Some(output) => output + | None => fallback + } + let selectedOutput = (result: option, activeTab: tab) => switch result { | None => "The compiler is loading. Results will appear here after the first compile." @@ -154,6 +179,13 @@ let selectedOutput = (result: option, activeTab: tab) | Lambda => result.lambda | Lam => result.lam | JavaScript => result.jsCode + | GenType => + optionalOutput(result.gentype, "This compiler bundle does not expose gentype output yet.") + | SourceMap => + optionalOutput( + result.sourceMap, + "This compiler bundle does not expose source map output yet.", + ) | Settings => "" } } @@ -211,7 +243,20 @@ module SettingsPanel = { ~scheduleCompile: unit => unit, ~scheduleUrlSync: unit => unit, ) => { - let updateConfig = f => Signal.update(config, f) + let updateConfig = f => { + let nextConfig = f(Signal.peek(config)) + Signal.set(config, nextConfig) + if !tabIsVisible(nextConfig, Signal.peek(activeTab)) { + Signal.set(activeTab, JavaScript) + } + } + let compilerVersionOptions: Signal.t> = Obj.magic( + Computed.make(() => + CompilerApi.selectableCompilerVersions( + Signal.get(config).compilerVersion, + )->Array.map(version => ) + ), + )
@@ -230,11 +275,7 @@ module SettingsPanel = { switchCompiler(nextVersion) }} > - {Node.fragment( - CompilerApi.selectableCompilerVersions( - Signal.get(config).compilerVersion, - )->Array.map(version => ), - )} + {Node.signalFragment(compilerVersionOptions)}
@@ -307,6 +348,71 @@ module SettingsPanel = { />
+
+ Signal.get(config).gentypeEnabled} + onChange={event => { + updateConfig(config => {...config, gentypeEnabled: Event.checked(event)}) + scheduleUrlSync() + compileNow() + }} + /> + +
+
+ + +
+
+ Signal.get(config).sourceMapSourcesContent} + onChange={event => { + updateConfig(config => { + ...config, + sourceMapSourcesContent: Event.checked(event), + }) + scheduleUrlSync() + compileNow() + }} + /> + +
+
+ + Signal.get(config).sourceMapRoot} + spellcheck=false + onInput={event => { + updateConfig(config => {...config, sourceMapRoot: Event.value(event)}) + scheduleUrlSync() + scheduleCompile() + }} + /> +
> = Signal.make(None) let compileResult: Signal.t> = Signal.make(None) let config = Signal.make(CompilerApi.defaultConfig) + let visibleTabNodes: Signal.t> = Obj.magic( + Computed.make(() => + tabsForConfig(Signal.get(config))->Array.map(tab => + Signal.set(activeTab, tab)} /> + ) + ), + ) let activeLine = Signal.make(1) let editorScrollTop = Signal.make(0) let editorScrollLeft = Signal.make(0) @@ -542,10 +655,17 @@ module App = { warnFlags: info.warnFlags, jsxPreserveMode: info.jsxPreserveMode, experimentalFeatures: info.experimentalFeatures, + gentypeEnabled: info.gentypeEnabled, + sourceMapMode: info.sourceMapMode, + sourceMapSourcesContent: info.sourceMapSourcesContent, + sourceMapRoot: info.sourceMapRoot, } } Signal.set(compilerInfo, Some(info)) Signal.set(config, nextConfig) + if !tabIsVisible(nextConfig, Signal.peek(activeTab)) { + Signal.set(activeTab, JavaScript) + } Signal.set(status, Ready) switch firstLoadConfigValue { | Some(_) => () @@ -672,13 +792,7 @@ module App = {
-
- {Node.fragment( - tabs->Array.map(tab => - Signal.set(activeTab, tab)} /> - ), - )} -
+
{Node.signalFragment(visibleTabNodes)}
Signal.get(activeTab) === Settings ? "output-panel hidden-panel" : "output-panel"} diff --git a/packages/dev-playground/src/PlaygroundConfig.res b/packages/dev-playground/src/PlaygroundConfig.res index c12959c368..750c4f0c8c 100644 --- a/packages/dev-playground/src/PlaygroundConfig.res +++ b/packages/dev-playground/src/PlaygroundConfig.res @@ -17,10 +17,37 @@ let parseExperimentalFeature = value => | _ => None } +type sourceMapMode = + | @as("disabled") Disabled + | @as("linked") Linked + | @as("inline") Inline + | @as("hidden") Hidden + +let parseSourceMapMode = value => + switch value { + | "disabled" | "false" | "none" => Some(Disabled) + | "linked" => Some(Linked) + | "inline" => Some(Inline) + | "hidden" => Some(Hidden) + | _ => None + } + +let sourceMapModeCompilerValue = mode => + switch mode { + | Disabled => "false" + | Linked => "linked" + | Inline => "inline" + | Hidden => "hidden" + } + type t = { compilerVersion: string, moduleSystem: moduleSystem, warnFlags: string, jsxPreserveMode: bool, experimentalFeatures: array, + gentypeEnabled: bool, + sourceMapMode: sourceMapMode, + sourceMapSourcesContent: bool, + sourceMapRoot: string, } diff --git a/packages/dev-playground/src/UrlState.res b/packages/dev-playground/src/UrlState.res index 39a9fbeb2e..68e234a16b 100644 --- a/packages/dev-playground/src/UrlState.res +++ b/packages/dev-playground/src/UrlState.res @@ -30,6 +30,30 @@ let applyUrlState = (~encoded, ~config: PlaygroundConfig.t) => { params->UrlSearchParams.delete("experimental") } + if config.gentypeEnabled { + params->UrlSearchParams.set("gentype", "true") + } else { + params->UrlSearchParams.delete("gentype") + } + + switch config.sourceMapMode { + | Disabled => + params->UrlSearchParams.delete("sourceMap") + params->UrlSearchParams.delete("sourceMapSourcesContent") + params->UrlSearchParams.delete("sourceMapRoot") + | sourceMapMode => + params->UrlSearchParams.set("sourceMap", (sourceMapMode :> string)) + params->UrlSearchParams.set( + "sourceMapSourcesContent", + config.sourceMapSourcesContent ? "true" : "false", + ) + if config.sourceMapRoot === "" { + params->UrlSearchParams.delete("sourceMapRoot") + } else { + params->UrlSearchParams.set("sourceMapRoot", config.sourceMapRoot) + } + } + let query = params->UrlSearchParams.toString let nextUrl = Location.pathname ++ (query === "" ? "" : "?" ++ query) ++ Location.hash History.replaceState(nextUrl) @@ -85,6 +109,29 @@ let queryExperimentalFeatures = defaultExperimentalFeatures => | _ => defaultExperimentalFeatures } +let querySourceMapMode = defaultValue => + switch getParam("sourceMap") { + | Some(value) => + switch value->PlaygroundConfig.parseSourceMapMode { + | Some(sourceMapMode) => sourceMapMode + | None => defaultValue + } + | None => defaultValue + } + +let queryBool = (~name, ~defaultValue) => + switch getParam(name) { + | Some(value) if value === "true" || value === "1" => true + | Some(value) if value === "false" || value === "0" => false + | _ => defaultValue + } + +let querySourceMapRoot = defaultValue => + switch getParam("sourceMapRoot") { + | Some(value) => value + | None => defaultValue + } + let queryConfig = (~defaultConfig: PlaygroundConfig.t) => { let requestedCompilerVersion = queryCompilerVersion(defaultConfig.compilerVersion) let compilerVersion = @@ -98,6 +145,13 @@ let queryConfig = (~defaultConfig: PlaygroundConfig.t) => { warnFlags: queryWarnFlags(defaultConfig.warnFlags), jsxPreserveMode: queryJsxPreserveMode(defaultConfig.jsxPreserveMode), experimentalFeatures: queryExperimentalFeatures(defaultConfig.experimentalFeatures), + gentypeEnabled: queryBool(~name="gentype", ~defaultValue=defaultConfig.gentypeEnabled), + sourceMapMode: querySourceMapMode(defaultConfig.sourceMapMode), + sourceMapSourcesContent: queryBool( + ~name="sourceMapSourcesContent", + ~defaultValue=defaultConfig.sourceMapSourcesContent, + ), + sourceMapRoot: querySourceMapRoot(defaultConfig.sourceMapRoot), } }