Skip to content

Commit 105b8ed

Browse files
authored
docs: add page for rescript for javascript developers (#1251)
* docs: add page for rescript for javascript developers * change order * Change ** to * * try and fix ordering * fix ordering * fix build * make sure LLMs come last
1 parent 3b0d4b6 commit 105b8ed

8 files changed

Lines changed: 71 additions & 5 deletions

File tree

markdown-pages/docs/manual/converting-from-js.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ order: 1
88

99
# Converting from JS
1010

11+
If you want a quick syntax guide before starting a migration, see [ReScript for JavaScript Developers](./rescript-for-javascript-developers.mdx).
12+
1113
ReScript offers a unique project conversion methodology which:
1214

1315
- Ensures minimal disruption to your teammates (very important!).

markdown-pages/docs/manual/editor-plugins.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ metaTitle: "Editor"
44
description: "Documentation about ReScript editor plugins and code analysis"
55
canonical: "/docs/manual/editor-plugins"
66
section: "Overview"
7-
order: 3
7+
order: 4
88
---
99

1010
# Editor

markdown-pages/docs/manual/introduction.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ ReScript compiles to clean, readable, and performant JavaScript, directly runnab
1616

1717
Your existing knowledge of web development transfers to ReScript projects.
1818

19+
If you are coming from JavaScript, start with [ReScript for JavaScript Developers](./rescript-for-javascript-developers.mdx) for a quick syntax guide.
20+
1921
ReScript code can be [imported into JavaScript code](./import-from-export-to-js.mdx#export-to-javascript), can [generate types for TypeScript](./typescript-integration.mdx), and ReScript can [import code written in JavaScript or TypeScript](./import-from-export-to-js.mdx#import-from-javascript).
2022

2123
## Type System

markdown-pages/docs/manual/llms.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "LLMs"
33
description: "Documentation for LLMs"
44
canonical: "/docs/manual/llms"
55
section: "Overview"
6-
order: 4
6+
order: 10
77
---
88

99
# Documentation for LLMs

markdown-pages/docs/manual/migrate-to-v12.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "Migrate to v12"
33
description: "Instructions on upgrading to ReScript 12"
44
canonical: "/docs/manual/migrate-to-v12"
55
section: "Overview"
6-
order: 4
6+
order: 5
77
---
88

99
# Migrate to ReScript 12

markdown-pages/docs/manual/overview.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ order: 1
1111

1212
A concise reference of ReScript's syntax and core language features.
1313

14+
If you already know JavaScript and want a quick syntax guide first, see [ReScript for JavaScript Developers](./rescript-for-javascript-developers.mdx).
15+
1416
## Semicolons
1517

1618
ReScript does not require semicolons. Line breaks are sufficient to separate statements.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: "ReScript for JavaScript Developers"
3+
description: "A quick ReScript syntax guide for JavaScript developers"
4+
canonical: "/docs/manual/rescript-for-javascript-developers"
5+
section: "Overview"
6+
order: 3
7+
---
8+
9+
# ReScript for JavaScript Developers
10+
11+
If you already write JavaScript, ReScript should feel familiar quickly. This page is a compact syntax guide for the main differences you should be aware of.
12+
13+
For a guided migration workflow, see [Converting from JS](./converting-from-js.mdx).
14+
15+
## What to know first
16+
17+
- `let` bindings are immutable by default. See [Let Binding](./let-binding.mdx) and [Mutation](./mutation.mdx).
18+
- ReScript does not use `null` and `undefined` as normal control flow. Reach for `option` instead. See [Null, Undefined and Option](./null-undefined-option.mdx).
19+
- Arrays must contain values of the same type. See [Array and List](./array-and-list.mdx) and [Tuple](./tuple.mdx).
20+
- Records are not ad-hoc JS objects; they have known field names and types. See [Record](./record.mdx) and [Object](./object.mdx).
21+
- Conditionals and blocks return values, so expression-oriented code is common. See [If-Else & Loops](./control-flow.mdx).
22+
- Pattern matching replaces many ad-hoc `if` or property-check branches. See [Pattern Matching / Destructuring](./pattern-matching-destructuring.mdx).
23+
24+
## Quick reference
25+
26+
| Topic | ReScript | Notes for JavaScript developers |
27+
| --------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
28+
| Semicolons | `let x = 1` | Semicolons are not required. See [Overview](./overview.mdx#semicolons). |
29+
| Comments | `//`, `/* */`, `/** */` | Familiar syntax, including doc comments. See [Overview](./overview.mdx#comments). |
30+
| Variables | `let x = 5` | `let` creates an immutable binding. See [Let Binding](./let-binding.mdx). |
31+
| Mutation | `let x = ref(5)` | Mutable state is explicit through `ref` or mutable fields. See [Mutation](./mutation.mdx). |
32+
| Strings | `"hello"` | Strings use double quotes. See [Primitive Types](./primitive-types.mdx). |
33+
| String concatenation | `"hello " ++ name` | ReScript uses `++` for strings. See [Primitive Types](./primitive-types.mdx). |
34+
| Interpolation | `` `hello ${name}` `` | Template strings work similarly. See [Primitive Types](./primitive-types.mdx). |
35+
| Equality | `===`, `!==`, `==`, `!=` | No coercive equality. `==` and `!=` are structural. See [Equality and Comparison](./equality-comparison.mdx). |
36+
| Numbers | `3`, `3.14`, `2.0 * 3.0` | Arithmetic operators work for both `int` and `float`. See [Primitive Types](./primitive-types.mdx). |
37+
| Records | `{x: 30, y: 20}` | Similar object syntax, but records are typed. See [Record](./record.mdx). |
38+
| Arrays | `[1, 2, 3]` | Arrays are homogeneous. See [Array and List](./array-and-list.mdx). |
39+
| Mixed fixed-size data | `(1, "Bob", true)` | Use tuples instead of heterogeneous arrays. See [Tuple](./tuple.mdx). |
40+
| Missing values | `option<'a>` | Use `Some(value)` and `None` instead of `null` and `undefined`. See [Null, Undefined and Option](./null-undefined-option.mdx). |
41+
| Functions | `let add = (a, b) => a + b` | Familiar arrow-style syntax. See [Function](./function.mdx). |
42+
| Blocks | `{ let x = 1; x + 1 }` | The last expression is returned implicitly. See [Overview](./overview.mdx#blocks). |
43+
| Conditionals | `if cond {a} else {b}` | `if` is an expression. See [If-Else & Loops](./control-flow.mdx). |
44+
| Pattern matching | `switch value { ... }` | Use `switch` for destructuring and exhaustive branching. See [Pattern Matching / Destructuring](./pattern-matching-destructuring.mdx). |
45+
| Destructuring | `let {a, b} = data` | Works for records, arrays, tuples, and more. See [Pattern Matching / Destructuring](./pattern-matching-destructuring.mdx). |
46+
| Loops | `for i in 0 to 10 {}` | `for` and `while` exist, but collection transforms are also common. See [If-Else & Loops](./control-flow.mdx). |
47+
| Exceptions | `throw(MyException(...))` | `throw` and `try` exist, but typed data flow is preferred where possible. See [Exception](./exception.mdx). |
48+
| JSX | `<Comp message />` | JSX is supported directly, with a few ReScript conventions. See [JSX](./jsx.mdx). |
49+
50+
## Where to Go Next
51+
52+
- For a broader syntax reference, see [Overview](./overview.mdx).
53+
- For a migration workflow inside an existing codebase, see [Converting from JS](./converting-from-js.mdx).
54+
- For JavaScript interop, see [Interop Cheatsheet](./interop-cheatsheet.mdx).
55+
- For importing and exporting JS modules, see [Import from Export to JS](./import-from-export-to-js.mdx).
56+
- For binding to JS objects and functions, see [Bind to JS Object](./bind-to-js-object.mdx) and [Bind to JS Function](./bind-to-js-function.mdx).

src/Mdx.res

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ external childrenToString: {..} => string = "toString"
5959
let sortSection = mdxPages =>
6060
Array.toSorted(mdxPages, (a: attributes, b: attributes) =>
6161
switch (a.order, b.order) {
62-
| (Some(a), Some(b)) => a > b ? 1.0 : -1.0
62+
| (Some(orderA), Some(orderB)) =>
63+
switch Int.compare(orderA, orderB) {
64+
| 0. => String.compare(a.title, b.title)
65+
| result => result
66+
}
6367
| (Some(_), None) => -1.0
6468
| (None, Some(_)) => 1.0
65-
| (None, None) => 0.0
69+
| (None, None) => String.compare(a.title, b.title)
6670
}
6771
)
6872

0 commit comments

Comments
 (0)