Skip to content

Open ReScript Core by default #871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
],
"uncurried": true,
"ppx-flags": [],
"bsc-flags": [],
"bsc-flags": [
"-open RescriptCore"
],
"sources": [
{
"dir": "src",
Expand Down
1 change: 0 additions & 1 deletion src/Blog.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

module Link = Next.Link
open RescriptCore

let defaultPreviewImg = "/static/Art-3-rescript-launch.jpg"

Expand Down
1 change: 0 additions & 1 deletion src/BlogArticle.res
Original file line number Diff line number Diff line change
Expand Up @@ -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) ++ " ")

Expand Down
2 changes: 1 addition & 1 deletion src/Design.res
Original file line number Diff line number Diff line change
@@ -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="") => {
Expand Down
1 change: 0 additions & 1 deletion src/DocsOverview.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open RescriptCore
module Card = {
@react.component
let make = (~title: string, ~hrefs: array<(string, string)>) => {
Expand Down
16 changes: 8 additions & 8 deletions src/SyntaxLookup.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/bindings/RescriptCompilerApi.res
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/common/Ansi.res
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
16 changes: 8 additions & 8 deletions src/common/BlogApi.res
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand All @@ -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 = () => {
Expand All @@ -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 = {
Expand Down Expand Up @@ -156,7 +156,7 @@ module RssFeed = {
let getLatest = (~max=10, ~baseUrl="https://rescript-lang.org", ()): array<item> => {
let items =
getAllPosts()
->Js.Array2.map(post => {
->Array.map(post => {
let fm = post.frontmatter
let description = Js.Null.toOption(fm.description)->Belt.Option.getWithDefault("")
{
Expand All @@ -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
}

Expand Down
5 changes: 3 additions & 2 deletions src/common/Url.res
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/components/AnsiPre.res
Original file line number Diff line number Diff line change
@@ -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
Expand Down
28 changes: 14 additions & 14 deletions src/vendor/Json_decode.res
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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<Js.Json.t> = 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 {
Expand All @@ -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"))
}
Expand All @@ -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"))
}
Expand All @@ -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"))
}
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 5 additions & 5 deletions src/vendor/Json_encode.res
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -25,24 +25,24 @@ let withDefault = (d, encode, x) =>
external jsonDict: Js_dict.t<Js.Json.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> => 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)
}

Expand Down