Skip to content

Commit 4e3734e

Browse files
Playground: auto-open @rescript/core when loaded
1 parent a66149e commit 4e3734e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Playground.res

+7
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,16 @@ module Settings = {
900900

901901
let onResetClick = evt => {
902902
ReactEvent.Mouse.preventDefault(evt)
903+
904+
let open_modules =
905+
readyState.selected.libraries->Belt.Array.some(el => el === "@rescript/core")
906+
? Some(["RescriptCore"])
907+
: None
908+
903909
let defaultConfig = {
904910
Api.Config.module_system: "nodejs",
905911
warn_flags: "+a-4-9-20-40-41-42-50-61-102-109",
912+
?open_modules,
906913
}
907914
setConfig(defaultConfig)
908915
}

src/bindings/RescriptCompilerApi.res

+4
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ module Config = {
348348
module_system: string,
349349
warn_flags: string,
350350
uncurried?: bool,
351+
open_modules?: array<string>,
351352
}
352353
}
353354

@@ -423,6 +424,8 @@ module Compiler = {
423424

424425
@send external setWarnFlags: (t, string) => bool = "setWarnFlags"
425426

427+
@send external setOpenModules: (t, array<string>) => bool = "setOpenModules"
428+
426429
let setConfig = (t: t, config: Config.t): unit => {
427430
let moduleSystem = switch config.module_system {
428431
| "nodejs" => #nodejs->Some
@@ -431,6 +434,7 @@ module Compiler = {
431434
}
432435

433436
Belt.Option.forEach(moduleSystem, moduleSystem => t->setModuleSystem(moduleSystem)->ignore)
437+
Belt.Option.forEach(config.open_modules, modules => t->setOpenModules(modules)->ignore)
434438

435439
t->setWarnFlags(config.warn_flags)->ignore
436440
}

src/bindings/RescriptCompilerApi.resi

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ module Config: {
159159
warn_flags: string,
160160
/** Only available in apiVersion > 3 (= ReScript 11+) */
161161
uncurried?: bool,
162+
open_modules?: array<string>,
162163
}
163164
}
164165

@@ -197,6 +198,7 @@ module Compiler: {
197198
let setModuleSystem: (t, [#es6 | #nodejs]) => bool
198199

199200
let setWarnFlags: (t, string) => bool
201+
let setOpenModules: (t, array<string>) => bool
200202
let setConfig: (t, Config.t) => unit
201203

202204
// General format function

0 commit comments

Comments
 (0)