Skip to content

Commit 838aabe

Browse files
committed
Merge branch 'master' into docgen-compiler
2 parents a5b8b8b + d5906ae commit 838aabe

Some content is hidden

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

47 files changed

+519
-281
lines changed

compilers/package-lock.json

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compilers/package.json

Lines changed: 5 additions & 5 deletions
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.5.0",
9-
"rescript-820": "npm:bs-platform@8.2.0",
10-
"rescript-902": "npm:bs-platform@9.0.2",
11-
"rescript-912": "npm:rescript@9.1.2",
8+
"@rescript/core": "^0.6.0",
129
"rescript-1000": "npm:rescript@10.0.0",
1310
"rescript-1010": "npm:rescript@10.1.0-rc.4",
14-
"rescript-1100": "npm:rescript@11.0.0-rc.4"
11+
"rescript-1100": "npm:rescript@11.0.0-rc.8",
12+
"rescript-820": "npm:bs-platform@8.2.0",
13+
"rescript-902": "npm:bs-platform@9.0.2",
14+
"rescript-912": "npm:rescript@9.1.2"
1515
}
1616
}

data/sidebar_manual_latest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Overview": [
33
"introduction",
44
"installation",
5-
"migrate-to-v11-and-uncurried-mode",
5+
"migrate-to-v11",
66
"editor-plugins",
77
"try"
88
],

data/sidebar_react_latest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"refs-and-the-dom",
1313
"context",
1414
"styling",
15-
"router"
15+
"router",
16+
"lazy-components"
1617
],
1718
"Hooks & State Management": [
1819
"hooks-overview",

misc_docs/syntax/operators_type_coercion.mdx

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ category: "operators"
88

99
The `:>` operator may be used to convert a polymorphic variant to a `string` or `int`, or convert an [object](/docs/manual/latest/object) to a type with a subset of its fields.
1010

11+
_Since ReScript `11.0.0`_ coercion also works for converting
12+
- from `int` to `float`
13+
- from record to record with the same field(s) or when record A is a subtype of record B
14+
- from `@unboxed` variant with only strings to `string`
15+
- from `string` to `@unboxed` variant that have a catch-all unboxed `string` case
16+
- from variant to variant when applicable
17+
- from variant to `string`/`int`/`float` when applicable
18+
- for invariant type arguments such as array payloads when the runtime representation is guaranteed to be exactly the same
19+
1120
### Example 1
1221

1322
<CodeTab labels={["ReScript", "JS Output"]}>
1423

15-
```res
24+
```res example
1625
type color = [#Red | #Green | #Blue]
1726
let color: color = #Red
1827
let message = "The color is " ++ (color :> string)
@@ -28,7 +37,7 @@ var message = "The color is Red";
2837

2938
<CodeTab labels={["ReScript", "JS Output"]}>
3039

31-
```res
40+
```res example
3241
type bit = [#0 | #1]
3342
let bit: bit = #1
3443
let value = (bit :> int)
@@ -45,7 +54,7 @@ var value = 1;
4554

4655
<CodeTab labels={["ReScript", "JS Output"]}>
4756

48-
```res
57+
```res example
4958
type person = {"id": int, "name": string}
5059
type name = {"name": string}
5160
let person = {"id": 10, "name": "Gideon"}
@@ -63,7 +72,56 @@ var name = person;
6372

6473
</CodeTab>
6574

75+
### Example 4
76+
77+
<CodeTab labels={["ReScript", "JS Output"]}>
78+
79+
```res example
80+
@unboxed
81+
type myNumberType = One | Two | Other(string)
82+
83+
let v = Other("Infinite")
84+
let v2 = One
85+
86+
let x = "NaN"
87+
88+
// variant to string
89+
Console.log((v :> string))
90+
Console.log((v2 :> string))
91+
92+
// string to variant
93+
let y = (x :> myNumberType)
94+
95+
let f = switch y {
96+
| One => "One"
97+
| _ => "Two"
98+
}
99+
```
100+
101+
```js
102+
var v = "Infinite";
103+
104+
var x = "NaN";
105+
106+
console.log(v);
107+
108+
console.log("One");
109+
110+
var f;
111+
112+
f = (x === "One" || x === "Two") && x === "One" ? "One" : "Two";
113+
114+
var v2 = "One";
115+
116+
var y = x;
117+
```
118+
119+
</CodeTab>
120+
66121

67122
### References
68123

124+
* [Int-to-Float Coercion](/docs/manual/latest/primitive-types#int-to-float-coercion)
125+
* [Variant Coercion](/docs/manual/latest/variant#coercion)
69126
* [Polymorphic Variant Coercion](/docs/manual/latest/polymorphic-variant#coercion)
127+
* [Record Type Coercion](/docs/manual/latest/record#record-type-coercion)

pages/docs/manual/latest/array-and-list.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ ReScript arrays' items must have the same type, i.e. homogeneous.
2525

2626
### Usage
2727

28-
See the [Js.Array](api/js/array) API.
29-
3028
Access & update an array item like so:
3129

3230
<CodeTab labels={["ReScript", "JS Output"]}>
@@ -38,7 +36,7 @@ let firstItem = myArray[0] // "hello"
3836
3937
myArray[0] = "hey" // now ["hey", "world", "how are you"]
4038
41-
let pushedValue = Js.Array2.push(myArray, "bye")
39+
myArray->Array.push("bye")
4240
```
4341
```js
4442
var myArray = ["hello", "world", "how are you"];

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let logUserDetails = async (userId: string) => {
3939
4040
await sendAnalytics(`User details have been logged for ${userId}`)
4141
42-
Js.log(`Email address for user ${userId}: ${email}`)
42+
Console.log(`Email address for user ${userId}: ${email}`)
4343
}
4444
```
4545

@@ -139,8 +139,8 @@ let checkAuth = async () => {
139139
} catch {
140140
| Js.Exn.Error(e) =>
141141
switch Js.Exn.message(e) {
142-
| Some(msg) => Js.log("JS error thrown: " ++ msg)
143-
| None => Js.log("Some other exception has been thrown")
142+
| Some(msg) => Console.log("JS error thrown: " ++ msg)
143+
| None => Console.log("Some other exception has been thrown")
144144
}
145145
}
146146
}
@@ -157,11 +157,11 @@ let authenticate = async () => {
157157
158158
let checkAuth = async () => {
159159
switch await authenticate() {
160-
| _ => Js.log("ok")
160+
| _ => Console.log("ok")
161161
| exception Js.Exn.Error(e) =>
162162
switch Js.Exn.message(e) {
163-
| Some(msg) => Js.log("JS error thrown: " ++ msg)
164-
| None => Js.log("Some other exception has been thrown")
163+
| Some(msg) => Console.log("JS error thrown: " ++ msg)
164+
| None => Console.log("Some other exception has been thrown")
165165
}
166166
}
167167
}
@@ -180,8 +180,8 @@ This can be done by wrapping your `await` calls in a new `{}` closure.
180180
@val external fetchUserMail: string => promise<string> = "GlobalAPI.fetchUserMail"
181181
182182
let fetchData = async () => {
183-
let mail = {await fetchUserMail("1234")}->Js.String2.toUpperCase
184-
Js.log(`All upper-cased mail: ${mail}`)
183+
let mail = {await fetchUserMail("1234")}->String.toUpperCase
184+
Console.log(`All upper-cased mail: ${mail}`)
185185
}
186186
```
187187

@@ -208,11 +208,11 @@ Note how the original closure was removed in the final JS output. No extra alloc
208208
let fetchData = async () => {
209209
switch (await fetchUserMail("user1"), await fetchUserMail("user2")) {
210210
| (user1Mail, user2Mail) => {
211-
Js.log("user 1 mail: " ++ user1Mail)
212-
Js.log("user 2 mail: " ++ user2Mail)
211+
Console.log("user 1 mail: " ++ user1Mail)
212+
Console.log("user 2 mail: " ++ user2Mail)
213213
}
214214
215-
| exception JsError(err) => Js.log2("Some error occurred", err)
215+
| exception JsError(err) => Console.log2("Some error occurred", err)
216216
}
217217
}
218218
```
@@ -242,13 +242,13 @@ async function fetchData(param) {
242242

243243
## `await` multiple promises
244244

245-
We can utilize the `Js.Promise2` module to handle multiple promises. E.g. let's use `Js.Promise2.all` to wait for multiple promises before continuing the program:
245+
We can utilize the `Promise` module to handle multiple promises. E.g. let's use `Promise.all` to wait for multiple promises before continuing the program:
246246

247247
```res
248248
let pauseReturn = (value, timeout) => {
249-
Js.Promise2.make((~resolve, ~reject) => {
249+
Promise.make((resolve, _reject) => {
250250
Js.Global.setTimeout(() => {
251-
resolve(. value)
251+
resolve(value)
252252
}, timeout)->ignore
253253
})
254254
}
@@ -258,11 +258,11 @@ let logMultipleValues = async () => {
258258
let promise2 = pauseReturn("value2", 1200)
259259
let promise3 = pauseReturn("value3", 500)
260260
261-
let all = await Js.Promise2.all([promise1, promise2, promise3])
261+
let all = await Promise.all([promise1, promise2, promise3])
262262
263263
switch all {
264-
| [v1, v2, v3] => Js.log(`All values: ${v1}, ${v2}, ${v3}`)
265-
| _ => Js.log("this should never happen")
264+
| [v1, v2, v3] => Console.log(`All values: ${v1}, ${v2}, ${v3}`)
265+
| _ => Console.log("this should never happen")
266266
}
267267
}
268268
```

pages/docs/manual/latest/bind-to-global-js-values.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type timerId
4343
@val external setTimeout: (unit => unit, int) => timerId = "setTimeout"
4444
@val external clearTimeout: timerId => unit = "clearTimeout"
4545
46-
let id = setTimeout(() => Js.log("hello"), 100)
46+
let id = setTimeout(() => Console.log("hello"), 100)
4747
clearTimeout(id)
4848
```
4949
```js
@@ -102,8 +102,8 @@ For these troublesome global values, ReScript provides a special approach: `%ext
102102

103103
```res example
104104
switch %external(__DEV__) {
105-
| Some(_) => Js.log("dev mode")
106-
| None => Js.log("production mode")
105+
| Some(_) => Console.log("dev mode")
106+
| None => Console.log("production mode")
107107
}
108108
```
109109
```js
@@ -126,8 +126,8 @@ Another example:
126126

127127
```res example
128128
switch %external(__filename) {
129-
| Some(f) => Js.log(f)
130-
| None => Js.log("non-node environment")
129+
| Some(f) => Console.log(f)
130+
| None => Console.log("non-node environment")
131131
};
132132
```
133133
```js

pages/docs/manual/latest/bind-to-js-function.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ external on: (
283283
let register = rl =>
284284
rl
285285
->on(#close(event => ()))
286-
->on(#line(line => Js.log(line)));
286+
->on(#line(line => Console.log(line)));
287287
```
288288
```js
289289
function register(rl) {
@@ -313,7 +313,7 @@ external processOnExit: (
313313
) => unit = "process.on"
314314
315315
processOnExit(exitCode =>
316-
Js.log("error code: " ++ Js.Int.toString(exitCode))
316+
Console.log("error code: " ++ Js.Int.toString(exitCode))
317317
);
318318
```
319319
```js
@@ -365,7 +365,7 @@ type x
365365
@val external x: x = "x"
366366
@set external setOnload: (x, @this ((x, int) => unit)) => unit = "onload"
367367
@get external resp: x => int = "response"
368-
setOnload(x, @this (o, v) => Js.log(resp(o) + v))
368+
setOnload(x, @this (o, v) => Console.log(resp(o) + v))
369369
```
370370
```js
371371
x.onload = function (v) {

pages/docs/manual/latest/bind-to-js-object.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ type t
143143
144144
let i32arr = create(3)
145145
i32arr->set(0, 42)
146-
Js.log(i32arr->get(0))
146+
Console.log(i32arr->get(0))
147147
```
148148
```js
149149
var i32arr = new Int32Array(3);

0 commit comments

Comments
 (0)