Skip to content

Commit 7d83ae4

Browse files
committed
Merge branch 'main' into doc-test-js-outuput
2 parents 36b197d + 5d675f7 commit 7d83ae4

29 files changed

+514
-118
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
## Next version
44

5+
- BREAKING: Use new native `bigint` type. This requires ReScript compiler version "11.1.0-rc.6" or higher. https://github.com/rescript-association/rescript-core/pull/207
6+
7+
## 1.2.0
8+
9+
- Add optional arguments to `JSON.stringify` and `JSON.parseExn` and deprecate `JSON.stringifyWithIndent`, `JSON.stringifyWithReplacer`, `JSON.parseExnWithReviver` etc. https://github.com/rescript-association/rescript-core/pull/201
10+
- Add `Array.join` and deprecate `Array.joinWith`. https://github.com/rescript-association/rescript-core/pull/205
511
- BREAKING: Intl types: simplify bindings for constructors / functions with optional arguments. https://github.com/rescript-association/rescript-core/pull/198
612
- Fix: Expose Intl.Common. https://github.com/rescript-association/rescript-core/pull/197
713
- Add `Array.flatMapWithIndex` https://github.com/rescript-association/rescript-core/pull/199
14+
- Add `Promise.any`, `Promise.allSettled`, `Promise.withResolvers` https://github.com/rescript-association/rescript-core/pull/204
815

916
## 1.1.0
1017

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rescript/core",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"scripts": {
55
"clean": "rescript clean",
66
"build": "rescript",
@@ -24,11 +24,11 @@
2424
"src/**/*.mjs"
2525
],
2626
"peerDependencies": {
27-
"rescript": ">=11.0.0 || ^11.1.0-rc.2"
27+
"rescript": "^11.1.0-rc.7"
2828
},
2929
"devDependencies": {
3030
"@babel/code-frame": "7.18.6",
3131
"@rescript/tools": "^0.5.0",
32-
"rescript": "11.1.0-rc.2"
32+
"rescript": "^11.1.0-rc.7"
3333
}
34-
}
34+
}

scripts/DocTests.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var bscBin = Path.join(compilerDir, "node_modules", ".bin", "bsc");
4848
var rescriptCoreCompiled = Path.join(compilerDir, "node_modules", "@rescript", "core", "lib", "ocaml");
4949

5050
function makePackageJson(coreVersion) {
51-
return "{\n \"name\": \"test-compiler-examples\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"@rescript/core\": \"file:rescript-core-" + coreVersion + ".tgz\",\n \"rescript\": \"^11.0.1\"\n }\n}\n";
51+
return "{\n \"name\": \"test-compiler-examples\",\n \"version\": \"1.0.0\",\n \"dependencies\": {\n \"@rescript/core\": \"file:rescript-core-" + coreVersion + ".tgz\",\n \"rescript\": \"11.1.0-rc.7\"\n }\n}\n";
5252
}
5353

5454
var rescriptJson = "{\n \"name\": \"dummy\",\n \"sources\": {\n \"dir\": \"dummy\",\n \"subdirs\": true\n },\n \"bs-dependencies\": [\n \"@rescript/core\"\n ],\n \"bsc-flags\": [\n \"-open RescriptCore\"\n ]\n}";
@@ -143,7 +143,7 @@ async function compileTest(id, code) {
143143
"-I",
144144
rescriptCoreCompiled,
145145
"-w",
146-
"-109",
146+
"-3-109",
147147
"-uncurried",
148148
"-open",
149149
"RescriptCore"

scripts/DocTests.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let makePackageJson = coreVersion =>
8989
"version": "1.0.0",
9090
"dependencies": {
9191
"@rescript/core": "file:rescript-core-${coreVersion}.tgz",
92-
"rescript": "^11.0.1"
92+
"rescript": "11.1.0-rc.7"
9393
}
9494
}
9595
`
@@ -163,7 +163,7 @@ let compileTest = async (~id, ~code) => {
163163
"-I",
164164
rescriptCoreCompiled,
165165
"-w",
166-
"-109",
166+
"-3-109",
167167
"-uncurried",
168168
"-open",
169169
"RescriptCore",
@@ -190,7 +190,7 @@ let compileTest = async (~id, ~code) => {
190190
| true =>
191191
stderr
192192
->Array.map(e => e->Buffer.toString)
193-
->Array.joinWith("")
193+
->Array.join("")
194194
->Error
195195
| false =>
196196
stdout
@@ -293,7 +293,7 @@ let getCodeBlocks = example => {
293293
code
294294
->List.reverse
295295
->List.toArray
296-
->Array.joinWith("\n"),
296+
->Array.join("\n"),
297297
...acc,
298298
},
299299
)
@@ -359,9 +359,9 @@ let main = async () => {
359359
e
360360
->String.split("\n")
361361
->Array.filterWithIndex((_, i) => i !== 2)
362-
->Array.joinWith("\n")
362+
->Array.join("\n")
363363
})
364-
->Array.joinWith("\n")
364+
->Array.join("\n")
365365

366366
let message = `${"error"->red}: failed to compile examples from ${kind} ${test.id->cyan}\n${errorMessage}`
367367

src/Core__Array.res

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,15 @@ let indexOfOpt = (arr, item) =>
124124
}
125125
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
126126

127-
@send external joinWith: (array<string>, string) => string = "join"
127+
@send external join: (array<string>, string) => string = "join"
128128

129-
@send external joinWithUnsafe: (array<'a>, string) => string = "join"
129+
@deprecated("Use `join` instead") @send
130+
external joinWith: (array<string>, string) => string = "join"
131+
132+
@send external joinUnsafe: (array<'a>, string) => string = "join"
133+
134+
@deprecated("Use `joinUnsafe` instead") @send
135+
external joinWithUnsafe: (array<'a>, string) => string = "join"
130136

131137
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"
132138
let lastIndexOfOpt = (arr, item) =>

src/Core__Array.resi

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,21 @@ Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"
397397
let indexOfOpt: (array<'a>, 'a) => option<int>
398398
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
399399

400+
/**
401+
`join(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.
402+
403+
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
404+
405+
## Examples
406+
```rescript
407+
let array = ["One", "Two", "Three"]
408+
409+
Console.log(array->Array.join(" -- ")) // One -- Two -- Three
410+
```
411+
*/
412+
@send
413+
external join: (array<string>, string) => string = "join"
414+
400415
/**
401416
`joinWith(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Array items must be strings, to join number or other arrays, use `joinWithUnsafe`. Under the hood this will run JavaScript's `toString` on all the array items.
402417
@@ -407,9 +422,25 @@ let array = ["One", "Two", "Three"]
407422
Console.log(array->Array.joinWith(" -- ")) // One -- Two -- Three
408423
```
409424
*/
425+
@deprecated("Use `join` instead")
410426
@send
411427
external joinWith: (array<string>, string) => string = "join"
412428

429+
/**
430+
`joinUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.
431+
432+
See [Array.join](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
433+
434+
## Examples
435+
```rescript
436+
let array = [1, 2, 3]
437+
438+
Console.log(array->Array.joinUnsafe(" -- ")) // 1 -- 2 -- 3
439+
```
440+
*/
441+
@send
442+
external joinUnsafe: (array<'a>, string) => string = "join"
443+
413444
/**
414445
`joinWithUnsafe(array, separator)` produces a string where all items of `array` are printed, separated by `separator`. Under the hood this will run JavaScript's `toString` on all the array items.
415446
@@ -420,6 +451,7 @@ let array = [1, 2, 3]
420451
Console.log(array->Array.joinWithUnsafe(" -- ")) // 1 -- 2 -- 3
421452
```
422453
*/
454+
@deprecated("Use `joinUnsafe` instead")
423455
@send
424456
external joinWithUnsafe: (array<'a>, string) => string = "join"
425457
@send external lastIndexOf: (array<'a>, 'a) => int = "lastIndexOf"

src/Core__BigInt.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ function toInt(t) {
55
return Number(t) | 0;
66
}
77

8-
function exp(x, y) {
9-
return (x ** y);
8+
function lnot(x) {
9+
return x ^ -1n;
1010
}
1111

1212
export {
1313
toInt ,
14-
exp ,
14+
lnot ,
1515
}
1616
/* No side effect */

src/Core__BigInt.res

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,95 @@
1-
type t = Js.Types.bigint_val
1+
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
2+
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"
23

3-
@val external asIntN: (~width: int, t) => t = "BigInt.asIntN"
4-
@val external asUintN: (~width: int, t) => t = "BigInt.asUintN"
4+
@val external fromString: string => bigint = "BigInt"
55

6-
@val external fromString: string => t = "BigInt"
7-
@val external fromInt: int => t = "BigInt"
8-
@val external fromFloat: float => t = "BigInt"
6+
@val
7+
/**
8+
Parses the given `string` into a `bigint` using JavaScript semantics. Return the
9+
number as a `bigint` if successfully parsed. Uncaught syntax exception otherwise.
910
10-
@send external toString: t => string = "toString"
11-
@send external toStringWithRadix: (t, ~radix: int) => string = "toString"
12-
@send external toLocaleString: t => string = "toLocaleString"
11+
## Examples
1312
14-
@val external toFloat: t => float = "Number"
13+
```rescript
14+
/* returns 123n */
15+
BigInt.fromStringExn("123")
16+
17+
/* returns 0n */
18+
BigInt.fromStringExn("")
19+
20+
/* returns 17n */
21+
BigInt.fromStringExn("0x11")
22+
23+
/* returns 3n */
24+
BigInt.fromStringExn("0b11")
25+
26+
/* returns 9n */
27+
BigInt.fromStringExn("0o11")
28+
29+
/* catch exception */
30+
try {
31+
BigInt.fromStringExn("a")
32+
} catch {
33+
| Exn.Error(_error) => 0n
34+
}
35+
```
36+
*/
37+
external fromStringExn: string => bigint = "BigInt"
38+
@val external fromInt: int => bigint = "BigInt"
39+
@val external fromFloat: float => bigint = "BigInt"
40+
41+
@send
42+
/**
43+
Formats a `bigint` as a string. Return a `string` representing the given value.
44+
See [`toString`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toString) on MDN.
45+
46+
## Examples
47+
48+
```rescript
49+
/* prints "123" */
50+
Js.BigInt.toString(123n)->Js.log
51+
```
52+
*/
53+
external toString: bigint => string = "toString"
54+
@send external toStringWithRadix: (bigint, ~radix: int) => string = "toString"
55+
56+
@send
57+
/**
58+
Returns a string with a language-sensitive representation of this BigInt value.
59+
60+
## Examples
61+
62+
```rescript
63+
/* prints "123" */
64+
Js.BigInt.toString(123n)->Js.log
65+
```
66+
*/
67+
external toLocaleString: bigint => string = "toLocaleString"
68+
69+
@val external toFloat: bigint => float = "Number"
1570

1671
let toInt = t => t->toFloat->Core__Int.fromFloat
1772

18-
external \"+": (t, t) => t = "%addfloat"
19-
external \"-": (t, t) => t = "%subfloat"
20-
external \"*": (t, t) => t = "%mulfloat"
21-
external \"/": (t, t) => t = "%divfloat"
73+
external \"+": (bigint, bigint) => bigint = "%addbigint"
74+
external \"-": (bigint, bigint) => bigint = "%subbigint"
75+
external \"*": (bigint, bigint) => bigint = "%mulbigint"
76+
external \"/": (bigint, bigint) => bigint = "%divbigint"
77+
external \"~-": bigint => bigint = "%negbigint"
78+
external \"~+": bigint => bigint = "%identity"
79+
external \"**": (bigint, bigint) => bigint = "%powbigint"
2280

23-
external add: (t, t) => t = "%addfloat"
24-
external sub: (t, t) => t = "%subfloat"
25-
external mul: (t, t) => t = "%mulfloat"
26-
external div: (t, t) => t = "%divfloat"
81+
external add: (bigint, bigint) => bigint = "%addfloat"
82+
external sub: (bigint, bigint) => bigint = "%subfloat"
83+
external mul: (bigint, bigint) => bigint = "%mulfloat"
84+
external div: (bigint, bigint) => bigint = "%divfloat"
2785

28-
@noalloc external mod: (t, t) => t = "?fmod_float"
86+
external mod: (bigint, bigint) => bigint = "%modbigint"
2987

30-
external land: (t, t) => t = "%andint"
31-
external lor: (t, t) => t = "%orint"
32-
external lxor: (t, t) => t = "%xorint"
88+
external land: (bigint, bigint) => bigint = "%andbigint"
89+
external lor: (bigint, bigint) => bigint = "%orbigint"
90+
external lxor: (bigint, bigint) => bigint = "%xorbigint"
3391

34-
external lsl: (t, t) => t = "%lslint"
35-
external asr: (t, t) => t = "%asrint"
92+
external lsl: (bigint, bigint) => bigint = "%lslbigint"
93+
external asr: (bigint, bigint) => bigint = "%asrbigint"
3694

37-
let exp = (x: t, y: t) => {
38-
let _ = x
39-
let _ = y
40-
%raw(`x ** y`)
41-
}
95+
let lnot = x => lxor(x, -1n)

src/Core__DataView.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i
2020
@send external getFloat32: t => float = "getFloat32"
2121
@send external getFloat64: t => float = "getFloat64"
2222

23-
@send external getBigInt64: t => Core__BigInt.t = "getBigInt64"
24-
@send external getBigUint64: t => Core__BigInt.t = "getBigUint64"
23+
@send external getBigInt64: t => bigint = "getBigInt64"
24+
@send external getBigUint64: t => bigint = "getBigUint64"
2525

2626
@send external setInt8: (t, int) => unit = "setInt8"
2727
@send external setUint8: (t, int) => unit = "setUint8"
@@ -33,5 +33,5 @@ external fromBufferWithRange: (Core__ArrayBuffer.t, ~byteOffset: int, ~length: i
3333
@send external setFloat32: (t, float) => unit = "setFloat32"
3434
@send external setFloat64: (t, float) => unit = "setFloat64"
3535

36-
@send external setBigInt64: (t, Core__BigInt.t) => unit = "setBigInt64"
37-
@send external setBigUint64: (t, Core__BigInt.t) => unit = "setBigUint64"
36+
@send external setBigInt64: (t, bigint) => unit = "setBigInt64"
37+
@send external setBigUint64: (t, bigint) => unit = "setBigUint64"

0 commit comments

Comments
 (0)