Skip to content

Commit 6d4ed7f

Browse files
committed
track module system in playground url
1 parent 915053e commit 6d4ed7f

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/Playground.res

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,8 @@ let make = (~versions: array<string>) => {
14291429
| _ => Api.Lang.Res
14301430
}
14311431

1432+
let initialModuleSystem = Dict.get(router.query, "module")
1433+
14321434
let initialContent = switch (Dict.get(router.query, "code"), initialLang) {
14331435
| (Some(compressedCode), _) => LzString.decompressToEncodedURIComponent(compressedCode)
14341436
| (None, Reason) => initialReContent
@@ -1447,6 +1449,7 @@ let make = (~versions: array<string>) => {
14471449
let onAction = _ => setActionCount(prev => prev > 1000000 ? 0 : prev + 1)
14481450
let (compilerState, compilerDispatch) = useCompilerManager(
14491451
~initialVersion?,
1452+
~initialModuleSystem?,
14501453
~initialLang,
14511454
~onAction,
14521455
~versions,

src/common/CompilerManagerHook.res

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,14 @@ type action =
242242
| CompileCode(Lang.t, string)
243243
| UpdateConfig(Config.t)
244244

245-
let createUrl = (pathName, {code, selected: {compilerVersion}, targetLang}) => {
246-
let params = switch targetLang {
245+
let createUrl = (pathName, ready) => {
246+
let params = switch ready.targetLang {
247247
| Res => []
248248
| lang => [("ext", RescriptCompilerApi.Lang.toExt(lang))]
249249
}
250-
Array.push(params, ("version", "v" ++ compilerVersion))
251-
Array.push(params, ("code", code->LzString.compressToEncodedURIComponent))
250+
Array.push(params, ("version", "v" ++ ready.selected.compilerVersion))
251+
Array.push(params, ("module", ready.selected.config.module_system))
252+
Array.push(params, ("code", ready.code->LzString.compressToEncodedURIComponent))
252253
let querystring = params->Array.map(((key, value)) => key ++ "=" ++ value)->Array.join("&")
253254
let url = pathName ++ "?" ++ querystring
254255
url
@@ -267,6 +268,7 @@ let createUrl = (pathName, {code, selected: {compilerVersion}, targetLang}) => {
267268
// cases where the output didn't visually change)
268269
let useCompilerManager = (
269270
~initialVersion: option<Semver.t>=?,
271+
~initialModuleSystem="esmodule",
270272
~initialLang: Lang.t=Res,
271273
~onAction: option<action => unit>=?,
272274
~versions: array<Semver.t>,
@@ -430,7 +432,7 @@ let useCompilerManager = (
430432
// internal compiler state with our playground state.
431433
let config = {
432434
...instance->Compiler.getConfig,
433-
module_system: "esmodule",
435+
module_system: initialModuleSystem,
434436
?open_modules,
435437
}
436438
instance->Compiler.setConfig(config)

src/common/CompilerManagerHook.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ type action =
5959

6060
let useCompilerManager: (
6161
~initialVersion: Semver.t=?,
62+
~initialModuleSystem: string=?,
6263
~initialLang: Lang.t=?,
6364
~onAction: action => unit=?,
6465
~versions: array<Semver.t>,

0 commit comments

Comments
 (0)