@@ -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
155161type 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 =>
0 commit comments