You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/array-and-list.mdx
+5-11Lines changed: 5 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ order: 12
10
10
11
11
## Array
12
12
13
-
Arrays are our main ordered data structure. They work the same way as JavaScript arrays: they can be randomly accessed, dynamically resized, updated, etc.
13
+
Arrays are the main ordered data structure in ReScript. They can be randomly accessed, dynamically resized, and updated.
14
14
15
15
<CodeTablabels={["ReScript", "JS Output"]}>
16
16
@@ -82,9 +82,7 @@ myArray[0] = "bye";
82
82
83
83
### Array spreads
84
84
85
-
**Since 11.1**
86
-
87
-
You can spread arrays of the the same type into new arrays, just like in JavaScript:
85
+
You can spread arrays of the same type into new arrays:
88
86
89
87
<CodeTablabels={["ReScript", "JS Output"]}>
90
88
@@ -96,21 +94,17 @@ let x3 = [...y]
96
94
```
97
95
98
96
```javascript
99
-
var Belt_Array =require("rescript/lib/js/belt_Array.js");
100
-
101
97
var y = [1, 2];
102
98
103
-
var x =Belt_Array.concatMany([[4, 5], y]);
99
+
var x =[4, 5, ...y];
104
100
105
-
var x2 =Belt_Array.concatMany([[4, 5], y, [7], y]);
101
+
var x2 =[4, 5, ...y, 7, ...y];
106
102
107
-
var x3 =Belt_Array.concatMany([y]);
103
+
var x3 =[...y];
108
104
```
109
105
110
106
</CodeTab>
111
107
112
-
> Note that array spreads compiles to `Belt.Array.concatMany` right now. This is likely to change to native array spreads in the future.
113
-
114
108
## List
115
109
116
110
ReScript provides a singly linked list too. Lists are:
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/async-await.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ You will probably notice that this looks very similar to `async` / `await` in JS
67
67
-`await` may only be called on a `promise` value
68
68
-`await` calls are expressions, therefore they can be used in pattern matching (`switch`)
69
69
- A function returning a `promise<'a>` is equivalent to an `async` function returning a value `'a` (important for writing signature files and bindings)
70
-
-`promise` values and types returned from an `async` function don't auto-collapse into a "flat promise" like in JS (more on this later)
70
+
-`promise` values and types returned from an `async` function don't auto-collapse into a flat promise. See the details below.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/browser-support-polyfills.mdx
+2-9Lines changed: 2 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,13 +8,6 @@ order: 13
8
8
9
9
# Browser Support & Polyfills
10
10
11
-
ReScript compiles to JavaScript **ES5**, with the exception of optionally allowing to compile to ES6's module import & export.
11
+
ReScript compiles to modern JavaScript (ES6+ by default). The generated output targets contemporary browsers and current versions of Node.js, so polyfills are generally not needed.
12
12
13
-
For [old browsers](https://caniuse.com/#search=typed%20array), you also need to polyfill TypedArray. The following standard library functions require it:
14
-
15
-
-`Int64.float_of_bits`
16
-
-`Int64.bits_of_float`
17
-
-`Int32.float_of_bits`
18
-
-`Int32.bits_of_float`
19
-
20
-
If you don't use these functions, you're fine. Otherwise, it'll be a runtime failure.
13
+
If you need to support very old browsers that lack ES6+ features, use your bundler's transpilation and polyfill capabilities (for example, Babel or SWC via Webpack, Vite, or esbuild) to downlevel the output as needed.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/build-configuration.mdx
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -81,15 +81,17 @@ Here, the file `src/MyMainModule.res` is exposed to outside consumers, while all
81
81
}
82
82
```
83
83
84
-
## bs-dependencies, bs-dev-dependencies
84
+
## dependencies, dev-dependencies
85
85
86
86
List of ReScript dependencies. Just like `package.json`'s dependencies, they'll be searched in `node_modules`.
87
87
88
-
Note that only sources marked with `"type":"dev"` will be able to resolve modules from `bs-dev-dependencies`.
88
+
Note that only sources marked with `"type":"dev"` will be able to resolve modules from `dev-dependencies`.
89
+
90
+
> The legacy keys `bs-dependencies` and `bs-dev-dependencies` are still accepted but deprecated.
89
91
90
92
## external-stdlib
91
93
92
-
**Since 9.0**: This setting allows depending on an externally built stdlib package (instead of a locally built stdlib runtime). Useful for shipping packages that are only consumed in JS or TS without any dependencies to the ReScript development toolchain.
94
+
This setting allows depending on an externally built stdlib package (instead of a locally built stdlib runtime). Useful for shipping packages that are only consumed in JS or TS without any dependencies to the ReScript development toolchain.
93
95
94
96
More details can be found on our [external stdlib](./build-external-stdlib.mdx) page.
95
97
@@ -155,7 +157,7 @@ This configuration only applies to you, when you develop the project. When the p
155
157
156
158
## suffix
157
159
158
-
**Since 11.0**: The suffix can now be freely chosen. However, we still suggest you stick to the convention and use
160
+
The suffix can be freely chosen. However, we still suggest you stick to the convention and use
159
161
one of the following:
160
162
161
163
-`".js`
@@ -190,12 +192,14 @@ Turn off warning `44` and `102` (polymorphic comparison). Turn warning `5` (part
190
192
191
193
The warning numbers are shown in the build output when they're triggered. See [Warning Numbers](./warning-numbers.mdx) for the complete list.
192
194
193
-
## bsc-flags
195
+
## compiler-flags
194
196
195
197
Extra flags to pass to the compiler. For advanced usages.
196
198
197
199
-`-open ABC` opens the module `ABC` for each file in the project. `ABC` can either be a dependency, namespaced project or local module of the current project.
198
200
201
+
> The legacy key `bsc-flags` is still accepted but deprecated.
202
+
199
203
## gentypeconfig
200
204
201
205
To enable genType, set `"gentypeconfig"` at top level in the project's `rescript.json`.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/build-external-stdlib.mdx
+9-15Lines changed: 9 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,34 +9,31 @@ order: 4
9
9
10
10
# External Stdlib
11
11
12
-
**Since 9.0**
13
-
14
-
Your ReScript project depends on the `rescript` package as a [`devDependency`](https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file), which includes our compiler, build system and runtime like `Belt`. However, you had to move it to `dependency` in `package.json` if you publish your code:
12
+
Your ReScript project depends on the `rescript` package as a [`devDependency`](https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file), which includes the compiler, build system, and runtime. However, you may need to move it to `dependency` in `package.json` if you publish your code:
15
13
16
14
- To Docker or other low-storage deployment devices.
17
15
- For pure JS/TS consumers who probably won't install `rescript` in their own project.
18
16
19
-
In these cases, the size or mere presence of `rescript` can be troublesome, since it includes not just our necessary runtime like `Belt`, but also our compiler and build system.
17
+
In these cases, the size or mere presence of `rescript` can be troublesome, since it includes not just the necessary runtime, but also the compiler and build system.
20
18
21
-
To solve that, we now publish our runtime as a standalone package at [`@rescript/std`](https://www.npmjs.com/package/@rescript/std), whose versions mirror `rescript`'s. Now you can keep `rescript` as a `devDependency` and have only `@rescript/std` as your runtime `dependency`.
19
+
To solve that, the runtime is published as a standalone package at [`@rescript/runtime`](https://www.npmjs.com/package/@rescript/runtime), whose versions mirror `rescript`'s. You can keep `rescript` as a `devDependency` and have only `@rescript/runtime` as your runtime `dependency`.
22
20
23
21
**This is an advanced feature**. Please only use it in the aforementioned scenarios. If you already use a JS bundler with dead code elimination, you might not need this feature.
24
22
25
23
## Configuration
26
24
27
-
Say you want to publish a JS-only ReScript 9.0 library. Install the packages like this:
25
+
Say you want to publish a JS-only ReScript library. Install the packages like this:
28
26
29
27
```sh
30
-
npm install rescript@11.0.1 --save-dev
31
-
npm install @rescript/std@11.0.1
28
+
npm install rescript --save-dev
29
+
npm install @rescript/runtime
32
30
```
33
31
34
32
Then add this to `rescript.json`:
35
33
36
34
```json
37
35
{
38
-
// ...
39
-
"external-stdlib": "@rescript/std"
36
+
"external-stdlib": "@rescript/runtime"
40
37
}
41
38
```
42
39
@@ -49,14 +46,11 @@ Array.forEach([1, 2, 3], num => Console.log(num))
49
46
```
50
47
51
48
```js
52
-
// Note the require path starting with "@rescript/std".
53
-
var Belt_Array =require("@rescript/std/lib/js/belt_Array.js");
54
-
55
-
Belt_Array.forEach([1, 2, 3], function (num) {
49
+
[1, 2, 3].forEach(function (num) {
56
50
console.log(num);
57
51
});
58
52
```
59
53
60
54
</CodeTab>
61
55
62
-
**Make sure the version number of `rescript` and `@rescript/std` match in your `package.json`** to avoid running into runtime issues due to mismatching stdlib assumptions.
56
+
**Make sure the version number of `rescript` and `@rescript/runtime` match in your `package.json`** to avoid running into runtime issues due to mismatching stdlib assumptions.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/build-performance.mdx
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,9 +68,7 @@ The watcher is also just a thin file watcher that calls `rescript.exe`. We don't
68
68
69
69
ReScript doesn't take whole seconds to run every time. The bulk of the build performance comes from incremental build, aka re-building a previously built project when a few files changed.
70
70
71
-
In short, thanks to our compiler and the build system's architecture, we're able to **only build what's needed**. E.g. if `MyFile.res` isn't changed, then it's not recompiled. You can roughly emulate such incrementalism in languages like JavaScript, but the degree of correctness is unfortunately low. For example, if you rename or move a JS file, then the watcher might get confused and not pick up the "new" file or fail to clean things up correctly, resulting in you needing to clean your build and restart anew, which defeats the purpose.
72
-
73
-
Say goodbye to stale build from your JavaScript ecosystem!
71
+
In short, thanks to our compiler and the build system's architecture, we're able to **only build what's needed**. If `MyFile.res` isn't changed, it isn't recompiled. The build system ensures complete correctness -- renaming or moving files is handled automatically, with no stale builds.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/control-flow.mdx
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@ order: 14
10
10
11
11
ReScript supports `if`, `else`, ternary expression (`a ? b : c`), `for` and `while`.
12
12
13
-
The `switch` pattern has a default case too, just like many other functional languages. Read more about [pattern-matching & destructuring](./pattern-matching-destructuring.mdx). there.
13
+
The `switch` pattern supports a default case. Read more about [pattern-matching & destructuring](./pattern-matching-destructuring.mdx).
14
14
15
15
## If-Else & Ternary
16
16
17
-
Unlike its JavaScript counterpart, ReScript's `if` is an expression; they evaluate to their body's content:
17
+
ReScript's `if` is an expression; it evaluates to its body's content:
**`if-else` and ternary are much less used** in ReScript than in other languages; [Pattern-matching](./pattern-matching-destructuring.mdx) kills a whole category of code that previously required conditionals.
97
+
`if-else` and ternary are often replaced by [pattern matching](./pattern-matching-destructuring.mdx), which handles a wide range of conditional logic more expressively.
- Ensures minimal disruption to your teammates (very important!).
14
14
- Remove the typical friction of verifying conversion's correctness and performance guarantees.
15
-
- Doesn't force you to search for pre-made binding libraries made by others. **ReScript doesn't need the equivalent of TypeScript's `DefinitelyTyped`**.
15
+
- Doesn't require pre-made binding libraries -- you can write bindings directly for any JavaScript API.
Copy file name to clipboardExpand all lines: markdown-pages/docs/manual/editor-plugins.mdx
+3-4Lines changed: 3 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -40,14 +40,14 @@ The code analysis provides extra checks for your ReScript project, such as detec
40
40
### Configuration
41
41
42
42
Add a `reanalyze` section to your `rescript.json` to control what the analyzer checks or ignores. You'll get autocomplete for config options in the editor.
43
-
More details: [reanalyze config docs](https://github.com/rescript-association/reanalyze#configuration-via-bsconfigjson)
43
+
More details: [reanalyze configuration docs](https://github.com/rescript-association/reanalyze#configuration-via-bsconfigjson)
44
44
45
45
### Exception analysis
46
46
47
47
The exception analysis is designed to keep track statically of the exceptions that might be thrown at runtime. It works by issuing warnings and recognizing annotations. Warnings are issued whenever an exception is thrown and not immediately caught. Annotations are used to push warnings from he local point where the exception is thrown, to the outside context: callers of the current function.
48
48
Nested functions need to be annotated separately.
49
49
50
-
Instructions on how to run the exception analysis using the `-exception` and `-exception-cmt` command-line arguments, or how to add `"analysis": ["exception"]` in `rescript.json` are contained in the [reanalyze config docs](https://github.com/rescript-association/reanalyze#configuration-via-bsconfigjson).
50
+
Instructions on how to run the exception analysis using the `-exception` and `-exception-cmt` command-line arguments, or how to add `"analysis": ["exception"]` in `rescript.json` are contained in the [reanalyze configuration docs](https://github.com/rescript-association/reanalyze#configuration-via-bsconfigjson).
51
51
52
52
Here's an example, where the analysis reports a warning any time an exception is thrown, and not caught:
53
53
@@ -142,12 +142,11 @@ There is a way to enhance this behavior via configuration, described further dow
142
142
143
143
### Dot completion enhancements
144
144
145
-
In ReScript, using a dot (`.`) normally means "access record field". But, because using `.` to trigger completions is so pervasive in for example JavaScript, we extend `.` to trigger completions in more scenarios than just for record field access.
145
+
In ReScript, using a dot (`.`) normally means "access record field". The editor extends dot (`.`) to trigger completions in more scenarios beyond record field access, providing a more natural completion flow.
146
146
147
147
This behavior has the following important implications:
148
148
149
149
- Improves discoverability (E.g. using a `.` will reveal important pipe completions)
150
-
- Enables a more natural completion flow for people used to JavaScript, where dots power more completions naturally
151
150
152
151
Below is a list of all the scenarios where using dots trigger completion in addition to the normal record field completion.
0 commit comments