From 8950d4d10273dfde4dc0a5e3412429cccb098556 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 31 Oct 2026 21:54:14 -0300 Subject: [PATCH 1/6] docs: update examples for ReScript v13 Replace removed syntax and legacy APIs in manual, React, and syntax lookup examples so they compile with the v13 alpha. Explain the current tagged template, global binding, record, and React component APIs. Regenerate JS and JSX output tabs with the installed compiler to keep the displayed examples consistent and restore content validation. --- .../docs/manual/array-and-list.mdx | 8 +- .../docs/manual/async-await.mdx | 8 +- .../docs/manual/bind-to-global-js-values.mdx | 37 +- .../docs/manual/bind-to-js-function.mdx | 12 +- .../docs/manual/control-flow.mdx | 16 +- .../docs/manual/equality-comparison.mdx | 4 +- .../markdown-pages/docs/manual/exception.mdx | 42 +- .../docs/manual/extensible-variant.mdx | 4 +- .../markdown-pages/docs/manual/function.mdx | 6 +- .../generalized-algebraic-data-types.mdx | 4 +- .../manual/generate-converters-accessors.mdx | 6 +- .../docs/manual/interop-cheatsheet.mdx | 11 +- apps/docs/markdown-pages/docs/manual/jsx.mdx | 2 + .../docs/manual/lazy-values.mdx | 8 +- .../markdown-pages/docs/manual/module.mdx | 6 +- .../manual/pattern-matching-destructuring.mdx | 661 ++++++------------ .../docs/manual/polymorphic-variant.mdx | 2 +- .../docs/manual/primitive-types.mdx | 7 +- .../markdown-pages/docs/manual/promise.mdx | 13 +- .../docs/manual/tagged-templates.mdx | 173 +++-- .../markdown-pages/docs/manual/variant.mdx | 2 +- .../docs/react/arrays-and-keys.mdx | 4 +- .../docs/react/components-and-props.mdx | 43 +- .../docs/react/elements-and-jsx.mdx | 4 +- .../docs/react/extensions-of-props.mdx | 8 +- .../docs/react/forwarding-refs.mdx | 12 +- .../docs/react/hooks-effect.mdx | 4 +- .../docs/react/hooks-overview.mdx | 6 +- .../docs/react/hooks-reducer.mdx | 26 +- .../markdown-pages/docs/react/hooks-ref.mdx | 16 +- apps/docs/markdown-pages/docs/react/memo.mdx | 6 +- .../docs/react/refs-and-the-dom.mdx | 20 +- .../syntax-lookup/decorator_deriving.mdx | 39 +- .../decorator_taggedTemplate.mdx | 9 +- .../extension_regular_expression.mdx | 6 +- .../syntax-lookup/extension_todo.mdx | 2 +- .../syntax-lookup/language_async.mdx | 4 +- .../syntax-lookup/language_exception.mdx | 2 +- .../syntax-lookup/language_include.mdx | 2 +- .../language_string_interpolation.mdx | 4 +- .../syntax-lookup/language_while.mdx | 16 +- .../operators_integer_addition.mdx | 4 +- .../syntax-lookup/operators_pipe.mdx | 4 +- .../syntax-lookup/operators_type_coercion.mdx | 2 +- 44 files changed, 516 insertions(+), 759 deletions(-) diff --git a/apps/docs/markdown-pages/docs/manual/array-and-list.mdx b/apps/docs/markdown-pages/docs/manual/array-and-list.mdx index 730504fb7..ae51fef23 100644 --- a/apps/docs/markdown-pages/docs/manual/array-and-list.mdx +++ b/apps/docs/markdown-pages/docs/manual/array-and-list.mdx @@ -102,15 +102,15 @@ let x3 = [...y] ``` ```javascript -import * as Belt_Array from "@rescript/runtime/lib/es6/Belt_Array.js"; +import * as Primitive_array from "@rescript/runtime/lib/es6/Primitive_array.mjs"; let y = [1, 2]; -let x = Belt_Array.concatMany([[4, 5], y]); +let x = Primitive_array.spread([[4, 5], y]); -let x2 = Belt_Array.concatMany([[4, 5], y, [7], y]); +let x2 = Primitive_array.spread([[4, 5], y, [7], y]); -let x3 = Belt_Array.concatMany([y]); +let x3 = Primitive_array.spread([y]); export { y, x, x2, x3 }; ``` diff --git a/apps/docs/markdown-pages/docs/manual/async-await.mdx b/apps/docs/markdown-pages/docs/manual/async-await.mdx index 4330c31dc..4210c0daa 100644 --- a/apps/docs/markdown-pages/docs/manual/async-await.mdx +++ b/apps/docs/markdown-pages/docs/manual/async-await.mdx @@ -48,8 +48,8 @@ let logUserDetails = async (userId: string) => { ```js async function logUserDetails(userId) { let email = await GlobalAPI.fetchUserMail(userId); - await GlobalAPI.sendAnalytics(`User details have been logged for ` + userId); - console.log(`Email address for user ` + userId + `: ` + email); + await GlobalAPI.sendAnalytics(`User details have been logged for ${userId}`); + console.log(`Email address for user ${userId}: ${email}`); } export { logUserDetails }; @@ -191,7 +191,7 @@ let fetchData = async () => { ```js async function fetchData() { let mail = (await GlobalAPI.fetchUserMail("1234")).toUpperCase(); - console.log(`All upper-cased mail: ` + mail); + console.log(`All upper-cased mail: ${mail}`); } export { fetchData }; @@ -223,7 +223,7 @@ let fetchData = async () => { ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; async function fetchData() { let val; diff --git a/apps/docs/markdown-pages/docs/manual/bind-to-global-js-values.mdx b/apps/docs/markdown-pages/docs/manual/bind-to-global-js-values.mdx index 840553d4b..a1ab20216 100644 --- a/apps/docs/markdown-pages/docs/manual/bind-to-global-js-values.mdx +++ b/apps/docs/markdown-pages/docs/manual/bind-to-global-js-values.mdx @@ -104,25 +104,24 @@ This binds to `window.location.ancestorOrigins.length`. ## Special Global Values -Global values like `__filename` and `__DEV__` don't always exist; you can't even model them as an `option`, since the mere act of referring to them in ReScript (then compiled into JS) would trigger the usual `Uncaught ReferenceError: __filename is not defined` error in e.g. the browser environment. +Application globals like `__DEV__` don't always exist. Referring to an undeclared identifier directly would trigger a JavaScript `ReferenceError`. -For these troublesome global values, ReScript provides a special approach: `%external(a_single_identifier)`. +Bind optional properties of `globalThis` instead. Reading a missing property returns `undefined`, which ReScript represents as `None`: ```res -switch %external(__DEV__) { +@scope("globalThis") +external dev: option = "__DEV__" + +switch dev { | Some(_) => Console.log("dev mode") | None => Console.log("production mode") } ``` ```js -import * as Js from "@rescript/runtime/lib/es6/Js.js"; - -let match = Js.undefinedToOption( - typeof __DEV__ === "undefined" ? undefined : __DEV__, -); +let match = globalThis.__DEV__; if (match !== undefined) { console.log("dev mode"); @@ -133,34 +132,30 @@ if (match !== undefined) { -That first line's `typeof` check won't trigger a JS ReferenceError. +This approach works for properties set on the global object. Module-scoped values, such as CommonJS's `__filename`, and identifiers replaced by a bundler are not necessarily properties of `globalThis`. Another example: ```res -switch %external(__filename) { +@scope("globalThis") +external appVersion: option = "__APP_VERSION__" + +switch appVersion { | Some(f) => Console.log(f) -| None => Console.log("non-node environment") +| None => Console.log("application version not provided") }; ``` ```js -import * as Js from "@rescript/runtime/lib/es6/Js.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; - -let f = Js.undefinedToOption( - typeof __filename === "undefined" ? undefined : __filename, -); +let f = globalThis.__APP_VERSION__; if (f !== undefined) { - console.log(Primitive_option.valFromOption(f)); + console.log(f); } else { - console.log("non-node environment"); + console.log("application version not provided"); } ``` - -{/* TODO: revamp this page. Not good. Tell to use globalThis["foo"], and look in our stdlib */} diff --git a/apps/docs/markdown-pages/docs/manual/bind-to-js-function.mdx b/apps/docs/markdown-pages/docs/manual/bind-to-js-function.mdx index 8108b5c0a..50836c941 100644 --- a/apps/docs/markdown-pages/docs/manual/bind-to-js-function.mdx +++ b/apps/docs/markdown-pages/docs/manual/bind-to-js-function.mdx @@ -154,7 +154,7 @@ let session = stripe->createCheckoutSession({}) ```js import Stripe from "stripe"; -let stripe = new Stripe("sk\_..."); +let stripe = new Stripe("sk_..."); let session = stripe.checkout.sessions.create({}); @@ -536,19 +536,17 @@ Currently 4 directives are supported: `null_to_opt`, `undefined_to_opt`, `nullab **Since 11.1** -**Experimental** You can easily bind to [JS tagged template functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates). +You can bind to [JS tagged template functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates). Tag functions in JS expect as input an array of strings and variadic parameters for the arguments of the interpolation. -To bind to those functions in ReScript, the binding signature must have two arrays as arguments, -the first one being an array of strings and the second can be an array of anything. -You add the `@taggedTemplate` annotation and you're good to go! +Use the built-in `taggedTemplate<'param, 'output>` type. The first type parameter describes the interpolated values, and the second describes the return value. This replaces the `@taggedTemplate` decorator removed in v13. ```res // see https://bun.sh/docs/runtime/shell type result = {exitCode: int} -@module("bun") @taggedTemplate -external sh: (array, array) => promise = "$" +@module("bun") +external sh: taggedTemplate> = "$" let filename = "index.res" let result = await sh`ls ${filename}` diff --git a/apps/docs/markdown-pages/docs/manual/control-flow.mdx b/apps/docs/markdown-pages/docs/manual/control-flow.mdx index e5278b3ba..0ac4da5bb 100644 --- a/apps/docs/markdown-pages/docs/manual/control-flow.mdx +++ b/apps/docs/markdown-pages/docs/manual/control-flow.mdx @@ -207,16 +207,16 @@ while (testCondition) { ### Tips & Tricks -There's no loop-breaking `break` keyword (nor early `return` from functions, for that matter) in ReScript. However, we can break out of a while loop easily through using a [mutable binding](./mutation.mdx). +A [mutable binding](./mutation.mdx) can control whether a while loop continues: ```res -let break = ref(false) +let shouldStop = ref(false) -while !break.contents { +while !shouldStop.contents { if Math.random() > 0.3 { - break := true + shouldStop := true } else { Console.log("Still running") } @@ -224,17 +224,17 @@ while !break.contents { ``` ```js -let $$break = { contents: false }; +let shouldStop = { contents: false }; -while (!$$break.contents) { +while (!shouldStop.contents) { if (Math.random() > 0.3) { - $$break.contents = true; + shouldStop.contents = true; } else { console.log("Still running"); } } -export { $$break }; +export { shouldStop }; ``` diff --git a/apps/docs/markdown-pages/docs/manual/equality-comparison.mdx b/apps/docs/markdown-pages/docs/manual/equality-comparison.mdx index 325d7a327..5efcf28f2 100644 --- a/apps/docs/markdown-pages/docs/manual/equality-comparison.mdx +++ b/apps/docs/markdown-pages/docs/manual/equality-comparison.mdx @@ -61,7 +61,7 @@ let doStringsMatch = (s1: string, s2: string) => s1 == s2 ``` ```js -import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js"; +import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; let t2 = true; @@ -122,7 +122,7 @@ let compareOptions = (a: option, b: option) => a < b ``` ```js -import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js"; +import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.mjs"; function compareInt(a, b) { return a > b; diff --git a/apps/docs/markdown-pages/docs/manual/exception.mdx b/apps/docs/markdown-pages/docs/manual/exception.mdx index 3aa56ba22..1fdad9651 100644 --- a/apps/docs/markdown-pages/docs/manual/exception.mdx +++ b/apps/docs/markdown-pages/docs/manual/exception.mdx @@ -21,7 +21,7 @@ throw(InputClosed("The stream has closed!")) ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let InputClosed = /* @__PURE__ */ Primitive_exceptions.create( "Example.InputClosed", @@ -64,7 +64,7 @@ let result = ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -105,8 +105,8 @@ switch list{1, 2, 3}->List.getOrThrow(4) { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -177,9 +177,9 @@ try divide(2, 0)->Console.log catch { ```` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -276,8 +276,8 @@ try decodeUser(%raw("{}"))->Console.log catch { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -385,8 +385,8 @@ false ```` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -479,9 +479,9 @@ Console.log(result) // None ```` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_int from "@rescript/runtime/lib/es6/Primitive_int.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -593,9 +593,9 @@ let myTest = () => { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -673,8 +673,8 @@ let myTest = () => { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { @@ -754,8 +754,8 @@ let myTest = () => { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function getItem(item) { if (item === 3) { diff --git a/apps/docs/markdown-pages/docs/manual/extensible-variant.mdx b/apps/docs/markdown-pages/docs/manual/extensible-variant.mdx index c82a4d7ec..d2cea7161 100644 --- a/apps/docs/markdown-pages/docs/manual/extensible-variant.mdx +++ b/apps/docs/markdown-pages/docs/manual/extensible-variant.mdx @@ -25,7 +25,7 @@ type t += ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let Other = /* @__PURE__ */ Primitive_exceptions.create("Example.Other"); @@ -59,7 +59,7 @@ let print = v => ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let Other = /* @__PURE__ */ Primitive_exceptions.create("Example.Other"); diff --git a/apps/docs/markdown-pages/docs/manual/function.mdx b/apps/docs/markdown-pages/docs/manual/function.mdx index 97da51115..d40b2c1c1 100644 --- a/apps/docs/markdown-pages/docs/manual/function.mdx +++ b/apps/docs/markdown-pages/docs/manual/function.mdx @@ -777,8 +777,8 @@ let someAsyncFn = async () => { ``` ```js -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; function greet(name) { return "Hello " + name; @@ -849,7 +849,7 @@ setTimeout(myFunc, 1000)->ignore ``` ```js -import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.js"; +import * as Stdlib_Promise from "@rescript/runtime/lib/es6/Stdlib_Promise.mjs"; function greet(name) { return "Hello " + name; diff --git a/apps/docs/markdown-pages/docs/manual/generalized-algebraic-data-types.mdx b/apps/docs/markdown-pages/docs/manual/generalized-algebraic-data-types.mdx index e923e4f0f..99bb4ed30 100644 --- a/apps/docs/markdown-pages/docs/manual/generalized-algebraic-data-types.mdx +++ b/apps/docs/markdown-pages/docs/manual/generalized-algebraic-data-types.mdx @@ -38,7 +38,7 @@ let convertToDaylight = tz => { switch tz { | EST => EDT | CST => CDT - | EDT | CDT /* or, _ */ => failwith("Invalid timezone provided!") + | EDT | CDT /* or, _ */ => panic("Invalid timezone provided!") } } ``` @@ -191,7 +191,7 @@ let flexible_find = ( switch Array.find(arr, f) { | None => switch ifNotFound { - | Raise => failwith("No matching item found") + | Raise => panic("No matching item found") | ReturnNone => None | DefaultTo(x) => x } diff --git a/apps/docs/markdown-pages/docs/manual/generate-converters-accessors.mdx b/apps/docs/markdown-pages/docs/manual/generate-converters-accessors.mdx index efd9ea9af..8f63f950e 100644 --- a/apps/docs/markdown-pages/docs/manual/generate-converters-accessors.mdx +++ b/apps/docs/markdown-pages/docs/manual/generate-converters-accessors.mdx @@ -12,17 +12,17 @@ order: 12 - `@deriving(jsConverter)` for records - `@deriving({jsConverter: newType})` for records -- `@deriving(abstract)` for records - `@deriving(jsConverter)` for plain and polymorphic variants These particular ones are no longer needed. Select a doc version lower than `9.0` in the sidebar to see their old docs. +The `@deriving(abstract)` decorator for records was removed in v13. Use record literals to construct JavaScript objects and direct field access to read or update them. Optional fields, mutable fields, and `@as` field renaming are supported directly on records. + {/* TODO: genType */} When using ReScript, you will sometimes come into situations where you want to - Automatically generate functions that convert between ReScript's internal and JS runtime values (e.g. variants). -- Convert a record type into an abstract type with generated creation, accessor and method functions. - Generate some other helper functions, such as functions from record attribute names. You can use the `@deriving` decorator for different code generation scenarios. All different options and configurations will be discussed on this page. @@ -91,7 +91,7 @@ let pets = [{name: "bob"}, {name: "bob2"}] pets ->Array.map(name) - ->Array.joinWith("&") + ->Array.join("&") ->Console.log ``` diff --git a/apps/docs/markdown-pages/docs/manual/interop-cheatsheet.mdx b/apps/docs/markdown-pages/docs/manual/interop-cheatsheet.mdx index dad4ab130..ea648ac48 100644 --- a/apps/docs/markdown-pages/docs/manual/interop-cheatsheet.mdx +++ b/apps/docs/markdown-pages/docs/manual/interop-cheatsheet.mdx @@ -38,7 +38,7 @@ This is a glossary with examples. All the features are described by later pages. - [`@uncurry`](./bind-to-js-function.mdx#extra-solution) - [`@unwrap`](./bind-to-js-function.mdx#trick-2-polymorphic-variant--bsunwrap) - [`@val`](./bind-to-global-js-values.mdx#global-modules) -- [`@taggedTemplate`](./bind-to-js-function.mdx#tagged_template-functions) +- [`taggedTemplate`](./bind-to-js-function.mdx#tagged-template-functions) - [`@deprecated`](./attribute.mdx#usage) - [`genType`](https://github.com/reason-association/genType) - [`@JSX`](./jsx.mdx) @@ -49,7 +49,6 @@ This is a glossary with examples. All the features are described by later pages. ### Extension Points - [`%debugger`](./embed-raw-javascript.mdx#debugger) -- [`%external`](./bind-to-global-js-values.mdx#special-global-values) - [`%raw`](./embed-raw-javascript.mdx#paste-raw-js-code) - [`%todo`](../../syntax-lookup/extension_todo.mdx) @@ -140,8 +139,8 @@ let result3: option = Nullable.toOption(Nullable.make(10)) ``` ```js -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; let result2 = Stdlib_Nullable.fromOption(10); @@ -207,8 +206,8 @@ external join: array => string = "join" ```res // see https://bun.sh/docs/runtime/shell type result = {exitCode: int} -@module("bun") @taggedTemplate -external sh: (array, array) => promise = "$" +@module("bun") +external sh: taggedTemplate> = "$" let filename = "index.res" let result = await sh`ls ${filename}` diff --git a/apps/docs/markdown-pages/docs/manual/jsx.mdx b/apps/docs/markdown-pages/docs/manual/jsx.mdx index 2fe3e6aa1..a38122e1e 100644 --- a/apps/docs/markdown-pages/docs/manual/jsx.mdx +++ b/apps/docs/markdown-pages/docs/manual/jsx.mdx @@ -388,6 +388,8 @@ type component<'props> = Jsx.component<'props> type componentLike<'props, 'return> = Jsx.componentLike<'props, 'return> +external component: componentLike<'props, element> => component<'props> = "%component_identity" + @module("preact/jsx-runtime") external jsx: (component<'props>, 'props) => element = "jsx" diff --git a/apps/docs/markdown-pages/docs/manual/lazy-values.mdx b/apps/docs/markdown-pages/docs/manual/lazy-values.mdx index 7c555d5b3..83facd799 100644 --- a/apps/docs/markdown-pages/docs/manual/lazy-values.mdx +++ b/apps/docs/markdown-pages/docs/manual/lazy-values.mdx @@ -25,7 +25,7 @@ let expensiveFilesRead = Lazy.make(() => { ```js import * as Nodefs from "node:fs"; -import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.js"; +import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.mjs"; let expensiveFilesRead = Stdlib_Lazy.make(() => { console.log("Reading dir"); @@ -55,7 +55,7 @@ Console.log(Lazy.get(expensiveFilesRead)) // logs the directory content ```js import * as Nodefs from "node:fs"; -import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.js"; +import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.mjs"; let expensiveFilesRead = Stdlib_Lazy.make(() => { console.log("Reading dir"); @@ -91,8 +91,8 @@ let result = try { ```js import * as Nodefs from "node:fs"; -import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_Lazy from "@rescript/runtime/lib/es6/Stdlib_Lazy.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let expensiveFilesRead = Stdlib_Lazy.make(() => { console.log("Reading dir"); diff --git a/apps/docs/markdown-pages/docs/manual/module.mdx b/apps/docs/markdown-pages/docs/manual/module.mdx index 789ccc686..4bae0ba80 100644 --- a/apps/docs/markdown-pages/docs/manual/module.mdx +++ b/apps/docs/markdown-pages/docs/manual/module.mdx @@ -317,7 +317,7 @@ let BaseComponent = { defaultGreeting: "Hello", getAudience: getAudience }; let defaultGreeting = "Hey"; function render() { - return defaultGreeting + " world!"; + return "Hey world!"; } let ActualComponent = { @@ -608,7 +608,7 @@ module MakeSet = (Item: Comparable) => { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; function getProfession(person) { if (person === "Teacher") { @@ -653,7 +653,7 @@ module SetOfIntPairs = MakeSet(IntPair) ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; function getProfession(person) { if (person === "Teacher") { diff --git a/apps/docs/markdown-pages/docs/manual/pattern-matching-destructuring.mdx b/apps/docs/markdown-pages/docs/manual/pattern-matching-destructuring.mdx index 7a1f6e919..ff3c8f025 100644 --- a/apps/docs/markdown-pages/docs/manual/pattern-matching-destructuring.mdx +++ b/apps/docs/markdown-pages/docs/manual/pattern-matching-destructuring.mdx @@ -256,34 +256,29 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } @@ -321,34 +316,29 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } @@ -409,50 +399,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } export { person1, message, myStatus }; @@ -481,50 +462,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } if (person1.TAG === "Teacher") { @@ -555,50 +527,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } if (typeof myStatus !== "object" || myStatus.TAG !== "Vacations") { @@ -629,50 +592,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } if (typeof myStatus !== "object" || myStatus.TAG !== "Vacations") { @@ -712,50 +666,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } if (person1.TAG !== "Teacher") { @@ -792,50 +737,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } if (person1.TAG !== "Teacher") { @@ -892,50 +828,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } function greetPet(pet) { @@ -1003,50 +930,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } function isPet(animal) { @@ -1092,50 +1010,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } function isPet(animal) { @@ -1179,50 +1088,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } function isPet(animal) { @@ -1261,58 +1161,49 @@ switch findItem() { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let myItems = { hd: 1, tl: { hd: 2, tl: { hd: 3, tl: /* [] */ 0 } } }; @@ -1325,13 +1216,13 @@ function findItem() { throw { RE_EXN_ID: "Not_found", Error: new Error() }; } -let exit$2 = 0; +let exit$1 = 0; let item; try { item = findItem(); - exit$2 = 1; + exit$1 = 1; } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); if (exn.RE_EXN_ID === "Not_found") { @@ -1341,7 +1232,7 @@ try { } } -if (exit$2 === 1) { +if (exit$1 === 1) { console.log(item); } @@ -1374,50 +1265,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let students = ["Jane", "Harvey", "Patrick"]; @@ -1465,50 +1347,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } function printStudents(_students) { @@ -1563,50 +1436,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; @@ -1639,50 +1503,41 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; @@ -1718,58 +1573,49 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; -console.log(10); - let b = d.B; +console.log(10); + let coordinates = [10, 20, 30]; let centerY = 20; @@ -1814,54 +1660,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function messageFor(person) { if (person.TAG === "Teacher") { switch (person.name) { @@ -1881,32 +1720,24 @@ function messageFor(person) { let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - return ( - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!` - ); + return `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } if (typeof match$1 !== "object") { if (match$1 === "Sick") { return `How are you feeling?`; } else { - return `Good luck next semester ` + name + `!`; + return `Good luck next semester ${name}!`; } } match$1.TAG === "Vacations"; if (match.reportCard.gpa !== 0.0) { - return `Good luck next semester ` + name + `!`; + return `Good luck next semester ${name}!`; } else { - return `Come back in ` + match$1._0.toString() + ` days!`; + return `Come back in ${match$1._0.toString()} days!`; } } } -let b = d.B; - export { person1, message, myStatus, d, b, messageFor }; ``` @@ -1941,58 +1772,49 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; -console.log("value is present"); - let b = d.B; +console.log("value is present"); + let myNullableValue = 5; export { person1, message, myStatus, d, b, myNullableValue }; @@ -2034,54 +1856,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function optionBoolToBool(opt) { if (opt === undefined) { return false; @@ -2090,8 +1905,6 @@ function optionBoolToBool(opt) { } } -let b = d.B; - export { person1, message, myStatus, d, b, optionBoolToBool }; ``` @@ -2116,54 +1929,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function optionBoolToBool(opt) { if (opt !== undefined) { return opt; @@ -2172,8 +1978,6 @@ function optionBoolToBool(opt) { } } -let b = d.B; - export { person1, message, myStatus, d, b, optionBoolToBool }; ``` @@ -2199,54 +2003,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function optionBoolToBool(opt) { if (opt !== undefined) { return opt; @@ -2255,8 +2052,6 @@ function optionBoolToBool(opt) { } } -let b = d.B; - export { person1, message, myStatus, d, b, optionBoolToBool }; ``` @@ -2281,54 +2076,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function optionBoolToBool(opt) { if (opt !== undefined) { return opt; @@ -2337,8 +2125,6 @@ function optionBoolToBool(opt) { } } -let b = d.B; - export { person1, message, myStatus, d, b, optionBoolToBool }; ``` @@ -2363,54 +2149,47 @@ let person1 = { TAG: "Teacher", name: "Jane", age: 35 }; let message; if (person1.TAG === "Teacher") { - message = `Hello ` + "Jane" + `.`; + message = `Hello Jane.`; } else { let match = "Jane"; let match$1 = match.status; let name = match.name; let match$2 = match.reportCard; if (match$2.passing) { - message = - `Congrats ` + - name + - `, nice GPA of ` + - match$2.gpa.toString() + - ` you got there!`; + message = `Congrats ${name}, nice GPA of ${match$2.gpa.toString()} you got there!`; } else { let exit = 0; if (typeof match$1 !== "object") { message = match$1 === "Sick" ? `How are you feeling?` - : `Good luck next semester ` + name + `!`; + : `Good luck next semester ${name}!`; } else { exit = 1; } if (exit === 1) { message = match.reportCard.gpa !== 0.0 - ? `Good luck next semester ` + name + `!` - : `Come back in ` + match$1._0.toString() + ` days!`; + ? `Good luck next semester ${name}!` + : `Come back in ${match$1._0.toString()} days!`; } } } let myStatus = { TAG: "Vacations", _0: 10 }; -let exit$1 = 0; - if (typeof myStatus !== "object") { console.log("Hey! How are you?"); +} else if (myStatus.TAG === "Vacations") { + console.log(`Come back in ${(10).toString()} days!`); } else { - exit$1 = 1; -} - -if (exit$1 === 1) { - console.log(`Come back in ` + (10).toString() + ` days!`); + console.log(`Come back in ${(10).toString()} days!`); } let d = { A: 5, B: 6 }; +let b = d.B; + function optionBoolToBool(opt) { if (opt !== undefined) { return opt; @@ -2419,8 +2198,6 @@ function optionBoolToBool(opt) { } } -let b = d.B; - export { person1, message, myStatus, d, b, optionBoolToBool }; ``` diff --git a/apps/docs/markdown-pages/docs/manual/polymorphic-variant.mdx b/apps/docs/markdown-pages/docs/manual/polymorphic-variant.mdx index f19c537e0..600390d41 100644 --- a/apps/docs/markdown-pages/docs/manual/polymorphic-variant.mdx +++ b/apps/docs/markdown-pages/docs/manual/polymorphic-variant.mdx @@ -406,7 +406,7 @@ let message = "Hello " ++ (theCompany :> string) ``` ```js -let message = "Hello " + "Apple"; +let message = "Hello Apple"; let myColor = "Ruby"; diff --git a/apps/docs/markdown-pages/docs/manual/primitive-types.mdx b/apps/docs/markdown-pages/docs/manual/primitive-types.mdx index cdd353066..50e4a136a 100644 --- a/apps/docs/markdown-pages/docs/manual/primitive-types.mdx +++ b/apps/docs/markdown-pages/docs/manual/primitive-types.mdx @@ -75,13 +75,10 @@ ${name} ```js let name = "Joe"; -let greeting = - `Hello +let greeting = `Hello World 👋 -` + - name + - ` +${name} `; export { name, greeting }; diff --git a/apps/docs/markdown-pages/docs/manual/promise.mdx b/apps/docs/markdown-pages/docs/manual/promise.mdx index e64cbf5f4..a281e69fb 100644 --- a/apps/docs/markdown-pages/docs/manual/promise.mdx +++ b/apps/docs/markdown-pages/docs/manual/promise.mdx @@ -50,19 +50,18 @@ let p3 = Promise.reject(MyOwnError("some rejection")) ```res let logAsyncMessage = () => { - open Promise Promise.resolve("hello world") - ->then(msg => { + ->Promise.then(msg => { // then callbacks require the result to be resolved explicitly - resolve("Message: " ++ msg) + Promise.resolve("Message: " ++ msg) }) - ->then(msg => { + ->Promise.then(msg => { Console.log(msg) // Even if there is no result, we need to use resolve() to return a promise - resolve() + Promise.resolve() }) - ->ignore // Requires ignoring due to unhandled return value + ->Promise.ignore // Handle the discarded promise explicitly } ``` @@ -94,7 +93,7 @@ external fetchMessage: string => promise = "global.fetchMessage" let logAsyncMessage = async () => { let messages = await Promise.all([fetchMessage("message1"), fetchMessage("message2")]) - Console.log(messages->Array.joinWith(", ")) + Console.log(messages->Array.join(", ")) } ``` diff --git a/apps/docs/markdown-pages/docs/manual/tagged-templates.mdx b/apps/docs/markdown-pages/docs/manual/tagged-templates.mdx index 7af778b41..1692036ee 100644 --- a/apps/docs/markdown-pages/docs/manual/tagged-templates.mdx +++ b/apps/docs/markdown-pages/docs/manual/tagged-templates.mdx @@ -18,13 +18,13 @@ to learn more about them. ## Define a tag function -Tag functions in ReScript have the following signature: +Tagged template values in ReScript have the following type: ```res sig -let myTagFunction : (array, array<'param>) => 'output +let myTagFunction: taggedTemplate<'param, 'output> ``` -As you can see, you can have any type you want both for the placeholder array and for the output. +The type parameters describe the interpolated values and the output. Use `TaggedTemplate.make` to lift a ReScript function that takes the string segments and an array of interpolated values into a tagged template value. Given how string interpolation works, you'll always have the following invariant: @@ -44,7 +44,7 @@ type params = | S(string) | Bool(bool) -let s = (strings, parameters) => { +let s = TaggedTemplate.make((strings, parameters) => { let text = Array.reduceWithIndex(parameters, Array.getUnsafe(strings, 0), ( acc, param, @@ -61,35 +61,32 @@ let s = (strings, parameters) => { acc ++ p ++ s }) React.string(text) -} +}) ``` ```js -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js"; - -function s(strings, parameters) { - return Stdlib_Array.reduceWithIndex( - parameters, - strings[0], - (acc, param, i) => { - let s = strings[(i + 1) | 0]; - let p; - switch (param.TAG) { - case "I": - case "F": - p = param._0.toString(); - break; - case "S": - p = param._0; - break; - case "Bool": - p = param._0 ? "true" : "false"; - break; - } - return acc + p + s; - }, - ); -} +import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; +import * as Stdlib_TaggedTemplate from "@rescript/runtime/lib/es6/Stdlib_TaggedTemplate.mjs"; + +let s = Stdlib_TaggedTemplate.make((strings, parameters) => + Stdlib_Array.reduceWithIndex(parameters, strings[0], (acc, param, i) => { + let s = strings[(i + 1) | 0]; + let p; + switch (param.TAG) { + case "I": + case "F": + p = param._0.toString(); + break; + case "S": + p = param._0; + break; + case "Bool": + p = param._0 ? "true" : "false"; + break; + } + return acc + p + s; + }), +); export { s }; ``` @@ -112,42 +109,36 @@ module Greetings = { ``` ```js -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js"; +import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as JsxRuntime from "react/jsx-runtime"; - -function s(strings, parameters) { - return Stdlib_Array.reduceWithIndex( - parameters, - strings[0], - (acc, param, i) => { - let s = strings[(i + 1) | 0]; - let p; - switch (param.TAG) { - case "I": - case "F": - p = param._0.toString(); - break; - case "S": - p = param._0; - break; - case "Bool": - p = param._0 ? "true" : "false"; - break; - } - return acc + p + s; - }, - ); -} +import * as Stdlib_TaggedTemplate from "@rescript/runtime/lib/es6/Stdlib_TaggedTemplate.mjs"; + +let s = Stdlib_TaggedTemplate.make((strings, parameters) => + Stdlib_Array.reduceWithIndex(parameters, strings[0], (acc, param, i) => { + let s = strings[(i + 1) | 0]; + let p; + switch (param.TAG) { + case "I": + case "F": + p = param._0.toString(); + break; + case "S": + p = param._0; + break; + case "Bool": + p = param._0 ? "true" : "false"; + break; + } + return acc + p + s; + }), +); function Example$Greetings(props) { return JsxRuntime.jsx("div", { - children: s( - [`hello `, ` you're `, ` year old!`], - [ - { TAG: "S", _0: props.name }, - { TAG: "I", _0: props.age }, - ], - ), + children: s`hello ${{ TAG: "S", _0: props.name }} you're ${{ + TAG: "I", + _0: props.age, + }} year old!`, }); } @@ -157,43 +148,37 @@ export { s, Greetings }; ``` ```jsx -import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js"; +import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.mjs"; import * as JsxRuntime from "react/jsx-runtime"; - -function s(strings, parameters) { - return Stdlib_Array.reduceWithIndex( - parameters, - strings[0], - (acc, param, i) => { - let s = strings[(i + 1) | 0]; - let p; - switch (param.TAG) { - case "I": - case "F": - p = param._0.toString(); - break; - case "S": - p = param._0; - break; - case "Bool": - p = param._0 ? "true" : "false"; - break; - } - return acc + p + s; - }, - ); -} +import * as Stdlib_TaggedTemplate from "@rescript/runtime/lib/es6/Stdlib_TaggedTemplate.mjs"; + +let s = Stdlib_TaggedTemplate.make((strings, parameters) => + Stdlib_Array.reduceWithIndex(parameters, strings[0], (acc, param, i) => { + let s = strings[(i + 1) | 0]; + let p; + switch (param.TAG) { + case "I": + case "F": + p = param._0.toString(); + break; + case "S": + p = param._0; + break; + case "Bool": + p = param._0 ? "true" : "false"; + break; + } + return acc + p + s; + }), +); function Example$Greetings(props) { return (
- {s( - [`hello `, ` you're `, ` year old!`], - [ - { TAG: "S", _0: props.name }, - { TAG: "I", _0: props.age }, - ], - )} + {s`hello ${{ TAG: "S", _0: props.name }} you're ${{ + TAG: "I", + _0: props.age, + }} year old!`}
); } diff --git a/apps/docs/markdown-pages/docs/manual/variant.mdx b/apps/docs/markdown-pages/docs/manual/variant.mdx index 714914497..22215b69b 100644 --- a/apps/docs/markdown-pages/docs/manual/variant.mdx +++ b/apps/docs/markdown-pages/docs/manual/variant.mdx @@ -578,7 +578,7 @@ switch animal { ```javascript function greetAnimal(animal) { if (animal !== "Dog" && animal !== "Bird" && animal !== "Cat") { - return `I don't know how to greet animal ` + animal; + return `I don't know how to greet animal ${animal}`; } switch (animal) { case "Dog": diff --git a/apps/docs/markdown-pages/docs/react/arrays-and-keys.mdx b/apps/docs/markdown-pages/docs/react/arrays-and-keys.mdx index 600596ae5..ea5bdcbbf 100644 --- a/apps/docs/markdown-pages/docs/react/arrays-and-keys.mdx +++ b/apps/docs/markdown-pages/docs/react/arrays-and-keys.mdx @@ -394,7 +394,7 @@ let make = () => { ``` ```js -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; import * as JsxRuntime from "react/jsx-runtime"; let todos = [ @@ -420,7 +420,7 @@ export { todos, items, make }; ``` ```jsx -import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.js"; +import * as Stdlib_List from "@rescript/runtime/lib/es6/Stdlib_List.mjs"; import * as JsxRuntime from "react/jsx-runtime"; let todos = [ diff --git a/apps/docs/markdown-pages/docs/react/components-and-props.mdx b/apps/docs/markdown-pages/docs/react/components-and-props.mdx index d4b040548..8703bbbb4 100644 --- a/apps/docs/markdown-pages/docs/react/components-and-props.mdx +++ b/apps/docs/markdown-pages/docs/react/components-and-props.mdx @@ -80,7 +80,7 @@ In ReactJS, props are usually described as a single `props` record. In ReScript, // src/Article.res @react.component let make = (~title: string, ~visitorCount: int, ~children: React.element) => { - let visitorCountMsg = "You are visitor number: " ++ Belt.Int.toString(visitorCount); + let visitorCountMsg = "You are visitor number: " ++ Int.toString(visitorCount);
{React.string(title)}
{React.string(visitorCountMsg)}
@@ -93,7 +93,8 @@ let make = (~title: string, ~visitorCount: int, ~children: React.element) => { import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { - let visitorCountMsg = "You are visitor number: " + String(props.visitorCount); + let visitorCountMsg = + "You are visitor number: " + props.visitorCount.toString(); return JsxRuntime.jsxs("div", { children: [ JsxRuntime.jsx("div", { children: props.title }), @@ -112,7 +113,8 @@ export { make }; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { - let visitorCountMsg = "You are visitor number: " + String(props.visitorCount); + let visitorCountMsg = + "You are visitor number: " + props.visitorCount.toString(); return (
{props.title}
@@ -201,7 +203,7 @@ let name = Some("Andrea") ``` ```js -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -218,7 +220,7 @@ export { Greeting, name }; ``` ```jsx -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -282,7 +284,7 @@ module MyList = { ``` ```js -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -308,7 +310,7 @@ export { Greeting, MyList }; ``` ```jsx -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -446,7 +448,7 @@ let make = (props: props) => { ``` ```js -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -465,7 +467,7 @@ export { Greeting, make }; ``` ```jsx -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -530,7 +532,7 @@ let make = () => { ``` ```js -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -551,7 +553,7 @@ export { Greeting, make }; ``` ```jsx -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -577,9 +579,9 @@ export { Greeting, make }; **Note:** React components are capitalized; primitive DOM elements like `div` or `button` are uncapitalized. More infos on the JSX specifics and code transformations can be found in our [JSX language manual section](../manual/jsx.mdx#capitalized-tag). -### Handwritten Components +### Components with a Props Record -You don't need to use the `@react.component` decorator to write components that can be used in JSX. Instead you can write the `make` function with type `props` and these will always work as React components. But then you will have the issue with the component name being "make" in the React dev tools. +Use `@react.componentWithProps` when a component takes a single props record instead of labeled arguments. For example: @@ -589,6 +591,7 @@ For example: module Link = { type props = {href: string, children: React.element}; + @react.componentWithProps let make = (props: props) => { {props.children} @@ -600,7 +603,7 @@ module Link = { ``` ```js -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -609,19 +612,19 @@ function Example$Greeting(props) { let Greeting = { make: Example$Greeting }; -function make(props) { +function Example$Link(props) { return JsxRuntime.jsx("a", { children: props.children, href: props.href }); } -let Link = { make: make }; +let Link = { make: Example$Link }; -JsxRuntime.jsx(make, { href: "/docs", children: "Docs" }); +JsxRuntime.jsx(Example$Link, { href: "/docs", children: "Docs" }); export { Greeting, Link }; ``` ```jsx -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$Greeting(props) { @@ -630,11 +633,11 @@ function Example$Greeting(props) { let Greeting = { make: Example$Greeting }; -function make(props) { +function Example$Link(props) { return {props.children}; } -let Link = { make: make }; +let Link = { make: Example$Link }; {"Docs"}; diff --git a/apps/docs/markdown-pages/docs/react/elements-and-jsx.mdx b/apps/docs/markdown-pages/docs/react/elements-and-jsx.mdx index 4bc92f07d..2631716b6 100644 --- a/apps/docs/markdown-pages/docs/react/elements-and-jsx.mdx +++ b/apps/docs/markdown-pages/docs/react/elements-and-jsx.mdx @@ -142,7 +142,7 @@ Sometimes it's necessary to pass around component functions to have more control ```res type props = {name: string} -let render = (myComp: props => React.element) => { +let render = (myComp: React.component) => {
{React.createElement(myComp, {name: "Franz"})}
} ``` @@ -164,7 +164,7 @@ There is also a `React.createElementVariadic` function, which takes an array of ```res type props = {title: string, children: React.element} -let render = (article: props => React.element) => { +let render = (article: React.component) => { let children = [React.string("Introduction"), React.string("Body")] let props = {title: "Article #1", children: React.null} diff --git a/apps/docs/markdown-pages/docs/react/extensions-of-props.mdx b/apps/docs/markdown-pages/docs/react/extensions-of-props.mdx index 10a302a3e..6e64403a5 100644 --- a/apps/docs/markdown-pages/docs/react/extensions-of-props.mdx +++ b/apps/docs/markdown-pages/docs/react/extensions-of-props.mdx @@ -42,9 +42,7 @@ let Comp = { make: make }; let props = { b: "b" }; -let newrecord = { ...props }; - -JsxRuntime.jsx(make, ((newrecord.a = "a"), newrecord)); +JsxRuntime.jsx(make, { ...props, a: "a" }); export { Comp, props }; ``` @@ -59,9 +57,7 @@ let Comp = { make: make }; let props = { b: "b" }; -let newrecord = { ...props }; - -; +; export { Comp, props }; ``` diff --git a/apps/docs/markdown-pages/docs/react/forwarding-refs.mdx b/apps/docs/markdown-pages/docs/react/forwarding-refs.mdx index 01c1d7b63..b93d55db6 100644 --- a/apps/docs/markdown-pages/docs/react/forwarding-refs.mdx +++ b/apps/docs/markdown-pages/docs/react/forwarding-refs.mdx @@ -125,9 +125,9 @@ let make = () => { ```js import * as React from "react"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; let make = React.forwardRef((props, ref) => @@ -174,9 +174,9 @@ export { FancyInput, make$1 as make }; ```jsx import * as React from "react"; -import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.mjs"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; let make = React.forwardRef((props, ref) => ( diff --git a/apps/docs/markdown-pages/docs/react/hooks-effect.mdx b/apps/docs/markdown-pages/docs/react/hooks-effect.mdx index a1ce61677..f749d5369 100644 --- a/apps/docs/markdown-pages/docs/react/hooks-effect.mdx +++ b/apps/docs/markdown-pages/docs/react/hooks-effect.mdx @@ -145,7 +145,7 @@ function Example(props) { let setCount = match[1]; let count = match[0]; React.useEffect(() => { - document.title = `You clicked ` + count.toString() + ` times!`; + document.title = `You clicked ${count.toString()} times!`; }); let onClick = (_evt) => setCount((prev) => (prev + 1) | 0); let msg = "You clicked" + count.toString() + "times"; @@ -173,7 +173,7 @@ function Example(props) { let setCount = match[1]; let count = match[0]; React.useEffect(() => { - document.title = `You clicked ` + count.toString() + ` times!`; + document.title = `You clicked ${count.toString()} times!`; }); let onClick = (_evt) => setCount((prev) => (prev + 1) | 0); let msg = "You clicked" + count.toString() + "times"; diff --git a/apps/docs/markdown-pages/docs/react/hooks-overview.mdx b/apps/docs/markdown-pages/docs/react/hooks-overview.mdx index 55c7626ee..62d078e60 100644 --- a/apps/docs/markdown-pages/docs/react/hooks-overview.mdx +++ b/apps/docs/markdown-pages/docs/react/hooks-overview.mdx @@ -38,7 +38,7 @@ let make = () => { setCount(prev => prev + 1) } - let msg = "You clicked" ++ Belt.Int.toString(count) ++ "times" + let msg = "You clicked" ++ Int.toString(count) ++ "times"

{React.string(msg)}

@@ -55,7 +55,7 @@ function Example(props) { let match = React.useState(() => 0); let setCount = match[1]; let onClick = (_evt) => setCount((prev) => (prev + 1) | 0); - let msg = "You clicked" + String(match[0]) + "times"; + let msg = "You clicked" + match[0].toString() + "times"; return JsxRuntime.jsxs("div", { children: [ JsxRuntime.jsx("p", { children: msg }), @@ -77,7 +77,7 @@ function Example(props) { let match = React.useState(() => 0); let setCount = match[1]; let onClick = (_evt) => setCount((prev) => (prev + 1) | 0); - let msg = "You clicked" + String(match[0]) + "times"; + let msg = "You clicked" + match[0].toString() + "times"; return (

{msg}

diff --git a/apps/docs/markdown-pages/docs/react/hooks-reducer.mdx b/apps/docs/markdown-pages/docs/react/hooks-reducer.mdx index 4a39ddf79..e232ed274 100644 --- a/apps/docs/markdown-pages/docs/react/hooks-reducer.mdx +++ b/apps/docs/markdown-pages/docs/react/hooks-reducer.mdx @@ -64,7 +64,7 @@ let make = () => { let (state, dispatch) = React.useReducer(reducer, {count: 0}) <> - {React.string("Count:" ++ Belt.Int.toString(state.count))} + {React.string("Count:" ++ Int.toString(state.count))} @@ -88,7 +88,7 @@ function Example(props) { let dispatch = match[1]; return JsxRuntime.jsxs(JsxRuntime.Fragment, { children: [ - "Count:" + String(match[0].count), + "Count:" + match[0].count.toString(), JsxRuntime.jsx("button", { children: "-", onClick: (param) => dispatch("Dec"), @@ -123,7 +123,7 @@ function Example(props) { let dispatch = match[1]; return ( <> - {"Count:" + String(match[0].count)} + {"Count:" + match[0].count.toString()} @@ -176,7 +176,7 @@ let reducer = (state, action) => let todos = Array.filter(state.todos, todo => todo.id !== id) {...state, todos: todos} | ToggleTodo(id) => - let todos = Belt.Array.map(state.todos, todo => + let todos = Array.map(state.todos, todo => if todo.id === id { { ...todo, @@ -198,7 +198,7 @@ let make = () => { {todos: initialTodos, nextId: 2}, ) - let todos = Belt.Array.map(state.todos, todo => + let todos = Array.map(state.todos, todo =>
  • {React.string(todo.content)} @@ -437,7 +435,7 @@ function Example(props) { let dispatch = match[1]; return JsxRuntime.jsxs(JsxRuntime.Fragment, { children: [ - "Count:" + String(match[0].count), + "Count:" + match[0].count.toString(), JsxRuntime.jsx("button", { children: "-", onClick: (param) => dispatch("Dec"), @@ -480,7 +478,7 @@ function Example(props) { let dispatch = match[1]; return ( <> - {"Count:" + String(match[0].count)} + {"Count:" + match[0].count.toString()} diff --git a/apps/docs/markdown-pages/docs/react/hooks-ref.mdx b/apps/docs/markdown-pages/docs/react/hooks-ref.mdx index aee8623ec..df1f73d68 100644 --- a/apps/docs/markdown-pages/docs/react/hooks-ref.mdx +++ b/apps/docs/markdown-pages/docs/react/hooks-ref.mdx @@ -72,8 +72,8 @@ let make = () => { ```js import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -103,8 +103,8 @@ export { make }; ```jsx import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -162,8 +162,8 @@ let make = () => { ```js import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -197,8 +197,8 @@ export { make }; ```jsx import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { diff --git a/apps/docs/markdown-pages/docs/react/memo.mdx b/apps/docs/markdown-pages/docs/react/memo.mdx index 2fa475e29..bba90dab8 100644 --- a/apps/docs/markdown-pages/docs/react/memo.mdx +++ b/apps/docs/markdown-pages/docs/react/memo.mdx @@ -128,7 +128,7 @@ export { make }; -Another approach is to use a custom prop type and remove the `@react.component` annotation. +Another approach is to use a custom props type and wrap the function with `React.component`. @@ -139,11 +139,11 @@ type props = { } let make = React.memoCustomCompareProps( - ({disabled, onClick}) => { + React.component(({disabled, onClick}: props) => { - }, + }), (p1, p2) => p1.disabled == p2.disabled, ) ``` diff --git a/apps/docs/markdown-pages/docs/react/refs-and-the-dom.mdx b/apps/docs/markdown-pages/docs/react/refs-and-the-dom.mdx index 96e861194..68f691c2a 100644 --- a/apps/docs/markdown-pages/docs/react/refs-and-the-dom.mdx +++ b/apps/docs/markdown-pages/docs/react/refs-and-the-dom.mdx @@ -109,7 +109,7 @@ let make = () => { ```js import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -144,7 +144,7 @@ export { make }; ```jsx import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -203,7 +203,7 @@ let make = () => { ```js import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$MyComp(props) { @@ -224,7 +224,7 @@ export { MyComp, make }; ```jsx import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$MyComp(props) { @@ -293,8 +293,8 @@ let make = () => { ```js import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -328,8 +328,8 @@ export { make }; ```jsx import * as React from "react"; -import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.js"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Stdlib_Nullable from "@rescript/runtime/lib/es6/Stdlib_Nullable.mjs"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example(props) { @@ -394,7 +394,7 @@ let make = () => { ```js import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$CustomTextInput(props) { @@ -423,7 +423,7 @@ export { CustomTextInput, make }; ```jsx import * as React from "react"; -import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js"; +import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.mjs"; import * as JsxRuntime from "react/jsx-runtime"; function Example$CustomTextInput(props) { diff --git a/apps/docs/markdown-pages/syntax-lookup/decorator_deriving.mdx b/apps/docs/markdown-pages/syntax-lookup/decorator_deriving.mdx index d658ea8e2..2313ed19c 100644 --- a/apps/docs/markdown-pages/syntax-lookup/decorator_deriving.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/decorator_deriving.mdx @@ -6,46 +6,55 @@ summary: "This is the `@deriving` decorator." category: "decorators" --- -When the `@deriving` decorator is applied to a **record** type, -it expands the type into a factory function plus a set of -getter/setter functions for its fields. +Use `@deriving(accessors)` on a record type to generate functions that read its fields. -> Note that this is an outdated decorator and you may no longer need to use it. -> See [Convert Record Type to Abstract Record](../docs/manual/generate-converters-accessors.mdx#convert-record-type-to-abstract-record) for more details. +The old `@deriving(abstract)` form was removed in v13. Use ordinary records and record literals for JavaScript objects, including optional fields and mutable fields when needed. ### Example ```res -@deriving(abstract) +@deriving(accessors) type person = { name: string, age: int, job: string, } -let joe = person(~name="Joe", ~age=20, ~job="teacher") +let joe = {name: "Joe", age: 20, job: "teacher"} -let joeName = nameGet(joe) -let joeAge = ageGet(joe) -let joeJob = jobGet(joe) +let joeName = name(joe) +let joeAge = age(joe) +let joeJob = job(joe) ``` ```js +function name(param) { + return param.name; +} + +function age(param) { + return param.age; +} + +function job(param) { + return param.job; +} + let joe = { name: "Joe", age: 20, job: "teacher" }; -let joeName = joe.name; +let joeName = "Joe"; -let joeAge = joe.age; +let joeAge = 20; -let joeJob = joe.job; +let joeJob = "teacher"; -export { joe, joeName, joeAge, joeJob }; +export { name, age, job, joe, joeName, joeAge, joeJob }; ``` ### References -- [Convert Record Type to Abstract Record](../docs/manual/generate-converters-accessors.mdx#convert-record-type-to-abstract-record) +- [Generate Field Accessors for Records](../docs/manual/generate-converters-accessors.mdx#generate-field-accessors-for-records) diff --git a/apps/docs/markdown-pages/syntax-lookup/decorator_taggedTemplate.mdx b/apps/docs/markdown-pages/syntax-lookup/decorator_taggedTemplate.mdx index 17300a742..6b5355ccc 100644 --- a/apps/docs/markdown-pages/syntax-lookup/decorator_taggedTemplate.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/decorator_taggedTemplate.mdx @@ -2,13 +2,14 @@ id: "taggedTemplate-decorator" keywords: ["taggedTemplate", "tagged", "template", "decorator"] name: "@taggedTemplate" -summary: "This is the `@taggedTemplate` decorator." +summary: "The removed decorator for binding JavaScript tag functions; use `taggedTemplate` instead." category: "decorators" +status: "deprecated" --- **Since 11.1** -The `@taggedTemplate` decorator is used to bind to JavaScript tag functions. +The `@taggedTemplate` decorator was removed in v13. Bind JavaScript tag functions with the built-in `taggedTemplate<'param, 'output>` type instead. ### Example @@ -17,8 +18,8 @@ The `@taggedTemplate` decorator is used to bind to JavaScript tag functions. ```res example // see https://bun.sh/docs/runtime/shell type result = {exitCode: int} -@module("bun") @taggedTemplate -external sh: (array, array) => promise = "$" +@module("bun") +external sh: taggedTemplate> = "$" let filename = "index.res" let result = await sh`ls ${filename}` diff --git a/apps/docs/markdown-pages/syntax-lookup/extension_regular_expression.mdx b/apps/docs/markdown-pages/syntax-lookup/extension_regular_expression.mdx index c1dd0efe8..8123b2a0c 100644 --- a/apps/docs/markdown-pages/syntax-lookup/extension_regular_expression.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/extension_regular_expression.mdx @@ -7,14 +7,14 @@ category: "extensionpoints" status: "deprecated" --- -> Deprecated in favor of native regular expression syntax in v12+ +> `%re` was removed in v13. Use a regular expression literal instead. -`%re` is used to create JavaScript regular expressions. +Regular expression literals create JavaScript regular expressions directly: ```res -let regex = %re("/^hello/") +let regex = /^hello/ let result = regex->RegExp.test("hello world") ``` diff --git a/apps/docs/markdown-pages/syntax-lookup/extension_todo.mdx b/apps/docs/markdown-pages/syntax-lookup/extension_todo.mdx index 036b00b23..023186998 100644 --- a/apps/docs/markdown-pages/syntax-lookup/extension_todo.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/extension_todo.mdx @@ -21,7 +21,7 @@ Console.log(x->String.includes("x")) ``` ```js -import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.js"; +import * as Stdlib_JsError from "@rescript/runtime/lib/es6/Stdlib_JsError.mjs"; function implementMeLater() { return Stdlib_JsError.throwWithMessage( diff --git a/apps/docs/markdown-pages/syntax-lookup/language_async.mdx b/apps/docs/markdown-pages/syntax-lookup/language_async.mdx index fb435b0ee..4e3595119 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_async.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_async.mdx @@ -33,8 +33,8 @@ let logUserDetails = async (userId: string) => { ```js async function logUserDetails(userId) { let email = await GlobalAPI.fetchUserMail(userId); - await GlobalAPI.sendAnalytics(`User details have been logged for ` + userId); - console.log(`Email address for user ` + userId + `: ` + email); + await GlobalAPI.sendAnalytics(`User details have been logged for ${userId}`); + console.log(`Email address for user ${userId}: ${email}`); } export { logUserDetails }; diff --git a/apps/docs/markdown-pages/syntax-lookup/language_exception.mdx b/apps/docs/markdown-pages/syntax-lookup/language_exception.mdx index ffa8dabcb..acdffbfb6 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_exception.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_exception.mdx @@ -23,7 +23,7 @@ let message = try { ``` ```js -import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js"; +import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.mjs"; let NotFound = /* @__PURE__ */ Primitive_exceptions.create("Example.NotFound"); diff --git a/apps/docs/markdown-pages/syntax-lookup/language_include.mdx b/apps/docs/markdown-pages/syntax-lookup/language_include.mdx index fa414a8a6..965c24915 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_include.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_include.mdx @@ -31,7 +31,7 @@ let greeting = "Hello"; let Message = { greeting: greeting }; function greet(name) { - return greeting + " " + name; + return "Hello " + name; } let Greeter = { greeting: greeting, greet: greet }; diff --git a/apps/docs/markdown-pages/syntax-lookup/language_string_interpolation.mdx b/apps/docs/markdown-pages/syntax-lookup/language_string_interpolation.mdx index a644fa18a..0c0d76257 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_string_interpolation.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_string_interpolation.mdx @@ -24,9 +24,7 @@ Right? ```js let language = "ReScript"; -let exclamation = - language + - ` is pretty cool. +let exclamation = `${language} is pretty cool. Right? 🎉 `; diff --git a/apps/docs/markdown-pages/syntax-lookup/language_while.mdx b/apps/docs/markdown-pages/syntax-lookup/language_while.mdx index a2a3d838a..74b2159cb 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_while.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_while.mdx @@ -8,18 +8,18 @@ category: "languagecontrolflow" ReScript supports `while` loops. While loops execute its body code block while its condition is true. -ReScript does not have the `break` keyword, but you can easily break out of a while loop by using a mutable binding. +A mutable binding can control whether a while loop continues. ### Example ```res -let break = ref(false) +let shouldStop = ref(false) -while !break.contents { +while !shouldStop.contents { if Math.random() > 0.3 { - break := true + shouldStop := true } else { Console.log("Still running") } @@ -28,17 +28,17 @@ while !break.contents { ``` ```js -let $$break = { contents: false }; +let shouldStop = { contents: false }; -while (!$$break.contents) { +while (!shouldStop.contents) { if (Math.random() > 0.3) { - $$break.contents = true; + shouldStop.contents = true; } else { console.log("Still running"); } } -export { $$break }; +export { shouldStop }; ``` diff --git a/apps/docs/markdown-pages/syntax-lookup/operators_integer_addition.mdx b/apps/docs/markdown-pages/syntax-lookup/operators_integer_addition.mdx index 1be9e6040..9dfe0be82 100644 --- a/apps/docs/markdown-pages/syntax-lookup/operators_integer_addition.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/operators_integer_addition.mdx @@ -20,10 +20,10 @@ let stringResult = "Re" + "Script" ```js let floatResult = 1.5 + 2.5; -let stringResult = "ReScript"; - let intResult = 3; +let stringResult = "ReScript"; + export { intResult, floatResult, stringResult }; ``` diff --git a/apps/docs/markdown-pages/syntax-lookup/operators_pipe.mdx b/apps/docs/markdown-pages/syntax-lookup/operators_pipe.mdx index 8cc325e62..39adfad9d 100644 --- a/apps/docs/markdown-pages/syntax-lookup/operators_pipe.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/operators_pipe.mdx @@ -25,7 +25,7 @@ let message = dieRoll(6)->dieRollMessage("Marshall") ``` ```js -import * as Stdlib_Math from "@rescript/runtime/lib/es6/Stdlib_Math.js"; +import * as Stdlib_Math from "@rescript/runtime/lib/es6/Stdlib_Math.mjs"; function dieRoll(size) { return Stdlib_Math.Int.random(1, size); @@ -63,7 +63,7 @@ String.toUpperCase("example message")->logMsg(user, datestr, _) ```js function logMsg(user, datestr, msg) { - console.log(user + `|` + datestr + `|` + msg); + console.log(`${user}|${datestr}|${msg}`); } let datestr = "01-01-2021"; diff --git a/apps/docs/markdown-pages/syntax-lookup/operators_type_coercion.mdx b/apps/docs/markdown-pages/syntax-lookup/operators_type_coercion.mdx index a4014ed0e..2cbd8cedb 100644 --- a/apps/docs/markdown-pages/syntax-lookup/operators_type_coercion.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/operators_type_coercion.mdx @@ -43,7 +43,7 @@ let message = "The color is " ++ (color :> string) ``` ```js -let message = "The color is " + "Red"; +let message = "The color is Red"; let color = "Red"; From 32bb0cc6f91699700787e3f1929471a9c4fc18cc Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 31 Oct 2026 22:20:32 -0300 Subject: [PATCH 2/6] Disable check:dead-code for now --- .github/workflows/pull-request.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 5ea4b01ce..53477c9cf 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -43,8 +43,9 @@ jobs: run: yarn ci:generated - name: Test examples and hrefs run: yarn test - - name: Check unused ReScript values and exports - run: yarn check:dead-code + # Disable for now. Reanalyze report wrong dead code. + # - name: Check unused ReScript values and exports + # run: yarn check:dead-code - name: Test dead-code diagnostics run: node --test scripts/__tests__/check-dead-code.test.mjs # Check the built Docs Pages routes and the Guide local dev server. From 1a6d9ee2086a360d1414e55e07b631a0aa615dc6 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 1 Nov 2026 13:02:52 -0300 Subject: [PATCH 3/6] Add docs for break, continue, for of and for await of --- .../docs/manual/async-await.mdx | 28 ++++ .../docs/manual/control-flow.mdx | 121 +++++++++++++++--- 2 files changed, 129 insertions(+), 20 deletions(-) diff --git a/apps/docs/markdown-pages/docs/manual/async-await.mdx b/apps/docs/markdown-pages/docs/manual/async-await.mdx index 4210c0daa..73c7a522e 100644 --- a/apps/docs/markdown-pages/docs/manual/async-await.mdx +++ b/apps/docs/markdown-pages/docs/manual/async-await.mdx @@ -126,6 +126,34 @@ let fetchData = async (userId: string): string => { } ``` +## For Await Of + +Inside an `async` function, use `for await of` to consume an `asyncIterable<'a>`. Each iteration waits for the next value before running the loop body: + + + +```res +let printMessages = async (messages: asyncIterable) => { + for await message of messages { + Console.log(message) + } +} +``` + +```js +async function printMessages(messages) { + for await (let message of messages) { + console.log(message); + } +} + +export { printMessages }; +``` + + + +Use [`for of`](./control-flow.mdx#forof-loops) for ordinary arrays and synchronous iterables; `for await of` expects an async iterable. You can use [`break` and `continue`](./control-flow.mdx#break--continue) to exit the loop early or skip to the next iteration. + ## Error handling You may use `try / catch` or `switch` to handle exceptions during async execution. diff --git a/apps/docs/markdown-pages/docs/manual/control-flow.mdx b/apps/docs/markdown-pages/docs/manual/control-flow.mdx index 0ac4da5bb..7d5dfee77 100644 --- a/apps/docs/markdown-pages/docs/manual/control-flow.mdx +++ b/apps/docs/markdown-pages/docs/manual/control-flow.mdx @@ -1,6 +1,6 @@ --- title: "If-Else & Loops" -description: "If, else, ternary, for, and while" +description: "If, else, ternary, for, for...of, while, break, and continue" canonical: "/docs/manual/control-flow" section: "Language Features" order: 14 @@ -21,7 +21,7 @@ order: 14
  • -ReScript supports `if`, `else`, ternary expression (`a ? b : c`), `for` and `while`. +ReScript supports `if`, `else`, ternary expressions (`a ? b : c`), numeric `for` loops, `for of`, and `while`. Use `break` to exit a loop early and `continue` to skip to its next iteration. The `switch` pattern supports a default case. Read more about [pattern-matching & destructuring](./pattern-matching-destructuring.mdx). @@ -115,7 +115,7 @@ export { message }; ## For Loops -For loops iterate from a starting value up to (and including) the ending value. +Numeric `for` loops iterate over integers from a starting value up to (and including) the ending value. The loop variable is local to the loop body. @@ -185,9 +185,98 @@ for (let x = 3; x >= 1; --x) { +## For Of Loops + +Use `for of` to visit each value in an array or an `iterable<'a>`, without managing an index: + + + +```res +let names = ["Ada", "Grace", "Margaret"] + +for name of names { + Console.log(name) +} +``` + +```js +let names = ["Ada", "Grace", "Margaret"]; + +for (let name of names) { + console.log(name); +} + +export { names }; +``` + + + +The loop binding must be a variable name or `_`. To destructure a value, do so inside the loop body: + + + +```res +for entry of [("Ada", 36), ("Grace", 85)] { + let (name, age) = entry + Console.log(`${name}: ${age->Int.toString}`) +} +``` + +```js +for (let entry of [ + ["Ada", 36], + ["Grace", 85], +]) { + console.log(`${entry[0]}: ${entry[1].toString()}`); +} +``` + + + +For asynchronous iteration, see [For Await Of](./async-await.mdx#for-awaitof). + +## Break & Continue + +`break` exits the nearest enclosing loop immediately. `continue` skips the rest of the current iteration and starts the next one. Both work in numeric `for`, `for of`, `for await of`, and `while` loops. + + + +```res +// Prints 1 and 3 +for number in 1 to 5 { + if number == 2 { + continue + } + if number == 4 { + break + } + Console.log(number) +} +``` + +```js +for (let number = 1; number <= 5; ++number) { + if (number === 2) { + continue; + } + if (number === 4) { + break; + } + console.log(number); +} +``` + + + +In a numeric `for` loop, `continue` still advances the loop variable. In a `while` loop, it rechecks the condition, so make sure any necessary updates happen before `continue`. + +You can also use `break` and `continue` inside a `switch` within a loop: they target the loop, not the `switch`. They cannot be used outside a loop or from a nested function to control an outer loop. + +`break` and `continue` are reserved keywords, so they cannot be used as ordinary variable names. + ## While Loops -While loops execute its body code block while its condition is true. +While loops execute their body while the condition is true. The condition is checked before each iteration, so the body may never run. @@ -205,36 +294,28 @@ while (testCondition) { -### Tips & Tricks +### Exiting Early -A [mutable binding](./mutation.mdx) can control whether a while loop continues: +Use `break` when the stopping condition is discovered inside the loop. There is no need for a separate mutable stop flag: ```res -let shouldStop = ref(false) - -while !shouldStop.contents { +while true { if Math.random() > 0.3 { - shouldStop := true - } else { - Console.log("Still running") + break } + Console.log("Still running") } ``` ```js -let shouldStop = { contents: false }; - -while (!shouldStop.contents) { +while (true) { if (Math.random() > 0.3) { - shouldStop.contents = true; - } else { - console.log("Still running"); + break; } + console.log("Still running"); } - -export { shouldStop }; ``` From 5c65729481c2229dcdb8958aec006eba8ea195f8 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 1 Nov 2026 13:06:41 -0300 Subject: [PATCH 4/6] Add dictionary-spread examples, including how later entries override earlier keys --- apps/docs/markdown-pages/docs/manual/dict.mdx | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/apps/docs/markdown-pages/docs/manual/dict.mdx b/apps/docs/markdown-pages/docs/manual/dict.mdx index b30653dd1..ef316f8fb 100644 --- a/apps/docs/markdown-pages/docs/manual/dict.mdx +++ b/apps/docs/markdown-pages/docs/manual/dict.mdx @@ -42,6 +42,93 @@ A few things to note here: - Using the first class `dict{}` syntax compiles cleanly to a JavaScript object directly - Using `Dict.fromArray` is useful when you need to create a dictionary programatically +## Copying and merging with spreads + +Use `...` inside `dict{}` to copy entries from an existing dictionary into a new one: + + + +```res +let original = dict{"apples": 2, "oranges": 3} +let copy = dict{...original, "bananas": 4} + +// Updating the copy does not change the original dictionary +copy->Dict.set("apples", 5) +Console.log(original->Dict.get("apples")) // Some(2) +Console.log(copy->Dict.get("apples")) // Some(5) +``` + +```js +let d = { A: 5, B: 6 }; + +let d2 = Object.fromEntries([ + ["A", 5], + ["B", 6], +]); + +let original = { apples: 2, oranges: 3 }; + +let copy = Object.assign({}, original, { bananas: 4 }); + +copy["apples"] = 5; + +console.log(original["apples"]); + +console.log(copy["apples"]); + +export { d, d2, original, copy }; +``` + + + +You can mix multiple spreads and explicit entries. Entries are applied from left to right: when a key appears more than once, the later value wins. This applies to both explicit entries and entries from a spread: + + + +```res +let defaults = dict{"retries": 3, "timeout": 1000} +let overrides = dict{"timeout": 5000, "retries": 5} + +let settings = dict{ + ...defaults, + "timeout": 2000, + ...overrides, + "retries": 1, +} + +// The later spread overrides the earlier explicit timeout +Console.log(settings->Dict.get("timeout")) // Some(5000) +// The final explicit entry overrides both spreads +Console.log(settings->Dict.get("retries")) // Some(1) +``` + +```js +let d = { A: 5, B: 6 }; + +let d2 = Object.fromEntries([ + ["A", 5], + ["B", 6], +]); + +let defaults = { retries: 3, timeout: 1000 }; + +let overrides = { timeout: 5000, retries: 5 }; + +let settings = Object.assign({}, defaults, { timeout: 2000 }, overrides, { + retries: 1, +}); + +console.log(settings["timeout"]); + +console.log(settings["retries"]); + +export { d, d2, defaults, overrides, settings }; +``` + + + +Spreads do not mutate their source dictionaries. They make a shallow copy: if a value is a mutable object, the new dictionary still refers to that same object. All values in the resulting dictionary must have the same type. + ## Access You can access values from a Dictionary either via the the standard library `Dict` module functions, or using pattern matching. From 15a23ae1b0ecd1f4322a6b3718411d34181bc92a Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 1 Nov 2026 13:27:36 -0300 Subject: [PATCH 5/6] Add record-rest patterns and explain that they collect fields not explicitly destructured --- .../markdown-pages/docs/manual/record.mdx | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/apps/docs/markdown-pages/docs/manual/record.mdx b/apps/docs/markdown-pages/docs/manual/record.mdx index 8580d4684..ee1663fe2 100644 --- a/apps/docs/markdown-pages/docs/manual/record.mdx +++ b/apps/docs/markdown-pages/docs/manual/record.mdx @@ -197,6 +197,96 @@ export { me, name }; +## Destructuring Record Rest + +You can destructure individual fields and capture the remaining fields as another record. Declare a type for the remaining fields, then use `...typeName as bindingName` in the pattern: + + + +```res +type contact = {name: string, email: string, active: bool} +type contactDetails = {email: string, active: bool} + +let contact = {name: "Ada", email: "ada@example.com", active: true} +let {name, ...contactDetails as details} = contact + +Console.log(name) // "Ada" +Console.log(details.email) // "ada@example.com" +``` + +```js +let contact = { name: "Ada", email: "ada@example.com", active: true }; + +let name = "Ada"; + +let { name: __unused0, ...details } = contact; + +console.log(name); + +console.log(details.email); + +let me = { age: 5, name: "Big ReScript" }; + +export { me, contact, details, name }; +``` + + + +Here, `contactDetails` is a type, while `details` is the new value containing `email` and `active`, but not `name`. Unlike JavaScript's `{name, ...details}`, ReScript requires the rest record type to be declared; it does not infer a new record type from the leftover fields. + +The rest type must describe the remaining fields with compatible types and optionality. You can use a type from another module, such as `...ContactDetails.t as details`. A pattern can contain only one rest element. + +Record rest patterns cannot be used on source records with `mutable` fields or with unboxed record types. + +### Pattern Matching and Function Parameters + +Record rest also works in `switch` cases and function parameter patterns: + + + +```res +type contact = {name: string, email: string, active: bool} +type contactDetails = {email: string, active: bool} + +let describeContact = (contact: contact) => { + switch contact { + | {name: "Ada", ...contactDetails as details} => + `Contact Ada at ${details.email}` + | {name, ...contactDetails as details} => + `Contact ${name} at ${details.email}` + } +} + +let getDetails = ({name: _, ...contactDetails as details}: contact) => details +``` + +```js +function describeContact(contact) { + let name = contact.name; + if (name === "Ada") { + let { name: __unused0, ...details } = contact; + return `Contact Ada at ${details.email}`; + } + let { name: __unused0$1, ...details$1 } = contact; + return `Contact ${name} at ${details$1.email}`; +} + +function getDetails(param) { + let { name: __unused0, ...rest } = param; + return rest; +} + +let me = { age: 5, name: "Big ReScript" }; + +export { me, describeContact, getDetails }; +``` + + + +In the first case, `name: "Ada"` matches a particular value. In the second, `name` binds any other name. Both cases capture the remaining fields in `details`. In `getDetails`, `name: _` excludes `name` without binding it. + +Record rest creates a new record without mutating the original. The copy is shallow: nested objects are still shared. This differs from [record type coercion](#record-type-coercion), which changes only the type and keeps the original value, and from [immutable update](#immutable-update), which creates a new value of the same record type. + ## Immutable Update New records can be created from old records with the `...` spread operator. The original record isn't mutated. From ab22189b0902ce9e9bd715a138e22085086d9142 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sun, 1 Nov 2026 14:01:42 -0300 Subject: [PATCH 6/6] update syntax lookup while --- .../syntax-lookup/language_while.mdx | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/apps/docs/markdown-pages/syntax-lookup/language_while.mdx b/apps/docs/markdown-pages/syntax-lookup/language_while.mdx index 74b2159cb..6fe6454e3 100644 --- a/apps/docs/markdown-pages/syntax-lookup/language_while.mdx +++ b/apps/docs/markdown-pages/syntax-lookup/language_while.mdx @@ -14,31 +14,23 @@ A mutable binding can control whether a while loop continues. -```res -let shouldStop = ref(false) - -while !shouldStop.contents { +```res nocheck +while true { if Math.random() > 0.3 { - shouldStop := true + break } else { Console.log("Still running") } } - ``` ```js -let shouldStop = { contents: false }; - -while (!shouldStop.contents) { +while (true) { if (Math.random() > 0.3) { - shouldStop.contents = true; - } else { - console.log("Still running"); + break; } + console.log("Still running"); } - -export { shouldStop }; ```