From 4b584ba63ac481673563dcbb27a662792849e8c3 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Sat, 21 Oct 2023 01:18:48 +0200 Subject: [PATCH 1/9] Adapt some pages to ReScript 11 including records and variants --- pages/docs/manual/latest/record.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/manual/latest/record.mdx b/pages/docs/manual/latest/record.mdx index b251d7aa4..53c114a9b 100644 --- a/pages/docs/manual/latest/record.mdx +++ b/pages/docs/manual/latest/record.mdx @@ -426,7 +426,7 @@ type c = { } ``` -Record type spreads act as a 'copy-paste' mechanism for fields from one or more records into a new record. This operation inlines the fields from the spread records directly into the new record definition, while preserving their original properties, such as whether they are optional or mandatory. It's important to note that duplicate field names are not allowed across the records being spread, even if the fields have the same type. +Record type spreads act as a 'copy-paste' mechanism for fields from one or more records into a new record. This operation inlines the fields from the spread records directly into the new record definition, while preserving their original properties, such as whether they are optional or mandatory. It's important to note that duplicate field names are not allowed across the records being spread, even if the fields share the same type. ## Record Type Coercion From 4030e7b6072fa064a7fecf8d87993e5580d25a93 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Sun, 22 Oct 2023 21:52:20 +0200 Subject: [PATCH 2/9] Some better wordings --- pages/docs/manual/latest/record.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/manual/latest/record.mdx b/pages/docs/manual/latest/record.mdx index 53c114a9b..b251d7aa4 100644 --- a/pages/docs/manual/latest/record.mdx +++ b/pages/docs/manual/latest/record.mdx @@ -426,7 +426,7 @@ type c = { } ``` -Record type spreads act as a 'copy-paste' mechanism for fields from one or more records into a new record. This operation inlines the fields from the spread records directly into the new record definition, while preserving their original properties, such as whether they are optional or mandatory. It's important to note that duplicate field names are not allowed across the records being spread, even if the fields share the same type. +Record type spreads act as a 'copy-paste' mechanism for fields from one or more records into a new record. This operation inlines the fields from the spread records directly into the new record definition, while preserving their original properties, such as whether they are optional or mandatory. It's important to note that duplicate field names are not allowed across the records being spread, even if the fields have the same type. ## Record Type Coercion From 0aac9bba9a62fa3228a489d520314910355cbff2 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Mon, 23 Oct 2023 23:57:54 +0200 Subject: [PATCH 3/9] Adapt example tests to Rescript11 + uncurried + RescriptCore --- compilers/package-lock.json | 55 +++++++++++++++++++ compilers/package.json | 4 +- compilers/rescript.json | 13 +++++ .../docs/manual/latest/api/belt/hash-map.mdx | 38 ++++++------- pages/docs/manual/latest/api/belt/map.mdx | 28 +++++----- .../manual/latest/api/belt/mutable-set.mdx | 2 +- pages/docs/manual/latest/api/belt/set.mdx | 2 +- pages/docs/manual/latest/api/js/re.mdx | 16 ++++-- pages/docs/manual/latest/exception.mdx | 2 +- .../latest/import-from-export-to-js.mdx | 2 +- pages/docs/manual/latest/lazy-values.mdx | 5 +- pages/docs/manual/latest/module.mdx | 2 +- .../latest/pattern-matching-destructuring.mdx | 4 +- scripts/test-examples.mjs | 28 +++++++++- 14 files changed, 152 insertions(+), 49 deletions(-) create mode 100644 compilers/rescript.json diff --git a/compilers/package-lock.json b/compilers/package-lock.json index 758506298..22c219d9c 100644 --- a/compilers/package-lock.json +++ b/compilers/package-lock.json @@ -9,13 +9,36 @@ "version": "1.0.0", "license": "MIT", "dependencies": { + "@rescript/core": "^0.5.0", "rescript-1000": "npm:rescript@10.0.0", "rescript-1010": "npm:rescript@10.1.0-rc.4", + "rescript-1100": "npm:rescript@11.0.0-rc.4", "rescript-820": "npm:bs-platform@8.2.0", "rescript-902": "npm:bs-platform@9.0.2", "rescript-912": "npm:rescript@9.1.2" } }, + "node_modules/@rescript/core": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@rescript/core/-/core-0.5.0.tgz", + "integrity": "sha512-Keqnpi+8VqyhCk/3aMwar8hJbNy2IsINAAfIFeQC65IIegCR0QXFDBpQxfVcmbbtoHq6HnW4B3RLm/9GCUJQhQ==", + "peerDependencies": { + "rescript": "^10.1.0 || ^11.0.0-alpha.0 || next" + } + }, + "node_modules/rescript": { + "version": "10.1.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.1.4.tgz", + "integrity": "sha512-FFKlS9AG/XrLepWsyw7B+A9DtQBPWEPDPDKghV831Y2KGbie+eeFBOS0xtRHp0xbt7S0N2Dm6hhX+kTZQ/3Ybg==", + "hasInstallScript": true, + "peer": true, + "bin": { + "bsc": "bsc", + "bsrefmt": "bsrefmt", + "bstracing": "lib/bstracing", + "rescript": "rescript" + } + }, "node_modules/rescript-1000": { "name": "rescript", "version": "10.0.0", @@ -42,6 +65,21 @@ "rescript": "rescript" } }, + "node_modules/rescript-1100": { + "name": "rescript", + "version": "11.0.0-rc.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.0.0-rc.4.tgz", + "integrity": "sha512-yh82o30J2/B/IwyPZjM+mc82FdyPkXRjXxlsUVEoyc5Z/snlq3Za2PhJhlfacwk+ui5lcOZsH8SndWPiI21vXg==", + "hasInstallScript": true, + "bin": { + "bsc": "bsc", + "bstracing": "lib/bstracing", + "rescript": "rescript" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/rescript-820": { "name": "bs-platform", "version": "8.2.0", @@ -69,6 +107,18 @@ } }, "dependencies": { + "@rescript/core": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/@rescript/core/-/core-0.5.0.tgz", + "integrity": "sha512-Keqnpi+8VqyhCk/3aMwar8hJbNy2IsINAAfIFeQC65IIegCR0QXFDBpQxfVcmbbtoHq6HnW4B3RLm/9GCUJQhQ==", + "requires": {} + }, + "rescript": { + "version": "10.1.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.1.4.tgz", + "integrity": "sha512-FFKlS9AG/XrLepWsyw7B+A9DtQBPWEPDPDKghV831Y2KGbie+eeFBOS0xtRHp0xbt7S0N2Dm6hhX+kTZQ/3Ybg==", + "peer": true + }, "rescript-1000": { "version": "npm:rescript@10.0.0", "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.0.0.tgz", @@ -79,6 +129,11 @@ "resolved": "https://registry.npmjs.org/rescript/-/rescript-10.1.0-rc.4.tgz", "integrity": "sha512-xvUfEKBs1U/WN1mFX8YipvNj7KUChX/ULvyb1TP2wSR2qgNrcRAy+dW7jc2F2tv0Qbrc47HEZi/1Ni0z3nVvmw==" }, + "rescript-1100": { + "version": "npm:rescript@11.0.0-rc.4", + "resolved": "https://registry.npmjs.org/rescript/-/rescript-11.0.0-rc.4.tgz", + "integrity": "sha512-yh82o30J2/B/IwyPZjM+mc82FdyPkXRjXxlsUVEoyc5Z/snlq3Za2PhJhlfacwk+ui5lcOZsH8SndWPiI21vXg==" + }, "rescript-820": { "version": "npm:bs-platform@8.2.0", "resolved": "https://registry.npmjs.org/bs-platform/-/bs-platform-8.2.0.tgz", diff --git a/compilers/package.json b/compilers/package.json index 5dc863069..e0d52a7f9 100644 --- a/compilers/package.json +++ b/compilers/package.json @@ -5,10 +5,12 @@ "main": "index.js", "license": "MIT", "dependencies": { + "@rescript/core": "^0.5.0", "rescript-820": "npm:bs-platform@8.2.0", "rescript-902": "npm:bs-platform@9.0.2", "rescript-912": "npm:rescript@9.1.2", "rescript-1000": "npm:rescript@10.0.0", - "rescript-1010": "npm:rescript@10.1.0-rc.4" + "rescript-1010": "npm:rescript@10.1.0-rc.4", + "rescript-1100": "npm:rescript@11.0.0-rc.4" } } diff --git a/compilers/rescript.json b/compilers/rescript.json new file mode 100644 index 000000000..53fd7f5ef --- /dev/null +++ b/compilers/rescript.json @@ -0,0 +1,13 @@ +{ + "name": "dummy", + "sources": { + "dir": "dummy", + "subdirs": true + }, + "bs-dependencies": [ + "@rescript/core" + ], + "bsc-flags": [ + "-open RescriptCore" + ] +} \ No newline at end of file diff --git a/pages/docs/manual/latest/api/belt/hash-map.mdx b/pages/docs/manual/latest/api/belt/hash-map.mdx index 36a8de539..906ebb3ff 100644 --- a/pages/docs/manual/latest/api/belt/hash-map.mdx +++ b/pages/docs/manual/latest/api/belt/hash-map.mdx @@ -31,7 +31,7 @@ let make: (~hintSize: int, ~id: id<'key, 'id>) => t<'key, 'value, 'id> `make(~hintSize=10, ~id)` creates a new map by taking in the comparator and `hintSize`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -51,7 +51,7 @@ let clear: t<'key, 'value, 'id> => unit Clears a hash table. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -71,7 +71,7 @@ let isEmpty: t<'a, 'b, 'c> => bool `isEmpty(m)` checks whether a hash map is empty. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -89,7 +89,7 @@ let set: (t<'key, 'value, 'id>, 'key, 'value) => unit `set(hMap, k, v)` if `k` does not exist, add the binding `k,v`, otherwise, update the old value with the new `v`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -111,7 +111,7 @@ let copy: t<'key, 'value, 'id> => t<'key, 'value, 'id> Creates copy of a hash map. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -134,7 +134,7 @@ let get: (t<'key, 'value, 'id>, 'key) => option<'value> Returns value bound under specific key. If values not exist returns `None`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -156,7 +156,7 @@ let has: (t<'key, 'value, 'id>, 'key) => bool Checks if `x` is bound in `tbl`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -178,7 +178,7 @@ let remove: (t<'key, 'value, 'id>, 'key) => unit If bound exists, removes it from the hash map. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -207,7 +207,7 @@ let forEach: (t<'key, 'value, 'id>, ('key, 'value) => unit) => unit `forEach(tbl, f)` applies `f` to all bindings in table `tbl`. `f` receives the key as first argument, and the associated value as second argument. Each binding is presented exactly once to `f`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -238,7 +238,7 @@ let reduce: (t<'key, 'value, 'id>, 'c, ('c, 'key, 'value) => 'c) => 'c The order in which the bindings are passed to `f` is unspecified. However, if the table contains several bindings for the same key, they are passed to `f` in reverse order of introduction, that is, the most recent binding is passed first. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -268,7 +268,7 @@ let keepMapInPlace: (t<'key, 'value, 'id>, ('key, 'value) => option<'value>) => Filters out values for which function `f` returned `None`. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -290,7 +290,7 @@ let size: t<'a, 'b, 'c> => int `size(tbl)` returns the number of bindings in `tbl`. It takes constant time. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -312,7 +312,7 @@ let toArray: t<'key, 'value, 'id> => array<('key, 'value)> Returns array of key value pairs. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -334,7 +334,7 @@ let keysToArray: t<'key, 'a, 'b> => array<'key> Returns array of keys. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -356,7 +356,7 @@ let valuesToArray: t<'a, 'value, 'b> => array<'value> Returns array of values. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -380,7 +380,7 @@ Creates new hash map from array of pairs. Returns array of values. ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -397,7 +397,7 @@ let mergeMany: (t<'key, 'value, 'id>, array<('key, 'value)>) => unit ``` ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -414,7 +414,7 @@ let getBucketHistogram: t<'a, 'b, 'c> => array ``` ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b @@ -432,7 +432,7 @@ let logStats: t<'a, 'b, 'c> => unit ``` ```res example -module IntHash = Belt.Id.MakeHashable({ +module IntHash = Belt.Id.MakeHashableU({ type t = int let hash = a => a let eq = (a, b) => a == b diff --git a/pages/docs/manual/latest/api/belt/map.mdx b/pages/docs/manual/latest/api/belt/map.mdx index ba31ca263..7ab76f666 100644 --- a/pages/docs/manual/latest/api/belt/map.mdx +++ b/pages/docs/manual/latest/api/belt/map.mdx @@ -33,7 +33,7 @@ let make: (~id: id<'k, 'id>) => t<'k, 'v, 'id> `make(~id)` creates a new map by taking in the comparator. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -52,7 +52,7 @@ let isEmpty: t<'a, 'b, 'c> => bool `isEmpty(m)` checks whether a map m is empty. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -69,7 +69,7 @@ let has: (t<'k, 'v, 'id>, 'k) => bool `has(m, k)` checks whether `m` has the key `k`. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -124,7 +124,7 @@ let findFirstBy: (t<'k, 'v, 'id>, ('k, 'v) => bool) => option<('k, 'v)> `findFirstBy(m, p)` uses function `f` to find the first key value pair to match predicate `p`. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -149,7 +149,7 @@ let forEach: (t<'k, 'v, 'id>, ('k, 'v) => unit) => unit `forEach(m, f)` applies `f` to all bindings in map `m`. `f` receives the `'k` as first argument, and the associated value as second argument. The bindings are passed to `f` in increasing order with respect to the ordering over the type of the keys. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -178,7 +178,7 @@ let reduce: (t<'k, 'v, 'id>, 'acc, ('acc, 'k, 'v) => 'acc) => 'acc `reduce(m, a, f)` computes `(f(kN, dN) ... (f(k1, d1, a))...)`, where `k1 ... kN` are the keys of all bindings in m (in increasing order), and `d1 ... dN` are the associated data. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -228,7 +228,7 @@ let size: t<'k, 'v, 'id> => int `size(s)` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -245,7 +245,7 @@ let toArray: t<'k, 'v, 'id> => array<('k, 'v)> `toArray(s)` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -276,7 +276,7 @@ let fromArray: (array<('k, 'v)>, ~id: id<'k, 'id>) => t<'k, 'v, 'id> `fromArray(kvs, ~id);` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -297,7 +297,7 @@ let keysToArray: t<'k, 'v, 'id> => array<'k> `keysToArray(s);` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -318,7 +318,7 @@ let valuesToArray: t<'k, 'v, 'id> => array<'v> `valuesToArray(s);` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -401,7 +401,7 @@ let get: (t<'k, 'v, 'id>, 'k) => option<'v> `get(s, k)` ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -455,7 +455,7 @@ let remove: (t<'k, 'v, 'id>, 'k) => t<'k, 'v, 'id> `remove(m, x)` when `x` is not in `m`, `m` is returned reference unchanged. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) @@ -490,7 +490,7 @@ let set: (t<'k, 'v, 'id>, 'k, 'v) => t<'k, 'v, 'id> `set(m, x, y)` returns a map containing the same bindings as `m`, with a new binding of `x` to `y`. If `x` was already bound in `m`, its previous binding disappears. ```res example -module IntCmp = Belt.Id.MakeComparable({ +module IntCmp = Belt.Id.MakeComparableU({ type t = int let cmp = (a, b) => Pervasives.compare(a, b) }) diff --git a/pages/docs/manual/latest/api/belt/mutable-set.mdx b/pages/docs/manual/latest/api/belt/mutable-set.mdx index 371f04de0..d379a691a 100644 --- a/pages/docs/manual/latest/api/belt/mutable-set.mdx +++ b/pages/docs/manual/latest/api/belt/mutable-set.mdx @@ -10,7 +10,7 @@ It also has three specialized inner modules [Belt.MutableSet.Int](mutable-set-in ```res example -module PairComparator = Belt.Id.MakeComparable({ +module PairComparator = Belt.Id.MakeComparableU({ type t = (int, int) let cmp = ((a0, a1), (b0, b1)) => switch Pervasives.compare(a0, b0) { diff --git a/pages/docs/manual/latest/api/belt/set.mdx b/pages/docs/manual/latest/api/belt/set.mdx index 173cdd865..f2b11edc4 100644 --- a/pages/docs/manual/latest/api/belt/set.mdx +++ b/pages/docs/manual/latest/api/belt/set.mdx @@ -11,7 +11,7 @@ It also has three specialized inner modules [Belt.Set.Int](set-int), [Belt.Set.S ```res example module PairComparator = - Belt.Id.MakeComparable({ + Belt.Id.MakeComparableU({ type t = (int, int) let cmp = ((a0, a1), (b0, b1)) => switch (Pervasives.compare(a0, b0)) { diff --git a/pages/docs/manual/latest/api/js/re.mdx b/pages/docs/manual/latest/api/js/re.mdx index 665eb7a2d..8151d4a03 100644 --- a/pages/docs/manual/latest/api/js/re.mdx +++ b/pages/docs/manual/latest/api/js/re.mdx @@ -68,7 +68,7 @@ Regex literals `%re("/.../")` should generally be preferred, but `fromString` is let firstReScriptFileExtension = (filename, content) => { let result = Js.Re.fromString(filename ++ "\.(res|resi)")->Js.Re.exec_(content) switch result { - | Some(r) => Js.Nullable.toOption(Js.Re.captures(r)[1]) + | Some(r) => Js.Re.captures(r)[1] | None => None } } @@ -134,10 +134,16 @@ let str = "abbcdefabh" let break = ref(false) while !break.contents { switch Js.Re.exec_(re, str) { - | Some(result) => Js.Nullable.iter(Js.Re.captures(result)[0], (. match_) => { - let next = Belt.Int.toString(Js.Re.lastIndex(re)) - Js.log("Found " ++ (match_ ++ (". Next match starts at " ++ next))) - }) + | Some(result) => + Js.Nullable.iter( + Js.Re.captures(result)[0]->Js.Nullable.fromOption, + (. match_) => { + let next = Belt.Int.toString(Js.Re.lastIndex(re)) + let matchStr = + match_->Js.Nullable.toOption->Belt.Option.getWithDefault("") + Js.log("Found " ++ (matchStr ++ (". Next match starts at " ++ next))) + }, + ) | None => break := true } } diff --git a/pages/docs/manual/latest/exception.mdx b/pages/docs/manual/latest/exception.mdx index 56a806e79..5635d99c2 100644 --- a/pages/docs/manual/latest/exception.mdx +++ b/pages/docs/manual/latest/exception.mdx @@ -65,7 +65,7 @@ You can directly match on exceptions _while_ getting another return value from a ```res prelude -switch List.find(i => i === 4, list{1, 2, 3}) { +switch list{1, 2, 3}->List.getExn(4) { | item => Js.log(item) | exception Not_found => Js.log("No such item found!") } diff --git a/pages/docs/manual/latest/import-from-export-to-js.mdx b/pages/docs/manual/latest/import-from-export-to-js.mdx index 9d10167cb..3c4e0aed4 100644 --- a/pages/docs/manual/latest/import-from-export-to-js.mdx +++ b/pages/docs/manual/latest/import-from-export-to-js.mdx @@ -60,7 +60,7 @@ By omitting the string argument to `module`, you bind to the whole JS module: ```res example -@module external leftPad: string => int => string = "./leftPad" +@module external leftPad: (string, int) => string = "./leftPad" let paddedResult = leftPad("hi", 5) ``` ```js diff --git a/pages/docs/manual/latest/lazy-values.mdx b/pages/docs/manual/latest/lazy-values.mdx index 7fde6bb26..bc9a1a9c4 100644 --- a/pages/docs/manual/latest/lazy-values.mdx +++ b/pages/docs/manual/latest/lazy-values.mdx @@ -11,10 +11,13 @@ If you have some expensive computations you'd like to **defer and cache** subseq ```res prelude +@module("node:fs") +external readdirSync: string => array = "readdirSync" + // Read the directory, only once let expensiveFilesRead = lazy({ Js.log("Reading dir") - Node.Fs.readdirSync("./pages") + readdirSync("./pages") }) ``` ```js diff --git a/pages/docs/manual/latest/module.mdx b/pages/docs/manual/latest/module.mdx index ad9d4e5c4..d81eeb639 100644 --- a/pages/docs/manual/latest/module.mdx +++ b/pages/docs/manual/latest/module.mdx @@ -445,7 +445,7 @@ module MakeSet = (Item: Comparable) => { let empty = list{} let add = (currentSet: backingType, newItem: Item.t): backingType => // if item exists - if List.exists(x => Item.equal(x, newItem), currentSet) { + if currentSet->List.some(x => Item.equal(x, newItem)) { currentSet // return the same (immutable) set (a list really) } else { list{ diff --git a/pages/docs/manual/latest/pattern-matching-destructuring.mdx b/pages/docs/manual/latest/pattern-matching-destructuring.mdx index 673b27d31..4f876f68d 100644 --- a/pages/docs/manual/latest/pattern-matching-destructuring.mdx +++ b/pages/docs/manual/latest/pattern-matching-destructuring.mdx @@ -625,7 +625,7 @@ printStudents({ let coordinates = (10, 20, 30) let centerY = 20 switch coordinates { -| (x, centerY, _) => Js.log(x) +| (x, _centerY, _) => Js.log(x) } ``` ```js @@ -721,7 +721,7 @@ Some({name: ""}) let myNullableValue = Some(5) switch myNullableValue { -| Some(v) => Js.log("value is present") +| Some(_v) => Js.log("value is present") | None => Js.log("value is absent") } ``` diff --git a/scripts/test-examples.mjs b/scripts/test-examples.mjs index de95bd687..d031485c7 100644 --- a/scripts/test-examples.mjs +++ b/scripts/test-examples.mjs @@ -14,7 +14,9 @@ let tempFileNameRegex = /_tempFile\.res/g // see the package.json on how to define another rescript version let compilersDir = path.join(__dirname, "..", "compilers") -let bsc = path.join(compilersDir, 'node_modules', 'rescript-1010', process.platform, 'bsc.exe') +let bsc = path.join(compilersDir, 'node_modules', 'rescript-1100', process.platform, 'bsc.exe'); +let rescriptBin = path.join(compilersDir, 'node_modules', 'rescript-1100', 'rescript'); +let rescriptCoreCompiled = path.join(compilersDir, 'node_modules', '@rescript', 'core', 'lib', 'ocaml'); const prepareCompilers = () => { if (fs.existsSync(bsc)) { @@ -24,6 +26,14 @@ const prepareCompilers = () => { child_process.execFileSync("npm", ['install'], {cwd: compilersDir}) } +const prepareRescriptCore = () => { + if (fs.existsSync(rescriptCoreCompiled)) { + return; + } + console.log("Rescript Core not installed. Installing..."); + child_process.execFileSync(rescriptBin, [], {cwd: compilersDir}) +} + let parseFile = content => { if (!/```res (example|prelude|sig)/.test(content)) { return @@ -69,6 +79,7 @@ let postprocessOutput = (file, error) => { prepareCompilers(); +prepareRescriptCore(); console.log("Running tests...") fs.writeFileSync(tempFileName, '') @@ -83,7 +94,20 @@ glob.sync(__dirname + '/../pages/docs/manual/latest/**/*.mdx').forEach((file) => try { // -109 for suppressing `Toplevel expression is expected to have unit type.` // Most doc snippets do e.g. `Belt.Array.length(["test"])`, which triggers this - child_process.execFileSync(bsc, [tempFileName, '-w', '-109'], {stdio: 'pipe'}) + child_process.execFileSync( + bsc, + [ + tempFileName, + '-I', + rescriptCoreCompiled, + '-w', + '-109', + "-uncurried", + '-open', + 'RescriptCore', + ], + { stdio: "pipe" } + ); } catch (e) { process.stdout.write(postprocessOutput(file, e)) success = false From c4027caca6bcd3a5d32bfa1d5ff11e021361eedc Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Tue, 24 Oct 2023 00:26:04 +0200 Subject: [PATCH 4/9] Change more examples from Belt to RescriptCore --- pages/docs/manual/latest/build-external-stdlib.mdx | 2 +- pages/docs/manual/latest/generate-converters-accessors.mdx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pages/docs/manual/latest/build-external-stdlib.mdx b/pages/docs/manual/latest/build-external-stdlib.mdx index d11eaa7a0..d5f2520fd 100644 --- a/pages/docs/manual/latest/build-external-stdlib.mdx +++ b/pages/docs/manual/latest/build-external-stdlib.mdx @@ -42,7 +42,7 @@ Now the compiled JS code will import using the path defined by `external-stdlib` ```res -Belt.Array.forEach([1, 2, 3], num => Js.log(num)) +Array.forEach([1, 2, 3], num => Js.log(num)) ``` ```js diff --git a/pages/docs/manual/latest/generate-converters-accessors.mdx b/pages/docs/manual/latest/generate-converters-accessors.mdx index 0f1932789..449ab004b 100644 --- a/pages/docs/manual/latest/generate-converters-accessors.mdx +++ b/pages/docs/manual/latest/generate-converters-accessors.mdx @@ -88,8 +88,8 @@ type pet = {name: string} let pets = [{name: "bob"}, {name: "bob2"}] pets - ->Belt.Array.map(name) - ->Js.Array2.joinWith("&") + ->Array.map(name) + ->Array.joinWith("&") ->Js.log ``` From 897e8c7a1f7982d37d838748d65b6825ce9b8a7e Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Thu, 2 Nov 2023 13:07:14 +0100 Subject: [PATCH 5/9] Fix uncurried error --- pages/docs/manual/latest/bind-to-js-function.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/manual/latest/bind-to-js-function.mdx b/pages/docs/manual/latest/bind-to-js-function.mdx index 90a2ab899..415000bc3 100644 --- a/pages/docs/manual/latest/bind-to-js-function.mdx +++ b/pages/docs/manual/latest/bind-to-js-function.mdx @@ -444,7 +444,7 @@ type x @val external x: x = "x" @set external setOnload: (x, @this ((x, int) => unit)) => unit = "onload" @get external resp: x => int = "response" -setOnload(x, @this ((o, v) => Js.log(resp(o) + v))) +setOnload(x, @this (o, v) => Js.log(resp(o) + v)) ``` ```js x.onload = function (v) { From c3fb880059edf8aafb3fa6080c2a748c00843abc Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Thu, 2 Nov 2023 13:09:52 +0100 Subject: [PATCH 6/9] Consistent quotes --- scripts/test-examples.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test-examples.mjs b/scripts/test-examples.mjs index d031485c7..7e01509f7 100644 --- a/scripts/test-examples.mjs +++ b/scripts/test-examples.mjs @@ -102,7 +102,7 @@ glob.sync(__dirname + '/../pages/docs/manual/latest/**/*.mdx').forEach((file) => rescriptCoreCompiled, '-w', '-109', - "-uncurried", + '-uncurried', '-open', 'RescriptCore', ], From 43b677394accfd9b0739f0f351fa7ec3531d0ea9 Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Fri, 10 Nov 2023 23:20:09 +0100 Subject: [PATCH 7/9] Fix remaining test --- .../manual/latest/pattern-matching-destructuring.mdx | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/pages/docs/manual/latest/pattern-matching-destructuring.mdx b/pages/docs/manual/latest/pattern-matching-destructuring.mdx index 4f876f68d..ca29e3d02 100644 --- a/pages/docs/manual/latest/pattern-matching-destructuring.mdx +++ b/pages/docs/manual/latest/pattern-matching-destructuring.mdx @@ -211,16 +211,10 @@ Here's a real-world scenario that'd be a headache to code in other languages. Gi ```res prelude type status = Vacations(int) | Sabbatical(int) | Sick | Present type reportCard = {passing: bool, gpa: float} +type student = {name: string, status: status, reportCard: reportCard} type person = - | Teacher({ - name: string, - age: int, - }) - | Student({ - name: string, - status: status, - reportCard: reportCard, - }) + | Teacher({name: string, age: int}) + | Student(student) ``` ```js // Empty output From 9d689e2b4f621c75a46c7a972bc4b240760be40e Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Fri, 10 Nov 2023 23:20:31 +0100 Subject: [PATCH 8/9] Mention RescriptCore in try section --- pages/docs/manual/latest/try.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/manual/latest/try.mdx b/pages/docs/manual/latest/try.mdx index 6e250decc..82e17e1ba 100644 --- a/pages/docs/manual/latest/try.mdx +++ b/pages/docs/manual/latest/try.mdx @@ -6,4 +6,4 @@ canonical: "/docs/manual/latest/try" ## Try Online -Our [Playground](/try) lets you try ReScript online, and comes with [ReScript-React](/docs/react/latest/introduction) preinstalled. +Our [Playground](/try) lets you try ReScript online, and comes with [ReScript-React](/docs/react/latest/introduction) and the new [ReScript-Core](https://github.com/rescript-association/rescript-core) standard library preinstalled. From f18c15d51e7a24cf6463dc662c74ea9d5e7f2e3f Mon Sep 17 00:00:00 2001 From: Florian Hammerschmidt Date: Fri, 10 Nov 2023 23:27:32 +0100 Subject: [PATCH 9/9] Add dummy file --- compilers/dummy/Dummy.res | 1 + 1 file changed, 1 insertion(+) create mode 100644 compilers/dummy/Dummy.res diff --git a/compilers/dummy/Dummy.res b/compilers/dummy/Dummy.res new file mode 100644 index 000000000..216d35a7a --- /dev/null +++ b/compilers/dummy/Dummy.res @@ -0,0 +1 @@ +Console.log("I am a dummy file")