Skip to content

Commit a2ef8e2

Browse files
committed
set up Null.t
1 parent 2e9c54f commit a2ef8e2

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

src/Core__Null.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type t<'a> = Js.Null.t<'a>
1+
@unboxed type t<'a> = Js.Null.t<'a> = Value('a) | @as(null) Null
22

33
external asNullable: t<'a> => Core__Nullable.t<'a> = "%identity"
44

src/Core__Null.resi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ If you also need to cover `undefined`, check out `Nullable` instead.
77
/**
88
A type representing a value that can be either `'a` or `null`.
99
*/
10-
type t<'a> = Js.Null.t<'a>
10+
@unboxed
11+
type t<'a> = Js.Null.t<'a> = Value('a) | @as(null) Null
1112

1213
/**
1314
Converts a `Null.t` into a `Nullable.t`.

src/Core__Nullable.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@unboxed type t<'a> = Js.Nullable.t<'a> = Present('a) | @as(null) Null | @as(undefined) Undefined
1+
@unboxed type t<'a> = Js.Nullable.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined
22

33
external null: t<'a> = "#null"
44

src/Core__Nullable.resi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Type representing a nullable value.
99
A nullable value can be the value `'a`, `null` or `undefined`.
1010
*/
1111
@unboxed
12-
type t<'a> = Js.Nullable.t<'a> = Present('a) | @as(null) Null | @as(undefined) Undefined
12+
type t<'a> = Js.Nullable.t<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined
1313

1414
/**
1515
The value `null`.

src/RescriptCore.res

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ type null<+'a> = Js.null<'a>
6464

6565
type undefined<+'a> = Js.undefined<'a>
6666

67-
type nullable<+'a> = Js.nullable<'a>
67+
// We're intentionally only bringing the constructors of `nullable` into scope
68+
// here. Reason is if we do the same for `null`, we'll get issues with inference
69+
// in the global scope, and we prioritize nullable higher because that covers
70+
// more cases.
71+
@unboxed
72+
type nullable<+'a> = Js.nullable<'a> = Value('a) | @as(null) Null | @as(undefined) Undefined
6873

6974
let panic = Core__Error.panic

test/NullableTests.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as Test from "./Test.mjs";
55
function shouldHandleNullableValues(param) {
66
var tNull = null;
77
var tUndefined = undefined;
8-
var tPresent = "hello";
8+
var tValue = "hello";
99
var tmp;
1010
tmp = (tNull === null || tNull === undefined) && tNull === null ? true : false;
1111
Test.run([
@@ -33,15 +33,15 @@ function shouldHandleNullableValues(param) {
3333
return prim0 === prim1;
3434
}), true);
3535
var tmp$2;
36-
tmp$2 = tPresent === null || tPresent === undefined || tPresent !== "hello" ? false : true;
36+
tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true;
3737
Test.run([
3838
[
3939
"NullableTests.res",
4040
29,
4141
15,
42-
38
42+
36
4343
],
44-
"Should handle present"
44+
"Should handle value"
4545
], tmp$2, (function (prim0, prim1) {
4646
return prim0 === prim1;
4747
}), true);

test/NullableTests.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ open RescriptCore
33
let shouldHandleNullableValues = () => {
44
let tNull: Nullable.t<string> = %raw("null")
55
let tUndefined: Nullable.t<string> = %raw("undefined")
6-
let tPresent: Nullable.t<string> = %raw(`"hello"`)
6+
let tValue: Nullable.t<string> = %raw(`"hello"`)
77

88
Test.run(
99
__POS_OF__("Should handle null"),
1010
switch tNull {
1111
| Null => true
12-
| Present(_) | Undefined => false
12+
| Value(_) | Undefined => false
1313
},
1414
\"==",
1515
true,
@@ -19,16 +19,16 @@ let shouldHandleNullableValues = () => {
1919
__POS_OF__("Should handle undefined"),
2020
switch tUndefined {
2121
| Undefined => true
22-
| Present(_) | Null => false
22+
| Value(_) | Null => false
2323
},
2424
\"==",
2525
true,
2626
)
2727

2828
Test.run(
29-
__POS_OF__("Should handle present"),
30-
switch tPresent {
31-
| Present("hello") => true
29+
__POS_OF__("Should handle value"),
30+
switch tValue {
31+
| Value("hello") => true
3232
| _ => false
3333
},
3434
\"==",

0 commit comments

Comments
 (0)