diff --git a/rescript.json b/rescript.json index f659cbec6..38bdaad59 100644 --- a/rescript.json +++ b/rescript.json @@ -11,7 +11,9 @@ ], "uncurried": true, "ppx-flags": [], - "bsc-flags": [], + "bsc-flags": [ + "-open RescriptCore" + ], "sources": [ { "dir": "src", diff --git a/src/Blog.res b/src/Blog.res index 4af7d2d91..42501b5ce 100644 --- a/src/Blog.res +++ b/src/Blog.res @@ -14,7 +14,6 @@ */ module Link = Next.Link -open RescriptCore let defaultPreviewImg = "/static/Art-3-rescript-launch.jpg" diff --git a/src/BlogArticle.res b/src/BlogArticle.res index fe24fe721..b13b6318c 100644 --- a/src/BlogArticle.res +++ b/src/BlogArticle.res @@ -16,7 +16,6 @@ builds are taking too long. I think we will be fine for now. Link to NextJS discussion: https://github.com/zeit/next.js/discussions/11728#discussioncomment-3501 */ -open RescriptCore let middleDotSpacer = " " ++ (String.fromCharCode(183) ++ " ") diff --git a/src/Design.res b/src/Design.res index f20027091..e86ef1d13 100644 --- a/src/Design.res +++ b/src/Design.res @@ -1,6 +1,6 @@ // NOTE: This file will later be important to document our // design tokens etc. -open RescriptCore + module ColorSquare = { @react.component let make = (~className="") => { diff --git a/src/DocsOverview.res b/src/DocsOverview.res index 79a07d7fe..02b6c95cb 100644 --- a/src/DocsOverview.res +++ b/src/DocsOverview.res @@ -1,4 +1,3 @@ -open RescriptCore module Card = { @react.component let make = (~title: string, ~hrefs: array<(string, string)>) => { diff --git a/src/SyntaxLookup.res b/src/SyntaxLookup.res index 6b5af7ea2..27f2cf986 100644 --- a/src/SyntaxLookup.res +++ b/src/SyntaxLookup.res @@ -55,9 +55,9 @@ module Status = { let compare = (a, b) => switch (a, b) { - | (Deprecated, Deprecated) | (Active, Active) => 0 - | (Active, Deprecated) => -1 - | (Deprecated, Active) => 1 + | (Deprecated, Deprecated) | (Active, Active) => Ordering.equal + | (Active, Deprecated) => Ordering.less + | (Deprecated, Active) => Ordering.greater } } @@ -76,7 +76,7 @@ module Item = { let compare = (a, b) => switch Status.compare(a.status, b.status) { - | 0 => String.compare(a.name, b.name) + | 0. => String.compare(a.name, b.name) | x => x } } @@ -299,15 +299,15 @@ let default = (props: props) => { }) }) ->Js.Dict.entries - ->Belt.Array.reduce([], (acc, entry) => { + ->Array.reduce([], (acc, entry) => { let (title, items) = entry - if Js.Array.length(items) === 0 { + if Array.length(items) === 0 { acc } else { let children = items - ->Belt.SortArray.stableSortBy(Item.compare) - ->Belt.Array.map(item => { + ->Array.toSorted(Item.compare) + ->Array.map(item => { let onMouseDown = evt => { ReactEvent.Mouse.preventDefault(evt) onSearchValueChange(item.name) diff --git a/src/bindings/RescriptCompilerApi.res b/src/bindings/RescriptCompilerApi.res index 27c800493..aad035666 100644 --- a/src/bindings/RescriptCompilerApi.res +++ b/src/bindings/RescriptCompilerApi.res @@ -128,7 +128,7 @@ module LocMsg = { let result = Js.Dict.empty() for i in 0 to Js.Array.length(arr) - 1 { - let locMsg = Js.Array2.unsafe_get(arr, i) + let locMsg = Array.getUnsafe(arr, i) let id = makeId(locMsg) // The last element with the same id wins diff --git a/src/common/Ansi.res b/src/common/Ansi.res index 1a1e667c7..512ab85b9 100644 --- a/src/common/Ansi.res +++ b/src/common/Ansi.res @@ -182,7 +182,7 @@ module Lexer = { switch x { | Some(result) => let groups = Js.Re.captures(result) - switch Js.Nullable.toOption(groups[1]) { + switch groups[1]->Option.flatMap(o => o->Js.Nullable.toOption) { | Some(str) => switch Js.String2.split(str, ";") { | ["0"] => ClearSgr({loc, raw}) diff --git a/src/common/BlogApi.res b/src/common/BlogApi.res index a7f512244..6f22d9c98 100644 --- a/src/common/BlogApi.res +++ b/src/common/BlogApi.res @@ -76,9 +76,9 @@ let getAllPosts = () => { } }) - Js.Array2.concat(nonArchivedPosts, archivedPosts)->Js.Array2.sortInPlaceWith((a, b) => { + Array.concat(nonArchivedPosts, archivedPosts)->Array.toSorted((a, b) => String.compare(Node.Path.basename(b.path), Node.Path.basename(a.path)) - }) + ) } let getLivePosts = () => { @@ -97,9 +97,9 @@ let getLivePosts = () => { } }) - livePosts->Js.Array2.sortInPlaceWith((a, b) => { + livePosts->Array.toSorted((a, b) => String.compare(Node.Path.basename(b.path), Node.Path.basename(a.path)) - }) + ) } let getArchivedPosts = () => { @@ -119,9 +119,9 @@ let getArchivedPosts = () => { } }) - archivedPosts->Js.Array2.sortInPlaceWith((a, b) => { + archivedPosts->Array.toSorted((a, b) => String.compare(Node.Path.basename(b.path), Node.Path.basename(a.path)) - }) + ) } module RssFeed = { @@ -156,7 +156,7 @@ module RssFeed = { let getLatest = (~max=10, ~baseUrl="https://rescript-lang.org", ()): array => { let items = getAllPosts() - ->Js.Array2.map(post => { + ->Array.map(post => { let fm = post.frontmatter let description = Js.Null.toOption(fm.description)->Belt.Option.getWithDefault("") { @@ -166,7 +166,7 @@ module RssFeed = { pubDate: DateStr.toDate(fm.date), } }) - ->Js.Array2.slice(~start=0, ~end_=max) + ->Array.slice(~start=0, ~end=max) items } diff --git a/src/common/Url.res b/src/common/Url.res index fb3b27089..722017bb7 100644 --- a/src/common/Url.res +++ b/src/common/Url.res @@ -64,8 +64,9 @@ let parse = (route: string): t => { (NoVersion, fullpath, []) } else { let version = switch fullpath[foundVersionIndex] { - | "latest" => Latest - | v => Version(v) + | Some("latest") => Latest + | Some(v) => Version(v) + | None => NoVersion } ( version, diff --git a/src/components/AnsiPre.res b/src/components/AnsiPre.res index 907bc1ee3..65a451dea 100644 --- a/src/components/AnsiPre.res +++ b/src/components/AnsiPre.res @@ -1,7 +1,6 @@ // This file was automatically converted to ReScript from 'AnsiPre.re' // Check the output and make sure to delete the original file open Ansi -open RescriptCore type colorTarget = | Fg diff --git a/src/vendor/Json_decode.res b/src/vendor/Json_decode.res index 6440ce47a..1281a94dd 100644 --- a/src/vendor/Json_decode.res +++ b/src/vendor/Json_decode.res @@ -43,7 +43,7 @@ let string = json => let char = json => { let s = string(json) if String.length(s) == 1 { - String.get(s, 0) + OCamlCompat.String.get(s, 0) } else { \"@@"(raise, DecodeError("Expected single-character string, got " ++ _stringify(json))) } @@ -72,26 +72,26 @@ let array = (decode, json) => let length = Js.Array.length(source) let target = _unsafeCreateUninitializedArray(length) for i in 0 to length - 1 { - let value = try decode(Array.unsafe_get(source, i)) catch { + let value = try decode(Array.getUnsafe(source, i)) catch { | DecodeError(msg) => \"@@"(raise, DecodeError(msg ++ ("\n\tin array at index " ++ string_of_int(i)))) } - Array.unsafe_set(target, i, value) + Array.setUnsafe(target, i, value) } target } else { \"@@"(raise, DecodeError("Expected array, got " ++ _stringify(json))) } -let list = (decode, json) => array(decode, json)->Array.to_list +let list = (decode, json) => array(decode, json)->List.fromArray let pair = (decodeA, decodeB, json) => if Js.Array.isArray(json) { let source: array = Obj.magic((json: Js.Json.t)) let length = Js.Array.length(source) if length == 2 { - try (decodeA(Array.unsafe_get(source, 0)), decodeB(Array.unsafe_get(source, 1))) catch { + try (decodeA(Array.getUnsafe(source, 0)), decodeB(Array.getUnsafe(source, 1))) catch { | DecodeError(msg) => \"@@"(raise, DecodeError(msg ++ "\n\tin pair/tuple2")) } } else { @@ -112,9 +112,9 @@ let tuple3 = (decodeA, decodeB, decodeC, json) => let length = Js.Array.length(source) if length == 3 { try ( - decodeA(Array.unsafe_get(source, 0)), - decodeB(Array.unsafe_get(source, 1)), - decodeC(Array.unsafe_get(source, 2)), + decodeA(Array.getUnsafe(source, 0)), + decodeB(Array.getUnsafe(source, 1)), + decodeC(Array.getUnsafe(source, 2)), ) catch { | DecodeError(msg) => \"@@"(raise, DecodeError(msg ++ "\n\tin tuple3")) } @@ -134,10 +134,10 @@ let tuple4 = (decodeA, decodeB, decodeC, decodeD, json) => let length = Js.Array.length(source) if length == 4 { try ( - decodeA(Array.unsafe_get(source, 0)), - decodeB(Array.unsafe_get(source, 1)), - decodeC(Array.unsafe_get(source, 2)), - decodeD(Array.unsafe_get(source, 3)), + decodeA(Array.getUnsafe(source, 0)), + decodeB(Array.getUnsafe(source, 1)), + decodeC(Array.getUnsafe(source, 2)), + decodeD(Array.getUnsafe(source, 3)), ) catch { | DecodeError(msg) => \"@@"(raise, DecodeError(msg ++ "\n\tin tuple4")) } @@ -162,7 +162,7 @@ let dict = (decode, json) => let l = Js.Array.length(keys) let target = Js.Dict.empty() for i in 0 to l - 1 { - let key = Array.unsafe_get(keys, i) + let key = Array.getUnsafe(keys, i) let value = try decode(Js.Dict.unsafeGet(source, key)) catch { | DecodeError(msg) => \"@@"(raise, DecodeError(msg ++ "\n\tin dict")) } @@ -208,7 +208,7 @@ let oneOf = (decoders, json) => { let rec inner = (decoders, errors) => switch decoders { | list{} => - let formattedErrors = "\n- " ++ Js.Array.joinWith("\n- ", Array.of_list(List.rev(errors))) + let formattedErrors = "\n- " ++ Js.Array.joinWith("\n- ", List.toArray(List.reverse(errors))) \"@@"( raise, DecodeError( diff --git a/src/vendor/Json_encode.res b/src/vendor/Json_encode.res index 8f85bd662..dc798aa95 100644 --- a/src/vendor/Json_encode.res +++ b/src/vendor/Json_encode.res @@ -6,7 +6,7 @@ external float: float => Js.Json.t = "%identity" external int: int => Js.Json.t = "%identity" external bool: bool => Js.Json.t = "%identity" -let char = c => string(String.make(1, c)) +let char = c => string(OCamlCompat.String.make(1, c)) let date = d => string(Js.Date.toJSONUnsafe(d)) @@ -25,24 +25,24 @@ let withDefault = (d, encode, x) => external jsonDict: Js_dict.t => Js.Json.t = "%identity" let dict = (encode, d) => { let pairs = Js.Dict.entries(d) - let encodedPairs = Array.map(((k, v)) => (k, encode(v)), pairs) + let encodedPairs = pairs->Array.map(((k, v)) => (k, encode(v))) jsonDict(Js.Dict.fromArray(encodedPairs)) } let object_ = (props): Js.Json.t => jsonDict(Js.Dict.fromList(props)) external jsonArray: array => Js.Json.t = "%identity" -let array = (encode, l) => jsonArray(Array.map(x => encode(x), l)) +let array = (encode, l) => jsonArray(l->Array.map(x => encode(x))) let list = (encode, x) => switch x { | list{} => jsonArray([]) | list{hd, ...tl} as l => - let a = Array.make(List.length(l), encode(hd)) + let a = encode(hd)->Array.make(~length=List.length(l)) let rec fill = (i, x) => switch x { | list{} => a | list{hd, ...tl} => - Array.unsafe_set(a, i, encode(hd)) + Array.setUnsafe(a, i, encode(hd)) fill(i + 1, tl) }