@@ -49,6 +49,8 @@ module CdnMeta = {
49
49
"v8.3.0-dev.2" ,
50
50
]
51
51
52
+ let experimentalVersions = ["v11.0.0-alpha.5" ]
53
+
52
54
let getCompilerUrl = (version : string ): string =>
53
55
j ` https://cdn.rescript-lang.org/$version/compiler.js`
54
56
@@ -66,26 +68,30 @@ module FinalResult = {
66
68
67
69
// This will a given list of libraries to a specific target version of the compiler.
68
70
// 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 > => {
70
73
switch Js .String2 .split (version , "." )-> Belt .List .fromArray {
71
74
| list {major , ... _rest } =>
72
75
let version =
73
76
Js .String2 .replace (major , "v" , "" )-> Belt .Int .fromString -> Belt .Option .getWithDefault (0 )
74
77
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
+ | _ => []
89
95
}
90
96
}
91
97
@@ -154,6 +160,7 @@ type selected = {
154
160
155
161
type ready = {
156
162
versions : array <string >,
163
+ experimentalVersions : array <string >,
157
164
selected : selected ,
158
165
targetLang : Lang .t ,
159
166
errors : array <string >, // For major errors like bundle loading
@@ -336,8 +343,9 @@ let useCompilerManager = (
336
343
// to "latest"
337
344
let initVersion = switch initialVersion {
338
345
| Some (version ) =>
346
+ let allVersions = Belt .Array .concat (CdnMeta .versions , CdnMeta .experimentalVersions )
339
347
if (
340
- CdnMeta . versions -> Js .Array2 .some (v => {
348
+ allVersions -> Js .Array2 .some (v => {
341
349
version == v
342
350
})
343
351
) {
@@ -349,7 +357,7 @@ let useCompilerManager = (
349
357
}
350
358
351
359
// Latest version is already running on @rescript/react
352
- let libraries = [ "@rescript/react" ]
360
+ let libraries = getLibrariesForVersion (~ version = initVersion )
353
361
354
362
switch await attachCompilerAndLibraries (~version = initVersion , ~libraries , ()) {
355
363
| Ok () =>
@@ -386,6 +394,7 @@ let useCompilerManager = (
386
394
selected ,
387
395
targetLang ,
388
396
versions ,
397
+ experimentalVersions : CdnMeta .experimentalVersions ,
389
398
errors : [],
390
399
result : FinalResult .Nothing ,
391
400
}))
@@ -395,10 +404,10 @@ let useCompilerManager = (
395
404
dispatchError (CompilerLoadingError (msg ))
396
405
}
397
406
}
398
- | SwitchingCompiler (ready , version , libraries ) =>
399
- let migratedLibraries = libraries -> migrateLibraries (~version )
407
+ | SwitchingCompiler (ready , version , _libraries ) =>
408
+ let libraries = getLibrariesForVersion (~version )
400
409
401
- switch await attachCompilerAndLibraries (~version , ~libraries = migratedLibraries , ()) {
410
+ switch await attachCompilerAndLibraries (~version , ~libraries , ()) {
402
411
| Ok () =>
403
412
// Make sure to remove the previous script from the DOM as well
404
413
LoadScript .removeScript (~src = CdnMeta .getCompilerUrl (ready .selected .id ))
@@ -418,14 +427,15 @@ let useCompilerManager = (
418
427
compilerVersion : instance -> Compiler .version ,
419
428
ocamlVersion : instance -> Compiler .ocamlVersion ,
420
429
config ,
421
- libraries : migratedLibraries ,
430
+ libraries ,
422
431
instance ,
423
432
}
424
433
425
434
setState (_ => Ready ({
426
435
selected ,
427
436
targetLang : Version .defaultTargetLang ,
428
437
versions : ready .versions ,
438
+ experimentalVersions : ready .experimentalVersions ,
429
439
errors : [],
430
440
result : FinalResult .Nothing ,
431
441
}))
@@ -439,13 +449,13 @@ let useCompilerManager = (
439
449
let instance = ready .selected .instance
440
450
441
451
let compResult = switch apiVersion {
442
- | Version . V1 =>
452
+ | V1 =>
443
453
switch lang {
444
454
| Lang .OCaml => instance -> Compiler .ocamlCompile (code )
445
455
| Lang .Reason => instance -> Compiler .reasonCompile (code )
446
456
| Lang .Res => instance -> Compiler .resCompile (code )
447
457
}
448
- | Version . V2 =>
458
+ | V2 | V3 =>
449
459
switch lang {
450
460
| Lang .OCaml => instance -> Compiler .ocamlCompile (code )
451
461
| Lang .Reason =>
0 commit comments