From 6d9df0f1e0e58c5133cca2428d3a1e083c83218c Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 20 Oct 2024 21:06:19 +0200 Subject: [PATCH] Fix undefined being emitted instead of null (#7112) --- compiler/ml/translcore.ml | 2 +- lib/es6/JSON.js | 7 +++---- lib/es6/Null.js | 13 ++++++++----- lib/js/JSON.js | 7 +++---- lib/js/Null.js | 13 ++++++++----- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 4b080b5f14..04c80e8e09 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -361,7 +361,7 @@ let primitives_table = ("#raw_expr", Pjs_raw_expr); ("#raw_stmt", Pjs_raw_stmt); (* FIXME: Core compatibility *) - ("#null", Pundefined); + ("#null", Pnull); ("#undefined", Pundefined); ("#typeof", Ptypeof); ("#is_nullable", Pisnullable); diff --git a/lib/es6/JSON.js b/lib/es6/JSON.js index e547968d71..bbfa0a1a65 100644 --- a/lib/es6/JSON.js +++ b/lib/es6/JSON.js @@ -1,6 +1,5 @@ -import * as Primitive_option from "./Primitive_option.js"; function classify(value) { let match = Object.prototype.toString.call(value); @@ -49,8 +48,8 @@ function bool(json) { } function $$null(json) { - if (json === undefined) { - return Primitive_option.some(undefined); + if (json === null) { + return null; } } @@ -70,7 +69,7 @@ function float(json) { } function object(json) { - if (typeof json === "object" && !Array.isArray(json) && json !== undefined) { + if (typeof json === "object" && !Array.isArray(json) && json !== null) { return json; } diff --git a/lib/es6/Null.js b/lib/es6/Null.js index 42519ac00b..5913fddfb1 100644 --- a/lib/es6/Null.js +++ b/lib/es6/Null.js @@ -6,8 +6,9 @@ import * as Primitive_option from "./Primitive_option.js"; function fromOption(option) { if (option !== undefined) { return Primitive_option.valFromOption(option); + } else { + return null; } - } function equal(a, b, eq) { @@ -45,10 +46,11 @@ function forEach(value, f) { } function map(value, f) { - if (!(value == null)) { + if (value == null) { + return null; + } else { return f(value); } - } function mapOr(value, $$default, f) { @@ -60,10 +62,11 @@ function mapOr(value, $$default, f) { } function flatMap(value, f) { - if (!(value == null)) { + if (value == null) { + return null; + } else { return f(value); } - } let getWithDefault = getOr; diff --git a/lib/js/JSON.js b/lib/js/JSON.js index b3fe6b0f6e..799be2bab0 100644 --- a/lib/js/JSON.js +++ b/lib/js/JSON.js @@ -1,6 +1,5 @@ 'use strict'; -let Primitive_option = require("./Primitive_option.js"); function classify(value) { let match = Object.prototype.toString.call(value); @@ -49,8 +48,8 @@ function bool(json) { } function $$null(json) { - if (json === undefined) { - return Primitive_option.some(undefined); + if (json === null) { + return null; } } @@ -70,7 +69,7 @@ function float(json) { } function object(json) { - if (typeof json === "object" && !Array.isArray(json) && json !== undefined) { + if (typeof json === "object" && !Array.isArray(json) && json !== null) { return json; } diff --git a/lib/js/Null.js b/lib/js/Null.js index d324e36b01..1f79c22c94 100644 --- a/lib/js/Null.js +++ b/lib/js/Null.js @@ -6,8 +6,9 @@ let Primitive_option = require("./Primitive_option.js"); function fromOption(option) { if (option !== undefined) { return Primitive_option.valFromOption(option); + } else { + return null; } - } function equal(a, b, eq) { @@ -45,10 +46,11 @@ function forEach(value, f) { } function map(value, f) { - if (!(value == null)) { + if (value == null) { + return null; + } else { return f(value); } - } function mapOr(value, $$default, f) { @@ -60,10 +62,11 @@ function mapOr(value, $$default, f) { } function flatMap(value, f) { - if (!(value == null)) { + if (value == null) { + return null; + } else { return f(value); } - } let getWithDefault = getOr;