Skip to content

Commit 6d9df0f

Browse files
authored
Fix undefined being emitted instead of null (#7112)
1 parent a3dee73 commit 6d9df0f

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

compiler/ml/translcore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ let primitives_table =
361361
("#raw_expr", Pjs_raw_expr);
362362
("#raw_stmt", Pjs_raw_stmt);
363363
(* FIXME: Core compatibility *)
364-
("#null", Pundefined);
364+
("#null", Pnull);
365365
("#undefined", Pundefined);
366366
("#typeof", Ptypeof);
367367
("#is_nullable", Pisnullable);

lib/es6/JSON.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22

3-
import * as Primitive_option from "./Primitive_option.js";
43

54
function classify(value) {
65
let match = Object.prototype.toString.call(value);
@@ -49,8 +48,8 @@ function bool(json) {
4948
}
5049

5150
function $$null(json) {
52-
if (json === undefined) {
53-
return Primitive_option.some(undefined);
51+
if (json === null) {
52+
return null;
5453
}
5554

5655
}
@@ -70,7 +69,7 @@ function float(json) {
7069
}
7170

7271
function object(json) {
73-
if (typeof json === "object" && !Array.isArray(json) && json !== undefined) {
72+
if (typeof json === "object" && !Array.isArray(json) && json !== null) {
7473
return json;
7574
}
7675

lib/es6/Null.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import * as Primitive_option from "./Primitive_option.js";
66
function fromOption(option) {
77
if (option !== undefined) {
88
return Primitive_option.valFromOption(option);
9+
} else {
10+
return null;
911
}
10-
1112
}
1213

1314
function equal(a, b, eq) {
@@ -45,10 +46,11 @@ function forEach(value, f) {
4546
}
4647

4748
function map(value, f) {
48-
if (!(value == null)) {
49+
if (value == null) {
50+
return null;
51+
} else {
4952
return f(value);
5053
}
51-
5254
}
5355

5456
function mapOr(value, $$default, f) {
@@ -60,10 +62,11 @@ function mapOr(value, $$default, f) {
6062
}
6163

6264
function flatMap(value, f) {
63-
if (!(value == null)) {
65+
if (value == null) {
66+
return null;
67+
} else {
6468
return f(value);
6569
}
66-
6770
}
6871

6972
let getWithDefault = getOr;

lib/js/JSON.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
let Primitive_option = require("./Primitive_option.js");
43

54
function classify(value) {
65
let match = Object.prototype.toString.call(value);
@@ -49,8 +48,8 @@ function bool(json) {
4948
}
5049

5150
function $$null(json) {
52-
if (json === undefined) {
53-
return Primitive_option.some(undefined);
51+
if (json === null) {
52+
return null;
5453
}
5554

5655
}
@@ -70,7 +69,7 @@ function float(json) {
7069
}
7170

7271
function object(json) {
73-
if (typeof json === "object" && !Array.isArray(json) && json !== undefined) {
72+
if (typeof json === "object" && !Array.isArray(json) && json !== null) {
7473
return json;
7574
}
7675

lib/js/Null.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ let Primitive_option = require("./Primitive_option.js");
66
function fromOption(option) {
77
if (option !== undefined) {
88
return Primitive_option.valFromOption(option);
9+
} else {
10+
return null;
911
}
10-
1112
}
1213

1314
function equal(a, b, eq) {
@@ -45,10 +46,11 @@ function forEach(value, f) {
4546
}
4647

4748
function map(value, f) {
48-
if (!(value == null)) {
49+
if (value == null) {
50+
return null;
51+
} else {
4952
return f(value);
5053
}
51-
5254
}
5355

5456
function mapOr(value, $$default, f) {
@@ -60,10 +62,11 @@ function mapOr(value, $$default, f) {
6062
}
6163

6264
function flatMap(value, f) {
63-
if (!(value == null)) {
65+
if (value == null) {
66+
return null;
67+
} else {
6468
return f(value);
6569
}
66-
6770
}
6871

6972
let getWithDefault = getOr;

0 commit comments

Comments
 (0)