Skip to content

Commit dd1f753

Browse files
committed
Revert "Rename functions ending with Exn to OrThrow"
This reverts commit d23316c.
1 parent d23316c commit dd1f753

File tree

15 files changed

+60
-174
lines changed

15 files changed

+60
-174
lines changed

CHANGELOG.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
1313
# 12.0.0-alpha.14 (Unreleased)
1414

15-
#### :boom: Breaking Change
16-
17-
- Rename functions ending with `Exn` to end with `OrThrow`. The old `Exn` functions are now deprecated:
18-
- `Bool.fromStringExn``Bool.fromStringOrThrow`
19-
- `BigInt.fromStringExn``BigInt.fromStringOrThrow`
20-
- `JSON.parseExn``JSON.parseOrThrow`
21-
- Changed `BigInt.fromFloat` to return an option rather than throwing an error.
22-
- Added `BigInt.fromFloatOrThrow`
23-
- Old functions remain available but are marked as deprecated with guidance to use the new `OrThrow` variants.
24-
2515
#### :rocket: New Feature
2616

2717
- Add `RegExp.flags`. https://github.com/rescript-lang/rescript/pull/7461

lib/es6/Stdlib_BigInt.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11

22

33

4-
function fromString(value) {
5-
try {
6-
return BigInt(value);
7-
} catch (exn) {
8-
return;
9-
}
10-
}
11-
124
function fromFloat(value) {
135
try {
146
return BigInt(value);
@@ -22,7 +14,6 @@ function toInt(t) {
2214
}
2315

2416
export {
25-
fromString,
2617
fromFloat,
2718
toInt,
2819
}

lib/es6/Stdlib_Bool.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function fromString(s) {
2020
}
2121
}
2222

23-
function fromStringOrThrow(param) {
23+
function fromStringExn(param) {
2424
switch (param) {
2525
case "false" :
2626
return false;
@@ -29,18 +29,15 @@ function fromStringOrThrow(param) {
2929
default:
3030
throw {
3131
RE_EXN_ID: "Invalid_argument",
32-
_1: "Bool.fromStringOrThrow: value is neither \"true\" nor \"false\"",
32+
_1: "Bool.fromStringExn: value is neither \"true\" nor \"false\"",
3333
Error: new Error()
3434
};
3535
}
3636
}
3737

38-
let fromStringExn = fromStringOrThrow;
39-
4038
export {
4139
toString,
4240
fromString,
43-
fromStringOrThrow,
4441
fromStringExn,
4542
}
4643
/* No side effect */

lib/js/Stdlib_BigInt.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
'use strict';
22

33

4-
function fromString(value) {
5-
try {
6-
return BigInt(value);
7-
} catch (exn) {
8-
return;
9-
}
10-
}
11-
124
function fromFloat(value) {
135
try {
146
return BigInt(value);
@@ -21,7 +13,6 @@ function toInt(t) {
2113
return Number(t) | 0;
2214
}
2315

24-
exports.fromString = fromString;
2516
exports.fromFloat = fromFloat;
2617
exports.toInt = toInt;
2718
/* No side effect */

lib/js/Stdlib_Bool.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function fromString(s) {
2020
}
2121
}
2222

23-
function fromStringOrThrow(param) {
23+
function fromStringExn(param) {
2424
switch (param) {
2525
case "false" :
2626
return false;
@@ -29,16 +29,13 @@ function fromStringOrThrow(param) {
2929
default:
3030
throw {
3131
RE_EXN_ID: "Invalid_argument",
32-
_1: "Bool.fromStringOrThrow: value is neither \"true\" nor \"false\"",
32+
_1: "Bool.fromStringExn: value is neither \"true\" nor \"false\"",
3333
Error: new Error()
3434
};
3535
}
3636
}
3737

38-
let fromStringExn = fromStringOrThrow;
39-
4038
exports.toString = toString;
4139
exports.fromString = fromString;
42-
exports.fromStringOrThrow = fromStringOrThrow;
4340
exports.fromStringExn = fromStringExn;
4441
/* No side effect */

runtime/Stdlib_BigInt.res

Lines changed: 11 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,89 +6,39 @@ type t = bigint
66
@val external asIntN: (~width: int, bigint) => bigint = "BigInt.asIntN"
77
@val external asUintN: (~width: int, bigint) => bigint = "BigInt.asUintN"
88

9+
@val external fromString: string => bigint = "BigInt"
10+
911
@val
1012
/**
1113
Parses the given `string` into a `bigint` using JavaScript semantics. Return the
12-
number as a `bigint` if successfully parsed. Throws a syntax exception otherwise.
14+
number as a `bigint` if successfully parsed. Uncaught syntax exception otherwise.
1315
1416
## Examples
1517
1618
```rescript
17-
BigInt.fromStringOrThrow("123")->assertEqual(123n)
19+
BigInt.fromStringExn("123")->assertEqual(123n)
1820
19-
BigInt.fromStringOrThrow("")->assertEqual(0n)
21+
BigInt.fromStringExn("")->assertEqual(0n)
2022
21-
BigInt.fromStringOrThrow("0x11")->assertEqual(17n)
23+
BigInt.fromStringExn("0x11")->assertEqual(17n)
2224
23-
BigInt.fromStringOrThrow("0b11")->assertEqual(3n)
25+
BigInt.fromStringExn("0b11")->assertEqual(3n)
2426
25-
BigInt.fromStringOrThrow("0o11")->assertEqual(9n)
27+
BigInt.fromStringExn("0o11")->assertEqual(9n)
2628
2729
/* catch exception */
28-
switch BigInt.fromStringOrThrow("a") {
30+
switch BigInt.fromStringExn("a") {
2931
| exception JsExn(_error) => assert(true)
3032
| _bigInt => assert(false)
3133
}
3234
```
3335
*/
34-
external fromStringOrThrow: string => bigint = "BigInt"
35-
36-
/**
37-
Parses the given `string` into a `bigint` using JavaScript semantics. Returns
38-
`Some(bigint)` if the string can be parsed, `None` otherwise.
39-
40-
## Examples
41-
42-
```rescript
43-
BigInt.fromString("123")->assertEqual(Some(123n))
44-
45-
BigInt.fromString("")->assertEqual(Some(0n))
46-
47-
BigInt.fromString("0x11")->assertEqual(Some(17n))
48-
49-
BigInt.fromString("0b11")->assertEqual(Some(3n))
50-
51-
BigInt.fromString("0o11")->assertEqual(Some(9n))
52-
53-
BigInt.fromString("invalid")->assertEqual(None)
54-
```
55-
*/
56-
let fromString = (value: string) => {
57-
try Some(fromStringOrThrow(value)) catch {
58-
| _ => None
59-
}
60-
}
61-
62-
@deprecated("Use `fromStringOrThrow` instead") @val
6336
external fromStringExn: string => bigint = "BigInt"
64-
6537
@val external fromInt: int => bigint = "BigInt"
66-
67-
@val
68-
/**
69-
Converts a `float` to a `bigint` using JavaScript semantics.
70-
Throws an exception if the float is not an integer or is infinite/NaN.
71-
72-
## Examples
73-
74-
```rescript
75-
BigInt.fromFloatOrThrow(123.0)->assertEqual(123n)
76-
77-
BigInt.fromFloatOrThrow(0.0)->assertEqual(0n)
78-
79-
BigInt.fromFloatOrThrow(-456.0)->assertEqual(-456n)
80-
81-
/* This will throw an exception */
82-
switch BigInt.fromFloatOrThrow(123.5) {
83-
| exception JsExn(_error) => assert(true)
84-
| _bigInt => assert(false)
85-
}
86-
```
87-
*/
88-
external fromFloatOrThrow: float => bigint = "BigInt"
38+
@val external fromFloat: float => bigint = "BigInt"
8939

9040
let fromFloat = (value: float) => {
91-
try Some(fromFloatOrThrow(value)) catch {
41+
try Some(fromFloat(value)) catch {
9242
| _ => None
9343
}
9444
}

runtime/Stdlib_Bool.res

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ let fromString = s => {
1515
}
1616
}
1717

18-
let fromStringOrThrow = param =>
18+
let fromStringExn = param =>
1919
switch param {
2020
| "true" => true
2121
| "false" => false
22-
| _ => throw(Invalid_argument(`Bool.fromStringOrThrow: value is neither "true" nor "false"`))
22+
| _ => throw(Invalid_argument(`Bool.fromStringExn: value is neither "true" nor "false"`))
2323
}
2424

25-
@deprecated("Use `fromStringOrThrow` instead")
26-
let fromStringExn = fromStringOrThrow
27-
2825
external compare: (bool, bool) => Stdlib_Ordering.t = "%compare"
2926

3027
external equal: (bool, bool) => bool = "%equal"

runtime/Stdlib_Bool.resi

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,6 @@ Bool.fromString("notAValidBoolean")->assertEqual(None)
3131
*/
3232
let fromString: string => option<bool>
3333

34-
/**
35-
Converts a string to a boolean.
36-
Throws an `Invalid_argument` exception if the string is not a valid boolean.
37-
38-
## Examples
39-
```rescript
40-
Bool.fromStringOrThrow("true")->assertEqual(true)
41-
Bool.fromStringOrThrow("false")->assertEqual(false)
42-
switch Bool.fromStringOrThrow("notAValidBoolean") {
43-
| exception Invalid_argument(_) => assert(true)
44-
| _ => assert(false)
45-
}
46-
```
47-
*/
48-
let fromStringOrThrow: string => bool
49-
5034
/**
5135
Converts a string to a boolean.
5236
Beware, this function will throw an `Invalid_argument` exception
@@ -62,7 +46,6 @@ switch Bool.fromStringExn("notAValidBoolean") {
6246
}
6347
```
6448
*/
65-
@deprecated("Use `fromStringOrThrow` instead")
6649
let fromStringExn: string => bool
6750

6851
external compare: (bool, bool) => Stdlib_Ordering.t = "%compare"

runtime/Stdlib_JSON.res

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ type rec t =
1010
@unboxed
1111
type replacer = Keys(array<string>) | Replacer((string, t) => t)
1212

13-
@raises @val external parseOrThrow: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse"
14-
15-
@deprecated("Use `parseOrThrow` instead") @raises @val
16-
external parseExn: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse"
13+
@raises @val external parseExn: (string, ~reviver: (string, t) => t=?) => t = "JSON.parse"
14+
@deprecated("Use `parseExn` with optional parameter instead") @raises @val
15+
external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse"
1716

1817
@val external stringify: (t, ~replacer: replacer=?, ~space: int=?) => string = "JSON.stringify"
1918
@deprecated("Use `stringify` with optional parameter instead") @val

0 commit comments

Comments
 (0)