Skip to content

Commit 7e2167b

Browse files
committed
Add support for experimental releases (aka ReScript 11 alpha.5)
1 parent 9d55261 commit 7e2167b

File tree

5 files changed

+55
-24
lines changed

5 files changed

+55
-24
lines changed

src/Playground.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,19 @@ module Settings = {
10571057
let id = (evt->ReactEvent.Form.target)["value"]
10581058
onCompilerSelect(id)
10591059
}}>
1060+
{switch readyState.experimentalVersions {
1061+
| [] => React.null
1062+
| experimentalVersions =>
1063+
<>
1064+
<option disabled=true className="py-4"> {React.string("---Experimental---")} </option>
1065+
{Belt.Array.map(experimentalVersions, version =>
1066+
<option className="py-4" key=version value=version>
1067+
{React.string(version)}
1068+
</option>
1069+
)->React.array}
1070+
<option disabled=true className="py-4"> {React.string("---Official Releases---")} </option>
1071+
</>
1072+
}}
10601073
{Belt.Array.map(readyState.versions, version =>
10611074
<option className="py-4" key=version value=version> {React.string(version)} </option>
10621075
)->React.array}

src/bindings/RescriptCompilerApi.res

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ module Version = {
3535
type t =
3636
| V1
3737
| V2
38+
| V3
3839
| UnknownVersion(string)
3940

4041
// Helps finding the right API version
@@ -55,13 +56,15 @@ module Version = {
5556
| _ => UnknownVersion(apiVersion)
5657
}
5758
| list{"2"} => V2
59+
| list{"3"} => V3
5860
| _ => UnknownVersion(apiVersion)
5961
}
6062

6163
let toString = t =>
6264
switch t {
6365
| V1 => "1.0"
6466
| V2 => "2.0"
67+
| V3 => "3.0"
6568
| UnknownVersion(version) => version
6669
}
6770

@@ -70,7 +73,7 @@ module Version = {
7073
let availableLanguages = t =>
7174
switch t {
7275
| V1 => [Lang.Reason, Res]
73-
| V2 => [Lang.Res]
76+
| V2 | V3 => [Lang.Res]
7477
| UnknownVersion(_) => [Res]
7578
}
7679
}
@@ -344,6 +347,7 @@ module Config = {
344347
type t = {
345348
module_system: string,
346349
warn_flags: string,
350+
uncurried?: bool,
347351
}
348352
}
349353

src/bindings/RescriptCompilerApi.resi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module Version: {
2323
type t =
2424
| V1
2525
| V2
26+
| V3
2627
| UnknownVersion(string)
2728

2829
// Helps finding the right API version
@@ -156,6 +157,8 @@ module Config: {
156157
type t = {
157158
module_system: string,
158159
warn_flags: string,
160+
/** Only available in apiVersion > 3 (= ReScript 11+) */
161+
uncurried?: bool,
159162
}
160163
}
161164

src/common/CompilerManagerHook.res

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ module CdnMeta = {
4949
"v8.3.0-dev.2",
5050
]
5151

52+
let experimentalVersions = ["v11.0.0-alpha.5"]
53+
5254
let getCompilerUrl = (version: string): string =>
5355
j`https://cdn.rescript-lang.org/$version/compiler.js`
5456

@@ -66,26 +68,30 @@ module FinalResult = {
6668

6769
// This will a given list of libraries to a specific target version of the compiler.
6870
// E.g. starting from v9, @rescript/react instead of reason-react is used.
69-
let migrateLibraries = (~version: string, libraries: array<string>): array<string> => {
71+
// If the version can't be parsed, an empty array will be returned.
72+
let getLibrariesForVersion = (~version: string): array<string> => {
7073
switch Js.String2.split(version, ".")->Belt.List.fromArray {
7174
| list{major, ..._rest} =>
7275
let version =
7376
Js.String2.replace(major, "v", "")->Belt.Int.fromString->Belt.Option.getWithDefault(0)
7477

75-
Belt.Array.map(libraries, library => {
76-
if version >= 9 {
77-
switch library {
78-
| "reason-react" => "@rescript/react"
79-
| _ => library
80-
}
81-
} else {
82-
switch library {
83-
| "@rescript/react" => "reason-react"
84-
| _ => library
85-
}
86-
}
87-
})
88-
| _ => libraries
78+
let libraries = if version >= 9 {
79+
["@rescript/react"]
80+
} else if version < 9 {
81+
["reason-react"]
82+
} else {
83+
[]
84+
}
85+
86+
// Since version 11, we ship the compiler-builtins as a separate file, and
87+
// we also added @rescript/core as a pre-vendored package
88+
if version >= 11 {
89+
libraries->Js.Array2.push("@rescript/core")->ignore
90+
libraries->Js.Array2.push("compiler-builtins")->ignore
91+
}
92+
93+
libraries
94+
| _ => []
8995
}
9096
}
9197

@@ -154,6 +160,7 @@ type selected = {
154160

155161
type ready = {
156162
versions: array<string>,
163+
experimentalVersions: array<string>,
157164
selected: selected,
158165
targetLang: Lang.t,
159166
errors: array<string>, // For major errors like bundle loading
@@ -336,8 +343,9 @@ let useCompilerManager = (
336343
// to "latest"
337344
let initVersion = switch initialVersion {
338345
| Some(version) =>
346+
let allVersions = Belt.Array.concat(CdnMeta.versions, CdnMeta.experimentalVersions)
339347
if (
340-
CdnMeta.versions->Js.Array2.some(v => {
348+
allVersions->Js.Array2.some(v => {
341349
version == v
342350
})
343351
) {
@@ -349,7 +357,7 @@ let useCompilerManager = (
349357
}
350358

351359
// Latest version is already running on @rescript/react
352-
let libraries = ["@rescript/react"]
360+
let libraries = getLibrariesForVersion(~version=initVersion)
353361

354362
switch await attachCompilerAndLibraries(~version=initVersion, ~libraries, ()) {
355363
| Ok() =>
@@ -386,6 +394,7 @@ let useCompilerManager = (
386394
selected,
387395
targetLang,
388396
versions,
397+
experimentalVersions: CdnMeta.experimentalVersions,
389398
errors: [],
390399
result: FinalResult.Nothing,
391400
}))
@@ -395,10 +404,10 @@ let useCompilerManager = (
395404
dispatchError(CompilerLoadingError(msg))
396405
}
397406
}
398-
| SwitchingCompiler(ready, version, libraries) =>
399-
let migratedLibraries = libraries->migrateLibraries(~version)
407+
| SwitchingCompiler(ready, version, _libraries) =>
408+
let libraries = getLibrariesForVersion(~version)
400409

401-
switch await attachCompilerAndLibraries(~version, ~libraries=migratedLibraries, ()) {
410+
switch await attachCompilerAndLibraries(~version, ~libraries, ()) {
402411
| Ok() =>
403412
// Make sure to remove the previous script from the DOM as well
404413
LoadScript.removeScript(~src=CdnMeta.getCompilerUrl(ready.selected.id))
@@ -418,14 +427,15 @@ let useCompilerManager = (
418427
compilerVersion: instance->Compiler.version,
419428
ocamlVersion: instance->Compiler.ocamlVersion,
420429
config,
421-
libraries: migratedLibraries,
430+
libraries,
422431
instance,
423432
}
424433

425434
setState(_ => Ready({
426435
selected,
427436
targetLang: Version.defaultTargetLang,
428437
versions: ready.versions,
438+
experimentalVersions: ready.experimentalVersions,
429439
errors: [],
430440
result: FinalResult.Nothing,
431441
}))
@@ -439,13 +449,13 @@ let useCompilerManager = (
439449
let instance = ready.selected.instance
440450

441451
let compResult = switch apiVersion {
442-
| Version.V1 =>
452+
| V1 =>
443453
switch lang {
444454
| Lang.OCaml => instance->Compiler.ocamlCompile(code)
445455
| Lang.Reason => instance->Compiler.reasonCompile(code)
446456
| Lang.Res => instance->Compiler.resCompile(code)
447457
}
448-
| Version.V2 =>
458+
| V2 | V3 =>
449459
switch lang {
450460
| Lang.OCaml => instance->Compiler.ocamlCompile(code)
451461
| Lang.Reason =>

src/common/CompilerManagerHook.resi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type selected = {
2525

2626
type ready = {
2727
versions: array<string>,
28+
experimentalVersions: array<string>,
2829
selected: selected,
2930
targetLang: Lang.t,
3031
errors: array<string>, // For major errors like bundle loading

0 commit comments

Comments
 (0)