Skip to content

Commit 5d27e1c

Browse files
authored
Migrate to Core (#876)
* Migrate to Core * update compiler version from tests * fix tests * update README.md * adios Js.Exn * requested changes * use Nullable.forEach * package.json, update `engines` to v20
1 parent 0035ddb commit 5d27e1c

File tree

87 files changed

+970
-1049
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+970
-1049
lines changed

README.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ This is the official documentation platform for the [ReScript](https://rescript-
1616

1717
## System Requirements
1818

19-
- `node@18` or higher
19+
- `node@20` or higher
2020
- `npm@10` or higher
2121

2222
## Setup
@@ -28,10 +28,7 @@ npm i
2828
# Initial build
2929
npx rescript
3030

31-
# Only needed for initial clone (or content H2 changes)
32-
npm run update-index
33-
34-
# Build the index data
31+
# Build the index data. Only needed for initial clone (or content H2 changes)
3532
npm run update-index
3633

3734
# In a new tab

compilers/package-lock.json

+24-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compilers/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"main": "index.js",
66
"license": "MIT",
77
"dependencies": {
8-
"@rescript/core": "^0.6.0",
8+
"@rescript/core": "^1.3.0",
99
"@rescript/react": "^0.12.0",
1010
"rescript-1000": "npm:rescript@10.0.0",
1111
"rescript-1010": "npm:rescript@10.1.0",
1212
"rescript-1100": "npm:rescript@11.0.0",
13-
"rescript-1110": "npm:rescript@11.1.0-rc.8",
13+
"rescript-1110": "npm:rescript@11.1.0",
1414
"rescript-820": "npm:bs-platform@8.2.0",
1515
"rescript-902": "npm:bs-platform@9.0.2",
1616
"rescript-912": "npm:rescript@9.1.2"

misc_docs/syntax/decorator_module.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var root = Path.dirname("/User/github");
3636
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
3737
```rescript
3838
@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
39-
external myJson: Js.Json.t = "default"
39+
external myJson: JSON.t = "default"
4040
4141
Console.log(myJson)
4242
```

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Patrick Ecker <ryyppy@users.noreply.github.com>",
66
"license": "MIT",
77
"engines": {
8-
"node": ">=18"
8+
"node": ">=20"
99
},
1010
"type": "module",
1111
"postcss": {

pages/docs/manual/latest/async-await.mdx

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,15 @@ You may use `try / catch` or `switch` to handle exceptions during async executio
130130
```res
131131
// For simulation purposes
132132
let authenticate = async () => {
133-
raise(Js.Exn.raiseRangeError("Authentication failed."))
133+
raise(Exn.raiseRangeError("Authentication failed."))
134134
}
135135
136136
let checkAuth = async () => {
137137
try {
138138
await authenticate()
139139
} catch {
140-
| Js.Exn.Error(e) =>
141-
switch Js.Exn.message(e) {
140+
| Exn.Error(e) =>
141+
switch Exn.message(e) {
142142
| Some(msg) => Console.log("JS error thrown: " ++ msg)
143143
| None => Console.log("Some other exception has been thrown")
144144
}
@@ -152,14 +152,14 @@ You may unify error and value handling in a single switch as well:
152152

153153
```res
154154
let authenticate = async () => {
155-
raise(Js.Exn.raiseRangeError("Authentication failed."))
155+
raise(Exn.raiseRangeError("Authentication failed."))
156156
}
157157
158158
let checkAuth = async () => {
159159
switch await authenticate() {
160160
| _ => Console.log("ok")
161-
| exception Js.Exn.Error(e) =>
162-
switch Js.Exn.message(e) {
161+
| exception Exn.Error(e) =>
162+
switch Exn.message(e) {
163163
| Some(msg) => Console.log("JS error thrown: " ++ msg)
164164
| None => Console.log("Some other exception has been thrown")
165165
}

pages/docs/manual/latest/exception.mdx

+7-7
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ throw {
134134

135135
## Catching JS Exceptions
136136

137-
To distinguish between JavaScript exceptions and ReScript exceptions, ReScript namespaces JS exceptions under the `Js.Exn.Error(payload)` variant. To catch an exception thrown from the JS side:
137+
To distinguish between JavaScript exceptions and ReScript exceptions, ReScript namespaces JS exceptions under the `Exn.Error(payload)` variant. To catch an exception thrown from the JS side:
138138

139139

140140
Throw an exception from JS:
@@ -158,25 +158,25 @@ try {
158158
// call the external method
159159
someJSFunctionThatThrows()
160160
} catch {
161-
| Js.Exn.Error(obj) =>
162-
switch Js.Exn.message(obj) {
161+
| Exn.Error(obj) =>
162+
switch Exn.message(obj) {
163163
| Some(m) => Console.log("Caught a JS exception! Message: " ++ m)
164164
| None => ()
165165
}
166166
}
167167
```
168168

169-
The `obj` here is of type `Js.Exn.t`, intentionally opaque to disallow illegal operations. To operate on `obj`, do like the code above by using the standard library's [`Js.Exn`](api/js/exn) module's helpers.
169+
The `obj` here is of type `Exn.t`, intentionally opaque to disallow illegal operations. To operate on `obj`, do like the code above by using the standard library's [`Exn`](api/js/exn) module's helpers.
170170

171171
## Raise a JS Exception
172172

173-
`raise(MyException)` raises a ReScript exception. To raise a JavaScript exception (whatever your purpose is), use `Js.Exn.raiseError`:
173+
`raise(MyException)` raises a ReScript exception. To raise a JavaScript exception (whatever your purpose is), use `Exn.raiseError`:
174174

175175
<CodeTab labels={["ReScript", "JS Output"]}>
176176

177177
```res example
178178
let myTest = () => {
179-
Js.Exn.raiseError("Hello!")
179+
Exn.raiseError("Hello!")
180180
}
181181
```
182182
```js
@@ -257,7 +257,7 @@ try {
257257
} catch {
258258
| Not_found => ... // catch a ReScript exception
259259
| Invalid_argument(_) => ... // catch a second ReScript exception
260-
| Js.Exn.Error(obj) => ... // catch the JS exception
260+
| Exn.Error(obj) => ... // catch the JS exception
261261
}
262262
```
263263

pages/docs/manual/latest/import-from-export-to-js.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var studentName = Student;
102102
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
103103
```rescript
104104
@module({from: "./myJson.json", with: {type_: "json", \"some-exotic-identifier": "someValue"}})
105-
external myJson: Js.Json.t = "default"
105+
external myJson: JSON.t = "default"
106106
107107
Console.log(myJson)
108108
```
@@ -130,7 +130,7 @@ Also notice `type_`. Since `type` is a reserved keyword in ReScript, you can use
130130
Leveraging JavaScript's [dynamic `import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) to reduce bundle size and lazy load code as needed is easy in ReScript. It's also a little bit more convenient than in regular JavaScript because you don't need to keep track of file paths manually with ReScript's module system.
131131

132132
### Dynamically Importing Parts of a Module
133-
Use the `Js.import` function to dynamically import a specific part of a module. Put whatever `let` binding you want to import in there, and you'll get a `promise` back resolving to that specific binding.
133+
Use the `import` function to dynamically import a specific part of a module. Put whatever `let` binding you want to import in there, and you'll get a `promise` back resolving to that specific binding.
134134

135135
Let's look at an example. Imagine the following file `MathUtils.res`:
136136

@@ -145,7 +145,7 @@ Now let's dynamically import the add function in another module, e.g. `App.res`:
145145
```rescript
146146
// App.res
147147
let main = async () => {
148-
let add = await Js.import(MathUtils.add)
148+
let add = await import(MathUtils.add)
149149
let onePlusOne = add(1, 1)
150150
151151
Console.log(onePlusOne)
@@ -164,7 +164,7 @@ async function main() {
164164
</CodeTab>
165165

166166
### Dynamically Importing an Entire Module
167-
The syntax for importing a whole module looks a little different, since we are operating on the module syntax level; instead of using `Js.import`, you may simply `await` the module itself:
167+
The syntax for importing a whole module looks a little different, since we are operating on the module syntax level; instead of using `import`, you may simply `await` the module itself:
168168
<CodeTab labels={["ReScript", "JS Output (Module)"]}>
169169
```rescript
170170
// App.res

pages/docs/manual/latest/primitive-types.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ As `bigint` is a different data type than `int`, it's necessary to open the corr
180180
<CodeTab labels={["ReScript", "JS Output"]}>
181181

182182
```res example
183-
open! Js.BigInt
183+
open! BigInt
184184
185185
let a = 9007199254740991n + 9007199254740991n
186186
let b = 2n ** 2n
@@ -198,7 +198,7 @@ It also supports all the bitwise operations, except unsigned shift right (`>>>`)
198198
<CodeTab labels={["ReScript", "JS Output"]}>
199199

200200
```res example
201-
open! Js.BigInt
201+
open! BigInt
202202
203203
let a = land(1n, 1n)
204204
let b = lor(1n, 1n)

pages/docs/react/latest/beyond-jsx.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ type props<'className, 'children, 'ref> = {
9999
100100
let make = (
101101
{?className, children, _}: props<'className, 'children, ReactRef.currentDomRef>,
102-
ref: Js.Nullable.t<ReactRef.currentDomRef>,
102+
ref: Nullable.t<ReactRef.currentDomRef>,
103103
) =>
104104
make(~className, ~children, ~ref, ())
105105
```

pages/docs/react/latest/forwarding-refs.mdx

+5-7
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ module FancyInput = {
5656
5757
@react.component
5858
let make = () => {
59-
let input = React.useRef(Js.Nullable.null)
59+
let input = React.useRef(Nullable.null)
6060
6161
let focusInput = () =>
62-
input.current
63-
->Js.Nullable.toOption
64-
->Belt.Option.forEach(input => input->focus)
62+
input.current->Nullable.forEach(input => input->focus)
6563
6664
let onClick = _ => focusInput()
6765
@@ -96,7 +94,7 @@ module FancyInput = {
9694
<input
9795
type_="text"
9896
?className
99-
ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}
97+
ref=?{Nullable.toOption(ref)->Option.map(ReactDOM.Ref.domRef)}
10098
/>
10199
children
102100
</div>
@@ -107,10 +105,10 @@ module FancyInput = {
107105
108106
@react.component
109107
let make = () => {
110-
let input = React.useRef(Js.Nullable.null)
108+
let input = React.useRef(Nullable.null)
111109
112110
let focusInput = () =>
113-
input.current->Js.Nullable.toOption->Belt.Option.forEach(input => input->focus)
111+
input.current->Nullable.forEach(input => input->focus)
114112
115113
let onClick = _ => focusInput()
116114

pages/docs/react/latest/hooks-reducer.mdx

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ type state = {
125125
let reducer = (state, action) =>
126126
switch action {
127127
| AddTodo(content) =>
128-
let todos = Js.Array2.concat(
128+
let todos = Array.concat(
129129
state.todos,
130130
[{id: state.nextId, content: content, completed: false}],
131131
)
132132
{todos: todos, nextId: state.nextId + 1}
133133
| RemoveTodo(id) =>
134-
let todos = Js.Array2.filter(state.todos, todo => todo.id !== id)
134+
let todos = Array.filter(state.todos, todo => todo.id !== id)
135135
{...state, todos: todos}
136136
| ToggleTodo(id) =>
137137
let todos = Belt.Array.map(state.todos, todo =>

0 commit comments

Comments
 (0)