diff --git a/common/Mdx.res b/common/Mdx.res index 3eceec600..f0db0d61d 100644 --- a/common/Mdx.res +++ b/common/Mdx.res @@ -48,8 +48,7 @@ module MdxChildren: { } = { type unknown - @unboxed - type rec t = Any('a): t + type t type case = | String(string) @@ -57,7 +56,7 @@ module MdxChildren: { | Array(array) | Unknown(unknown) - let classify = (Any(v): t): case => + let classify = (v: t): case => if %raw(`function (a) { return a instanceof Array}`)(v) { Array((Obj.magic(v): array)) } else if Js.typeof(v) == "string" { diff --git a/common/MetaFrontmatter.js b/common/MetaFrontmatter.js deleted file mode 100644 index 2de49633d..000000000 --- a/common/MetaFrontmatter.js +++ /dev/null @@ -1,16 +0,0 @@ -// Generated by ReScript, PLEASE EDIT WITH CARE - - -function decode(json) { - return { - TAG: 1, - _0: "Not implemented", - [Symbol.for("name")]: "Error" - }; -} - -export { - decode , - -} -/* No side effect */ diff --git a/common/MetaFrontmatter.res b/common/MetaFrontmatter.res deleted file mode 100644 index ad4f147c3..000000000 --- a/common/MetaFrontmatter.res +++ /dev/null @@ -1,10 +0,0 @@ -// This module is used for accessing meta data from MDX frontmatter -// It's mostly used in conjunction with the component - -// Note: Every optional value in here must be encoded -// as Js.Null.t, since it will be used for JSON serialization -// within Next's static generation - -type t - -let decode = (json: Js.Json.t): result => Error("Not implemented") diff --git a/compilers/README.md b/compilers/README.md new file mode 100644 index 000000000..37503ac3b --- /dev/null +++ b/compilers/README.md @@ -0,0 +1,5 @@ +# compilers + +This folder is needed to install additional rescript compiler versions for testing our documented source code on multiple compiler versions. + +Our `scripts/test-examples.js` script will automatically install all package.json dependencies if it cannot find any compiler versions. diff --git a/compilers/package-lock.json b/compilers/package-lock.json new file mode 100644 index 000000000..0edc863f2 --- /dev/null +++ b/compilers/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "compilers", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "rescript-820": { + "version": "npm:bs-platform@8.2.0", + "resolved": "https://registry.npmjs.org/bs-platform/-/bs-platform-8.2.0.tgz", + "integrity": "sha512-quvmUac/ZxGDsT7L5+6RNXrLPvLHkWFownacaqlwVoyAm770bPyupTRU49ALPGk3HpjfD5eE+lpGdOSPtuwJiA==" + } + } +} diff --git a/compilers/package.json b/compilers/package.json new file mode 100644 index 000000000..4d308f493 --- /dev/null +++ b/compilers/package.json @@ -0,0 +1,10 @@ +{ + "name": "compilers", + "private": true, + "version": "1.0.0", + "main": "index.js", + "license": "MIT", + "dependencies": { + "rescript-820": "npm:bs-platform@8.2.0" + } +} diff --git a/components/ApiMarkdown.res b/components/ApiMarkdown.res index 78e8f884b..fa48b4f0b 100644 --- a/components/ApiMarkdown.res +++ b/components/ApiMarkdown.res @@ -1,7 +1,3 @@ -// This file was automatically converted to ReScript from 'ApiMarkdown.re' -// Check the output and make sure to delete the original file -open Util.ReactStuff - /* This module is intended for the ODOC like documentation layout. It hides the h2 tags and does diff --git a/components/Button.res b/components/Button.res index f3fa964fb..9f71c0399 100644 --- a/components/Button.res +++ b/components/Button.res @@ -1,5 +1,3 @@ -open Util.ReactStuff - @react.component let make = (~children) => }) - let body = switch Belt.Array.get(tabs, current) { - | Some(tab) => tab.content - | None => React.null - } - let body = Belt.Array.mapWithIndex(tabs, (i, tab) => { let className = current === i ? "block h-full" : "hidden" @@ -511,7 +506,7 @@ module ResultPane = { } module WarningFlagsWidget = { - @bs.set external scrollTop: (Dom.element, int) => unit = "scrollTop" + @bs.set external _scrollTop: (Dom.element, int) => unit = "scrollTop" @bs.send external focus: Dom.element => unit = "focus" @bs.send external scrollIntoView: (Dom.element, @bs.as(json`false`) _) => unit = "scrollIntoView" @@ -693,10 +688,10 @@ module WarningFlagsWidget = { let inputRef = React.useRef(Js.Nullable.null) let focusInput = () => - React.Ref.current(inputRef)->Js.Nullable.toOption->Belt.Option.forEach(el => el->focus) + inputRef.current->Js.Nullable.toOption->Belt.Option.forEach(el => el->focus) let blurInput = () => - React.Ref.current(inputRef)->Js.Nullable.toOption->Belt.Option.forEach(el => el->blur) + inputRef.current->Js.Nullable.toOption->Belt.Option.forEach(el => el->blur) let chips = Belt.Array.mapWithIndex(flags, (i, token) => { let {WarningFlagDescription.Parser.flag: flag, enabled} = token @@ -766,7 +761,7 @@ module WarningFlagsWidget = { let key = ReactEvent.Keyboard.key(evt) let ctrlKey = ReactEvent.Keyboard.ctrlKey(evt) - let caretPosition = ReactEvent.Keyboard.target(evt)["selectionStart"] + /* let caretPosition = ReactEvent.Keyboard.target(evt)["selectionStart"] */ /* Js.log2("caretPosition", caretPosition); */ let full = (ctrlKey ? "CTRL+" : "") ++ key @@ -856,7 +851,7 @@ module WarningFlagsWidget = { let ref = if selected === i { ReactDOMRe.Ref.callbackDomRef(dom => { let el = Js.Nullable.toOption(dom) - let parent = React.Ref.current(listboxRef)->Js.Nullable.toOption + let parent = listboxRef.current->Js.Nullable.toOption switch (parent, el) { | (Some(parent), Some(el)) => scrollToElement(~parent, el) @@ -969,7 +964,7 @@ module WarningFlagsWidget = { "border-night-light" } - let areaOnFocus = evt => + let areaOnFocus = _evt => if !isActive { focusInput() } @@ -1018,21 +1013,15 @@ module Settings = { ~readyState: CompilerManagerHook.ready, ~dispatch: CompilerManagerHook.action => unit, ~setConfig: Api.Config.t => unit, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ~config: Api.Config.t, ) => { let {Api.Config.warn_flags: warn_flags} = config - let targetLangVersion = switch readyState.targetLang { - | Res => (Api.Lang.Res, readyState.selected.compilerVersion) - | Reason => (Reason, readyState.selected.reasonVersion) - | OCaml => (OCaml, readyState.selected.ocamlVersion) - } - let availableTargetLangs = Api.Version.availableLanguages(readyState.selected.apiVersion) let onTargetLangSelect = lang => - dispatch(SwitchLanguage({lang: lang, code: React.Ref.current(editorCode)})) + dispatch(SwitchLanguage({lang: lang, code: editorCode.current})) let onWarningFlagsUpdate = flags => { let normalizeEmptyFlags = flags => @@ -1211,7 +1200,7 @@ module ControlPanel = { ~actionIndicatorKey: string, ~state: CompilerManagerHook.state, ~dispatch: CompilerManagerHook.action => unit, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ) => { let router = Next.Router.useRouter() let children = switch state { @@ -1221,7 +1210,7 @@ module ControlPanel = { | Ready(ready) => let onFormatClick = evt => { ReactEvent.Mouse.preventDefault(evt) - dispatch(Format(React.Ref.current(editorCode))) + dispatch(Format(editorCode.current)) } let createShareLink = () => { @@ -1232,7 +1221,7 @@ module ControlPanel = { Js.Array2.push( params, - ("code", editorCode->React.Ref.current->LzString.compressToEncodedURIComponent), + ("code", editorCode.current->LzString.compressToEncodedURIComponent), )->ignore let querystring = Belt.Array.reduce(params, "", (acc, next) => { @@ -1288,10 +1277,9 @@ module OutputPanel = { @react.component let make = ( - ~actionIndicatorKey, ~compilerDispatch, ~compilerState: CompilerManagerHook.state, - ~editorCode: React.Ref.t, + ~editorCode: React.ref, ) => { /* We need the prevState to understand different @@ -1303,7 +1291,7 @@ module OutputPanel = { */ let prevState = React.useRef(None) - let cmCode = switch React.Ref.current(prevState) { + let cmCode = switch prevState.current { | Some(prev) => switch (prev, compilerState) { | (_, Ready({result: Nothing})) => None @@ -1324,7 +1312,7 @@ module OutputPanel = { } } - React.Ref.setCurrent(prevState, Some(compilerState)) + prevState.current = Some(compilerState) let resultPane = switch compilerState { | Compiling(ready, _) @@ -1390,7 +1378,7 @@ module OutputPanel = { let prevSelected = React.useRef(0) let selected = switch compilerState { - | Compiling(_, _) => React.Ref.current(prevSelected) + | Compiling(_, _) => prevSelected.current | Ready(ready) => switch ready.result { | Comp(Success(_)) @@ -1400,7 +1388,7 @@ module OutputPanel = { | _ => 0 } - React.Ref.setCurrent(prevSelected, selected) + prevSelected.current = selected let tabs = [ {Pane.title: "JavaScript", content: output}, @@ -1499,7 +1487,7 @@ let default = () => { // The user can focus an error / warning on a specific line & column // which is stored in this ref and triggered by hover / click states // in the CodeMirror editor - let (focusedRowCol, setFocusedRowCol) = React.useState(_ => None) + let (_focusedRowCol, setFocusedRowCol) = React.useState(_ => None) let editorCode = React.useRef(initialContent) @@ -1507,9 +1495,9 @@ let default = () => { we take any success results and set the editor code to the new formatted code */ switch compilerState { | Ready({result: FinalResult.Nothing} as ready) => - compilerDispatch(CompileCode(ready.targetLang, React.Ref.current(editorCode))) + compilerDispatch(CompileCode(ready.targetLang, editorCode.current)) | Ready({result: FinalResult.Conv(Api.ConversionResult.Success({code}))}) => - React.Ref.setCurrent(editorCode, code) + editorCode.current = code | _ => () } @@ -1525,13 +1513,12 @@ let default = () => { let timeoutCompile = React.useRef(() => ()) React.useEffect1(() => { - React.Ref.setCurrent(timeoutCompile, () => + timeoutCompile.current = () => switch compilerState { - | Ready(ready) => - compilerDispatch(CompileCode(ready.targetLang, React.Ref.current(editorCode))) + | Ready(ready) => compilerDispatch(CompileCode(ready.targetLang, editorCode.current)) | _ => () } - ) + None }, [compilerState]) @@ -1598,21 +1585,21 @@ let default = () => { maxHeight="calc(100vh - 10rem)" mode="reason" errors=cmErrors - value={React.Ref.current(editorCode)} + value={editorCode.current} onChange={value => { - React.Ref.setCurrent(editorCode, value) + editorCode.current = value - switch React.Ref.current(typingTimer) { + switch typingTimer.current { | None => () | Some(timer) => Js.Global.clearTimeout(timer) } let timer = Js.Global.setTimeout(() => { - React.Ref.current(timeoutCompile)() - React.Ref.setCurrent(typingTimer, None) + timeoutCompile.current() + typingTimer.current = None }, 100) - React.Ref.setCurrent(typingTimer, Some(timer)) + typingTimer.current = Some(timer) }} - onMarkerFocus={rowCol => setFocusedRowCol(prev => Some(rowCol))} + onMarkerFocus={rowCol => setFocusedRowCol(_prev => Some(rowCol))} onMarkerFocusLeave={_ => setFocusedRowCol(_ => None)} /> @@ -1620,12 +1607,7 @@ let default = () => {
1024 ? "56rem" : "100%", ())}> - +
{ + if (fs.existsSync(bsc)) { + return; + } + console.log("compilers not installed. Installing compilers..."); + child_process.execFileSync("npm", ['install'], {cwd: compilersDir}) +} let parseFile = content => { if (!/```res (example|prelude|sig)/.test(content)) { @@ -50,6 +62,10 @@ let postprocessOutput = (file, error) => { }) } + +prepareCompilers(); + +console.log("Running tests...") fs.writeFileSync(tempFileName, '') let success = true diff --git a/yarn.lock b/yarn.lock index 198b47fbe..ed20de9b2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2161,10 +2161,10 @@ bs-fetch@^0.3.1: resolved "https://registry.yarnpkg.com/bs-fetch/-/bs-fetch-0.3.1.tgz#9c7d074b27e6bb2b9f2ec985964f32bcac49f79e" integrity sha512-MxwnuuXPldXnoCtlpeN5JNbbmb1tVgsqpLfVunvuMLAIQNyP0TqoImHiQRTz38PBSN8/iX+2yVlm+PFJfnHHiA== -bs-platform@8.3.2: - version "8.3.2" - resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.2.tgz#c307f1cc2d2397c3d088c7f3b62e9f493283cdcf" - integrity sha512-iOTi5JIlNPoCPq31NS9ET79FLyCpwTL2JZbgHz35LzY9Bch1iDtbBR3FVGhRbjphxelAP4fLlFONfUNp5Y3a5g== +bs-platform@8.3.3-dev.2: + version "8.3.3-dev.2" + resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.3.3-dev.2.tgz#af94cf48708899b02af76095d4197e20e6d12e97" + integrity sha512-2G2PPIFhUBoN1tzZW9PurjWgvCg+Lx/gIqkAjPaDIIA6S8GFPs/UcTyl4ZwJNvQdKv33Qgih2eYTiBp4hCM3MQ== buffer-from@^1.0.0, buffer-from@^1.1.1: version "1.1.1"