Skip to content

Commit

Permalink
V12 docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fhammerschmidt committed Dec 7, 2024
1 parent d634989 commit 266ebe0
Show file tree
Hide file tree
Showing 161 changed files with 12,489 additions and 395 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VERSION_LATEST="v11.0.0"
VERSION_NEXT="v12.0.0"
10 changes: 0 additions & 10 deletions data/sidebar_gentype_latest.json

This file was deleted.

File renamed without changes.
77 changes: 77 additions & 0 deletions data/sidebar_manual_v1200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"Overview": [
"introduction",
"installation",
"migrate-to-v11",
"editor-plugins",
"try"
],
"Language Features": [
"overview",
"let-binding",
"type",
"primitive-types",
"tuple",
"record",
"object",
"variant",
"polymorphic-variant",
"null-undefined-option",
"array-and-list",
"function",
"control-flow",
"pipe",
"pattern-matching-destructuring",
"mutation",
"jsx",
"exception",
"lazy-values",
"promise",
"async-await",
"tagged-templates",
"module",
"import-export",
"attribute",
"reserved-keywords",
"equality-comparison"
],
"Advanced Features": [
"extensible-variant",
"scoped-polymorphic-types"
],
"JavaScript Interop": [
"interop-cheatsheet",
"embed-raw-javascript",
"shared-data-types",
"external",
"bind-to-js-object",
"bind-to-js-function",
"import-from-export-to-js",
"bind-to-global-js-values",
"json",
"inlining-constants",
"use-illegal-identifier-names",
"generate-converters-accessors",
"browser-support-polyfills",
"libraries",
"typescript-integration"
],
"Build System": [
"build-overview",
"build-configuration",
"build-configuration-schema",
"build-external-stdlib",
"build-pinned-dependencies",
"interop-with-js-build-systems",
"build-performance",
"warning-numbers"
],
"Guides": [
"converting-from-js"
],
"Extra": [
"newcomer-examples",
"project-structure",
"faq"
]
}
21 changes: 19 additions & 2 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
import fs from "fs";
import webpack from "webpack";
import rehypeSlug from "rehype-slug";
Expand All @@ -7,17 +8,19 @@ import remarkFrontmatter from "remark-frontmatter";
import remarkMdxFrontmatter from "remark-mdx-frontmatter";
import { createLoader } from "simple-functional-loader";

const bsconfig = JSON.parse(fs.readFileSync("./rescript.json"));
const bsconfig = JSON.parse(fs.readFileSync("./rescript.json").toString());

const { ProvidePlugin } = webpack;

const transpileModules = ["rescript"].concat(bsconfig["bs-dependencies"]);

const config = {
output: process.env.BUILD_STATIC === 'true' ? 'export' : undefined,
output: process.env.BUILD_STATIC === "true" ? "export" : undefined,
pageExtensions: ["jsx", "js", "bs.js", "mdx", "mjs"],
env: {
ENV: process.env.NODE_ENV,
VERSION_LATEST: process.env.VERSION_LATEST,
VERSION_NEXT: process.env.VERSION_NEXT,
},
swcMinify: false,
webpack: (config, options) => {
Expand Down Expand Up @@ -81,6 +84,20 @@ const config = {
config.plugins.push(new ProvidePlugin({ React: "react" }));
return config;
},
async rewrites() {
return {
beforeFiles: [
{
source: "/docs/manual/latest/:slug",
destination: `/docs/manual/${process.env.VERSION_LATEST}/:slug`,
},
{
source: "/docs/manual/next/:slug",
destination: `/docs/manual/${process.env.VERSION_NEXT}/:slug`,
},
],
};
},
async redirects() {
return [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"unified": "^8.4.0"
},
"scripts": {
"dev": "next",
"dev": "NODE_OPTIONS='--inspect' next dev",
"build": "rescript && npm run update-index && next build",
"test": "node scripts/test-examples.mjs && node scripts/test-hrefs.mjs",
"reanalyze": "reanalyze -all-cmt .",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
getStaticPathsByVersion,
getStaticPropsByVersion
getStaticPropsByVersion,
} from "src/ApiDocs.mjs";

import APIDocs from "src/ApiDocs.mjs";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ canonical: "/docs/manual/latest/overview"

### Semicolon

| JavaScript | ReScript |
| ------------------------------------ | -------------------- |
| Rules enforced by linter/formatter | No semicolon needed! |
| JavaScript | ReScript |
| ---------------------------------- | -------------------- |
| Rules enforced by linter/formatter | No semicolon needed! |

### Comments

Expand All @@ -26,21 +26,21 @@ canonical: "/docs/manual/latest/overview"

### Variable

| JavaScript | ReScript |
| ----------------------- | ------------------------------ |
| `const x = 5;` | `let x = 5` |
| `var x = y;` | No equivalent (thankfully) |
| JavaScript | ReScript |
| ----------------------- | ------------------------------------- |
| `const x = 5;` | `let x = 5` |
| `var x = y;` | No equivalent (thankfully) |
| `let x = 5; x = x + 1;` | `let x = ref(5); x := x.contents + 1` |

### String & Character

| JavaScript | ReScript |
| ----------------------------- | --------------------- |
| `"Hello world!"` | Same |
| `'Hello world!'` | Strings must use `"` |
| `"hello " + "world"` | `"hello " ++ "world"` |
| `` `hello ${message}` `` | Same |
| `` sql`select ${fnName};` `` | Same |
| JavaScript | ReScript |
| ---------------------------- | --------------------- |
| `"Hello world!"` | Same |
| `'Hello world!'` | Strings must use `"` |
| `"hello " + "world"` | `"hello " ++ "world"` |
| `` `hello ${message}` `` | Same |
| `` sql`select ${fnName};` `` | Same |

### Boolean

Expand Down Expand Up @@ -77,11 +77,11 @@ canonical: "/docs/manual/latest/overview"

### Array

| JavaScript | ReScript |
| --------------------- | ---------------------------------- |
| `[1, 2, 3]` | Same |
| `myArray[1] = 10` | Same |
| `[1, "Bob", true]` | `(1, "Bob", true)` \* |
| JavaScript | ReScript |
| ------------------ | --------------------- |
| `[1, 2, 3]` | Same |
| `myArray[1] = 10` | Same |
| `[1, "Bob", true]` | `(1, "Bob", true)` \* |

\* ReScript does not have heterogenous arrays. Use tuples or [Untagged Variants](variant#untagged-variants) instead.

Expand All @@ -104,12 +104,12 @@ canonical: "/docs/manual/latest/overview"

### Async Function / Await

| JavaScript | ReScript |
| ---------------------------------------- | ---------------------------------- |
| `async (arg) => {...}` | Same |
| `async function named(arg) {...}` | `let named = async (arg) => {...}` |
| `await somePromise` | Same |
| `async (arg): Promise<string> => {...}` | `async (arg): string => {...}` (note the return type)|
| JavaScript | ReScript |
| --------------------------------------- | ----------------------------------------------------- |
| `async (arg) => {...}` | Same |
| `async function named(arg) {...}` | `let named = async (arg) => {...}` |
| `await somePromise` | Same |
| `async (arg): Promise<string> => {...}` | `async (arg): string => {...}` (note the return type) |

### Blocks

Expand Down Expand Up @@ -146,31 +146,31 @@ canonical: "/docs/manual/latest/overview"

### If-else

| JavaScript | ReScript |
| --------------------- | ------------------------------------------------------------------- |
| `if (a) {b} else {c}` | `if a {b} else {c}` \* |
| `a ? b : c` | Same |
| JavaScript | ReScript |
| --------------------- | --------------------------------------------------------------------------------- |
| `if (a) {b} else {c}` | `if a {b} else {c}` \* |
| `a ? b : c` | Same |
| `switch` | `switch` but [super-powered pattern matching!](pattern-matching-destructuring.md) |

\* Our conditionals are always expressions! You can write `let result = if a {"hello"} else {"bye"}`

### Destructuring

| JavaScript | ReScript |
| ----------------------------- | --------------------------------------------- |
| `const {a, b} = data` | `let {a, b} = data` |
| `const [a, b] = data` | `let [a, b] = data` \* |
| `const {a: aa, b: bb} = data` | `let {a: aa, b: bb} = data` |
| JavaScript | ReScript |
| ----------------------------- | --------------------------- |
| `const {a, b} = data` | `let {a, b} = data` |
| `const [a, b] = data` | `let [a, b] = data` \* |
| `const {a: aa, b: bb} = data` | `let {a: aa, b: bb} = data` |

\* Gives good compiler warning that `data` might not be of length 2.

### Loop

| JavaScript | ReScript |
| ------------------------------------- | ------------------------------ |
| `for (let i = 0; i <= 10; i++) {...}` | `for i in 0 to 10 {...}` |
| `for (let i = 10; i >= 0; i--) {...}` | `for i in 10 downto 0 {...}` |
| `while (true) {...}` | `while true {...}` |
| JavaScript | ReScript |
| ------------------------------------- | ---------------------------- |
| `for (let i = 0; i <= 10; i++) {...}` | `for i in 0 to 10 {...}` |
| `for (let i = 10; i >= 0; i--) {...}` | `for i in 10 downto 0 {...}` |
| `while (true) {...}` | `while true {...}` |

### JSX

Expand All @@ -185,10 +185,10 @@ canonical: "/docs/manual/latest/overview"

### Exception

| JavaScript | ReScript |
| ----------------------------------------------- | ------------------------------------------ |
| `throw new SomeError(...)` | `raise(SomeError(...))` |
| `try {a} catch (err) {...} finally {...}` | `try a catch { \| SomeError(err) => ...}` \* |
| JavaScript | ReScript |
| ----------------------------------------- | -------------------------------------------- |
| `throw new SomeError(...)` | `raise(SomeError(...))` |
| `try {a} catch (err) {...} finally {...}` | `try a catch { \| SomeError(err) => ...}` \* |

\* No finally.

Expand Down Expand Up @@ -229,27 +229,27 @@ The last expression of a block delimited by `{}` implicitly returns (including f

## Common Features' JS Output

Feature | Example | JavaScript Output
--------------------------------|--------------------------------------|----------------------
String | `"Hello"` | `"Hello"`
String Interpolation | `` `Hello ${message}` `` | `"Hello " + message`
Character (disrecommended) | `'x'` | `120` (char code)
Integer | `23`, `-23` | `23`, `-23`
Float | `23.0`, `-23.0` | `23.0`, `-23.0`
Integer Addition | `23 + 1` | `23 + 1`
Float Addition | `23.0 +. 1.0` | `23.0 + 1.0`
Integer Division/Multiplication | `2 / 23 * 1` | `2 / 23 * 1`
Float Division/Multiplication | `2.0 /. 23.0 *. 1.0` | `2.0 / 23.0 * 1.0`
Float Exponentiation | `2.0 ** 3.0` | `Math.pow(2.0, 3.0)`
String Concatenation | `"Hello " ++ "World"` | `"Hello " + "World"`
Comparison | `>`, `<`, `>=`, `<=` | `>`, `<`, `>=`, `<=`
Boolean operation | `!`, `&&`, <code>&#124;&#124;</code> | `!`, `&&`, <code>&#124;&#124;</code>
Shallow and deep Equality | `===`, `==` | `===`, `==`
List (disrecommended) | `list{1, 2, 3}` | `{hd: 1, tl: {hd: 2, tl: {hd: 3, tl: 0}}}`
List Prepend | `list{a1, a2, ...oldList}` | `{hd: a1, tl: {hd: a2, tl: theRest}}`
Array | `[1, 2, 3]` | `[1, 2, 3]`
Record | `type t = {b: int}; let a = {b: 10}` | `var a = {b: 10}`
Multiline Comment | `/* Comment here */` | Not in output
Single line Comment | `// Comment here` | Not in output
| Feature | Example | JavaScript Output |
| ------------------------------- | ------------------------------------ | ------------------------------------------ |
| String | `"Hello"` | `"Hello"` |
| String Interpolation | `` `Hello ${message}` `` | `"Hello " + message` |
| Character (disrecommended) | `'x'` | `120` (char code) |
| Integer | `23`, `-23` | `23`, `-23` |
| Float | `23.0`, `-23.0` | `23.0`, `-23.0` |
| Integer Addition | `23 + 1` | `23 + 1` |
| Float Addition | `23.0 +. 1.0` | `23.0 + 1.0` |
| Integer Division/Multiplication | `2 / 23 * 1` | `2 / 23 * 1` |
| Float Division/Multiplication | `2.0 /. 23.0 *. 1.0` | `2.0 / 23.0 * 1.0` |
| Float Exponentiation | `2.0 ** 3.0` | `Math.pow(2.0, 3.0)` |
| String Concatenation | `"Hello " ++ "World"` | `"Hello " + "World"` |
| Comparison | `>`, `<`, `>=`, `<=` | `>`, `<`, `>=`, `<=` |
| Boolean operation | `!`, `&&`, <code>&#124;&#124;</code> | `!`, `&&`, <code>&#124;&#124;</code> |
| Shallow and deep Equality | `===`, `==` | `===`, `==` |
| List (disrecommended) | `list{1, 2, 3}` | `{hd: 1, tl: {hd: 2, tl: {hd: 3, tl: 0}}}` |
| List Prepend | `list{a1, a2, ...oldList}` | `{hd: a1, tl: {hd: a2, tl: theRest}}` |
| Array | `[1, 2, 3]` | `[1, 2, 3]` |
| Record | `type t = {b: int}; let a = {b: 10}` | `var a = {b: 10}` |
| Multiline Comment | `/* Comment here */` | Not in output |
| Single line Comment | `// Comment here` | Not in output |

_Note that this is a cleaned-up comparison table; a few examples' JavaScript output are slightly different in reality._
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions pages/docs/manual/v12.0.0/api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Overview

## ReScript Core

[Core](api/core) is ReScript's new standard library. It replaces the complete `Js` module as well as some of the more frequently used modules from `Belt` and is recommended to use with uncurried mode.

In ReScript 11, it is shipped as a separate npm package `@rescript/core` that is added to your project as per the [installation instructions](/docs/manual/next/installation). In future ReScript versions, it will be included with the `rescript` npm package itself.

## Additional Libraries

ReScript ships with these two additional modules in its standard library:

- [Belt](api/belt): immutable collections and extra helpers not available in JavaScript / [Core](api/core).
- [Dom](api/dom): Dom related types and modules. Contains our standardized types used by various userland DOM bindings.

## Legacy Modules

The [Js](api/js) module is superseded by [Core](api/core).
18 changes: 18 additions & 0 deletions pages/docs/manual/v12.0.0/api/[...slug].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
getStaticPathsByVersion,
getStaticPropsByVersion,
} from "src/ApiDocs.mjs";

import APIDocs from "src/ApiDocs.mjs";

export async function getStaticProps(ctx) {
return await getStaticPropsByVersion({ ...ctx, version: "latest" });
}

export async function getStaticPaths(ctx) {
return await getStaticPathsByVersion("latest");
}

export default function Comp(props) {
return <APIDocs {...props} />;
}
Loading

0 comments on commit 266ebe0

Please sign in to comment.