diff --git a/apps/docs/e2e/Playground.cy.res b/apps/docs/e2e/Playground.cy.res index f4fd5eb09..a47aa870b 100644 --- a/apps/docs/e2e/Playground.cy.res +++ b/apps/docs/e2e/Playground.cy.res @@ -98,6 +98,30 @@ describe("Playground", () => { ) }) + it("should run exception code with v13.0.0-alpha.6", () => { + let code = `exception HttpError({status: int}) + +let isRetriable: exn => bool = error => + switch error { + | HttpError({status: 502 | 503 | 504}) => true + | _ => false + } + +Console.log(isRetriable(HttpError({status: 500})))` + let compressedCode = LzString.lzString.compressToEncodedURIComponent(code) + visit(`/try?version=v13.0.0-alpha.6&code=${compressedCode}`) + waitForPlayground() + + get("pre.whitespace-pre-wrap")->shouldContainText("Primitive_exceptions.mjs")->ignore + getByTestId("control-panel") + ->find("button") + ->containsChainable("Run") + ->click + ->ignore + + get("div.whitespace-pre-wrap pre")->shouldContainText("false")->ignore + }) + it("should open the landing page example in the playground with code and compiled output", () => { containsSelector("a", "Edit this example in Playground") ->scrollIntoView diff --git a/apps/guide/__tests__/GuideRuntime_.test.res b/apps/guide/__tests__/GuideRuntime_.test.res index 8c708ea54..95da4ff5e 100644 --- a/apps/guide/__tests__/GuideRuntime_.test.res +++ b/apps/guide/__tests__/GuideRuntime_.test.res @@ -124,6 +124,32 @@ test("normalizes old compiler runtime import filenames", async () => { )->toBe("core__array") }) +test("resolves v13 exception imports to the published runtime file", async () => { + let compilerVersion = Semver.parse("v13.0.0-alpha.6")->Option.getOrThrow + let url = GuideRuntimeImport.url( + ~bundleBaseUrl="https://cdn.rescript-lang.org", + ~compilerVersion, + "./stdlib/Primitive_exceptions.mjs", + ) + + expect(url)->toBe( + "https://cdn.rescript-lang.org/v13.0.0-alpha.6/compiler-builtins/stdlib/Primitive_exceptions.js", + ) +}) + +test("preserves runtime imports that already use the published extension", async () => { + let compilerVersion = Semver.parse("v12.3.1")->Option.getOrThrow + let url = GuideRuntimeImport.url( + ~bundleBaseUrl="https://cdn.rescript-lang.org", + ~compilerVersion, + "./stdlib/Stdlib_Array.js", + ) + + expect(url)->toBe( + "https://cdn.rescript-lang.org/v12.3.1/compiler-builtins/stdlib/Stdlib_Array.js", + ) +}) + test("normalizes old compiler versions for runtime imports", async () => { let alpha7 = Semver.parse("v12.0.0-alpha.7")->Option.getOrThrow let alpha9 = Semver.parse("v12.0.0-alpha.9")->Option.getOrThrow diff --git a/packages/playground/src/CompilerManagerHook.res b/packages/playground/src/CompilerManagerHook.res index 65cf44aca..49df72d48 100644 --- a/packages/playground/src/CompilerManagerHook.res +++ b/packages/playground/src/CompilerManagerHook.res @@ -41,8 +41,15 @@ module CdnMeta = { let getLibraryCmijUrl = (baseUrl, version, libraryName: string): string => `${baseUrl}/${Semver.toString(version)}/${libraryName}/cmij.js` - let getStdlibRuntimeUrl = (baseUrl, version, filename) => + let getStdlibRuntimeUrl = (baseUrl, version, filename) => { + // The compiler emits .mjs imports, while the published runtime bundles use .js. + let filename = if filename->String.endsWith(".mjs") { + filename->String.slice(~start=0, ~end=-4) ++ ".js" + } else { + filename + } `${baseUrl}/${Semver.toString(version)}/compiler-builtins/stdlib/${filename}` + } } module FinalResult = {