Skip to content

Commit 69266b6

Browse files
Merge branch 'master' into rescript-assoication-stuff
2 parents 4f0f00b + f17e7ea commit 69266b6

Some content is hidden

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

65 files changed

+1165
-2389
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*.res linguist-language=ReScript
22
*.resi linguist-language=ReScript
3+
4+
/public/playground-bundles/** binary linguist-vendored

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public/blog/feed.xml
77

88
node_modules/
99
.next/
10+
out/
1011
index_data/*.json
1112

1213
# Generated via test examples script
@@ -26,9 +27,13 @@ lib/
2627
.vercel
2728

2829
src/**/*.mjs
29-
scripts/**/*.mjs
30+
scripts/gendocs.mjs
31+
scripts/generate_*.mjs
3032

3133
# Generated via generate-llms script
3234
public/llms/manual/**/llm*.txt
3335
public/llms/react/**/llm*.txt
3436
pages/docs/**/**/llms.mdx
37+
38+
public/playground-bundles/
39+
public/_redirects

.nowignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
2-
3-
<a href="https://simpleanalytics.com/rescript-lang.org?utm_source=rescript-lang.org&utm_content=badge" referrerpolicy="origin" target="_blank"><img src="https://simpleanalyticsbadge.com/rescript-lang.org?counter=true" loading="lazy" referrerpolicy="no-referrer" crossorigin="anonymous" /></a>
4-
51
# rescript-lang.org
2+
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v1.4%20adopted-ff69b4.svg)](CODE_OF_CONDUCT.md)
63

74
This is the official documentation platform for the [ReScript](https://rescript-lang.org) programming language.
85

data/sidebar_manual_v1200.json

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,30 @@
22
"Overview": [
33
"introduction",
44
"installation",
5-
"migrate-to-v11",
65
"editor-plugins",
7-
"try"
6+
"llms"
7+
],
8+
"Guides": [
9+
"converting-from-js",
10+
"editor-code-analysis",
11+
"project-structure"
12+
],
13+
"JavaScript Interop": [
14+
"interop-cheatsheet",
15+
"embed-raw-javascript",
16+
"shared-data-types",
17+
"external",
18+
"bind-to-js-object",
19+
"bind-to-js-function",
20+
"import-from-export-to-js",
21+
"bind-to-global-js-values",
22+
"json",
23+
"inlining-constants",
24+
"use-illegal-identifier-names",
25+
"generate-converters-accessors",
26+
"browser-support-polyfills",
27+
"libraries",
28+
"typescript-integration"
829
],
930
"Language Features": [
1031
"overview",
@@ -14,6 +35,7 @@
1435
"tuple",
1536
"record",
1637
"object",
38+
"dict",
1739
"variant",
1840
"polymorphic-variant",
1941
"null-undefined-option",
@@ -35,27 +57,6 @@
3557
"reserved-keywords",
3658
"equality-comparison"
3759
],
38-
"Advanced Features": [
39-
"extensible-variant",
40-
"scoped-polymorphic-types"
41-
],
42-
"JavaScript Interop": [
43-
"interop-cheatsheet",
44-
"embed-raw-javascript",
45-
"shared-data-types",
46-
"external",
47-
"bind-to-js-object",
48-
"bind-to-js-function",
49-
"import-from-export-to-js",
50-
"bind-to-global-js-values",
51-
"json",
52-
"inlining-constants",
53-
"use-illegal-identifier-names",
54-
"generate-converters-accessors",
55-
"browser-support-polyfills",
56-
"libraries",
57-
"typescript-integration"
58-
],
5960
"Build System": [
6061
"build-overview",
6162
"build-configuration",
@@ -66,14 +67,8 @@
6667
"build-performance",
6768
"warning-numbers"
6869
],
69-
"Guides": [
70-
"converting-from-js",
71-
"editor-code-analysis"
72-
],
73-
"Extra": [
74-
"newcomer-examples",
75-
"project-structure",
76-
"faq",
77-
"llms"
70+
"Advanced Features": [
71+
"extensible-variant",
72+
"scoped-polymorphic-types"
7873
]
7974
}

misc_docs/syntax/decorator_as.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,28 @@ let somethingElse = null;
8282

8383
Read more about the [`@as` decorator and variants](variant.md#valid-as-payloads).
8484

85+
## Adding fixed argument values to external functions
86+
You can leverage the `@as` decorator to add fixed values for external function arguments. You then do not need to supply a value for that argument.
87+
88+
<CodeTab labels={["ReScript", "JS Output"]}>
89+
90+
```res
91+
@module("fs")
92+
external readFileSyncUtf8: (string, @as(json`{encoding: "utf8"}`) _) => string = "readFileSync"
93+
94+
let contents = readFileSyncUtf8("./someFile.txt")
95+
```
96+
97+
```js
98+
import * as Fs from "fs";
99+
100+
let contents = Fs.readFileSync("./someFile.txt", {encoding: "utf8"});
101+
```
102+
103+
</CodeTab>
104+
105+
Read more about [fixed arguments in functions](bind-to-js-function.md#fixed-arguments).
106+
85107
### References
86108

87109
* [Bind Using ReScript Record](/docs/manual/latest/bind-to-js-object#bind-using-rescript-record)

misc_docs/syntax/extension_regular_expression.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ summary: "This is the `regular expression` extension point."
66
category: "extensionpoints"
77
---
88

9+
> Deprecated in favor of native regular expression syntax in v12+
10+
911
`%re` is used to create JavaScript regular expressions.
1012

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

misc_docs/syntax/language_dict.mdx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
id: "dict"
3+
keywords: ["dict"]
4+
name: "dict"
5+
summary: "This is the `dict{}` syntax"
6+
category: "languageconstructs"
7+
---
8+
9+
> Available in v12+
10+
11+
The `dict{}` syntax is used to represent [dictionaries](dict.md). It's used both when creating dicts, and when pattern matching on dicts.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
// Create a dict
19+
let d = dict{"A": 5, "B": 6, "C": 7}
20+
21+
// Pattern match on the full dict
22+
let b = switch d {
23+
| dict{"B": b} => Some(b)
24+
| _ => None
25+
}
26+
27+
// Destructure the dict
28+
let dict{"C": ?c} = d
29+
```
30+
31+
```js
32+
let d = {
33+
A: 5,
34+
B: 6,
35+
C: 7
36+
};
37+
38+
let b = d.B;
39+
40+
let b$1 = b !== undefined ? b : undefined;
41+
42+
let c = d.C;
43+
```
44+
45+
</CodeTab>
46+
47+
### References
48+
49+
* [Dictionaries](/docs/manual/latest/dict)
50+
51+

misc_docs/syntax/language_for.mdx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
id: "for"
3+
keywords: ["for", "loop"]
4+
name: "for loop"
5+
summary: "This is the `for` loop."
6+
category: "languageconstructs"
7+
---
8+
9+
ReScript supports `for` loops.
10+
11+
For loops can iterate from a starting value up to (and including) the ending value via the `to` keyword, or in the opposite direction via the `downto` keyword.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
// Using `to`
19+
for x in 1 to 3 {
20+
Console.log(x)
21+
}
22+
23+
// Using `downto`
24+
for y in 3 downto 1 {
25+
Console.log(y)
26+
}
27+
```
28+
29+
```js
30+
for(var x = 1; x <= 3; ++x){
31+
console.log(x);
32+
}
33+
34+
for(var y = 3; y >= 1; --y){
35+
console.log(y);
36+
}
37+
```
38+
39+
</CodeTab>
40+
41+
42+
### References
43+
44+
* [For Loops](control-flow.md#for-loops)
45+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
id: "regular-expression-syntax"
3+
keywords: ["regular", "expression", "regex"]
4+
name: "/re/"
5+
summary: "This is the `regular expression` syntax."
6+
category: "languageconstructs"
7+
---
8+
9+
> Available in v12+
10+
11+
You write regular expressions in ReScript just like you do in JavaScript.
12+
13+
<CodeTab labels={["ReScript", "JS Output"]}>
14+
15+
```res
16+
let regex = /^hello/
17+
let result = regex->RegExp.test("hello world")
18+
```
19+
20+
```js
21+
let regex = /^hello/;
22+
23+
let result = regex.test("hello world");
24+
```
25+
26+
</CodeTab>
27+
28+
### References
29+
30+
* [Regular Expressions](/docs/manual/latest/primitive-types#regular-expression)
31+
* [RegExp API](/docs/manual/latest/api/core/regexp)

misc_docs/syntax/language_while.mdx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
id: "while"
3+
keywords: ["while", "loop"]
4+
name: "while loop"
5+
summary: "This is the `while` loop."
6+
category: "languageconstructs"
7+
---
8+
9+
ReScript supports `while` loops. While loops execute its body code block while its condition is true.
10+
11+
ReScript does not have the `break` keyword, but you can easily break out of a while loop by using a mutable binding.
12+
13+
### Example
14+
15+
<CodeTab labels={["ReScript", "JS Output"]}>
16+
17+
```res
18+
let break = ref(false)
19+
20+
while !break.contents {
21+
if Math.random() > 0.3 {
22+
break := true
23+
} else {
24+
Console.log("Still running")
25+
}
26+
}
27+
28+
```
29+
30+
```js
31+
let $$break = {
32+
contents: false
33+
};
34+
35+
while (!$$break.contents) {
36+
if (Math.random() > 0.3) {
37+
$$break.contents = true;
38+
} else {
39+
console.log("Still running");
40+
}
41+
};
42+
```
43+
44+
</CodeTab>
45+
46+
47+
### References
48+
49+
* [While Loops](control-flow.md#while-loops)
50+

0 commit comments

Comments
 (0)