Skip to content

Commit fc3191a

Browse files
committed
make playground runtime work with all compiler versions
1 parent a71ae31 commit fc3191a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/RenderPanel.res

+33-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ let wrapReactApp = code =>
44
window.reactRoot.render(React.createElement(App.make, {}));
55
})();`
66

7+
let capitalizeFirstLetter = string => {
8+
let firstLetter = string->String.charAt(0)->String.toUpperCase
9+
`${firstLetter}${string->String.sliceToEnd(~start=1)}`
10+
}
11+
712
@react.component
813
let make = (~compilerState: CompilerManagerHook.state, ~clearLogs, ~runOutput) => {
914
let (validReact, setValidReact) = React.useState(() => false)
@@ -18,7 +23,34 @@ let make = (~compilerState: CompilerManagerHook.state, ~clearLogs, ~runOutput) =
1823
let {entryPointExists, code, imports} = PlaygroundValidator.validate(ast)
1924
let imports = imports->Dict.mapValues(path => {
2025
let filename = path->String.sliceToEnd(~start=9) // the part after "./stdlib/"
21-
CompilerManagerHook.CdnMeta.getStdlibRuntimeUrl(selected.id, filename)
26+
let filename = switch selected.id {
27+
| {major: 12, minor: 0, patch: 0, preRelease: Some(Alpha(alpha))} if alpha < 8 =>
28+
let filename = if filename->String.startsWith("core__") {
29+
filename->String.sliceToEnd(~start=6)
30+
} else {
31+
filename
32+
}
33+
capitalizeFirstLetter(filename)
34+
| {major} if major < 12 && filename->String.startsWith("core__") =>
35+
capitalizeFirstLetter(filename)
36+
| _ => filename
37+
}
38+
let compilerVersion = switch selected.id {
39+
| {major: 12, minor: 0, patch: 0, preRelease: Some(Alpha(alpha))} if alpha < 8 => {
40+
Semver.major: 12,
41+
minor: 0,
42+
patch: 0,
43+
preRelease: Some(Alpha(8)),
44+
}
45+
| {major, minor} if (major === 11 && minor < 2) || major < 11 => {
46+
major: 11,
47+
minor: 2,
48+
patch: 0,
49+
preRelease: Some(Beta(1)),
50+
}
51+
| version => version
52+
}
53+
CompilerManagerHook.CdnMeta.getStdlibRuntimeUrl(compilerVersion, filename)
2254
})
2355

2456
entryPointExists

src/RenderPanel.resi

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@react.component
2+
let make: (
3+
~compilerState: CompilerManagerHook.state,
4+
~clearLogs: unit => unit,
5+
~runOutput: bool,
6+
) => Jsx.element

0 commit comments

Comments
 (0)