Skip to content

Fix undefined being emitted instead of null #7112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/ml/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions lib/es6/JSON.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@


import * as Primitive_option from "./Primitive_option.js";

function classify(value) {
let match = Object.prototype.toString.call(value);
Expand Down Expand Up @@ -49,8 +48,8 @@ function bool(json) {
}

function $$null(json) {
if (json === undefined) {
return Primitive_option.some(undefined);
if (json === null) {
return null;
}

}
Expand All @@ -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;
}

Expand Down
13 changes: 8 additions & 5 deletions lib/es6/Null.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions lib/js/JSON.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

let Primitive_option = require("./Primitive_option.js");

function classify(value) {
let match = Object.prototype.toString.call(value);
Expand Down Expand Up @@ -49,8 +48,8 @@ function bool(json) {
}

function $$null(json) {
if (json === undefined) {
return Primitive_option.some(undefined);
if (json === null) {
return null;
}

}
Expand All @@ -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;
}

Expand Down
13 changes: 8 additions & 5 deletions lib/js/Null.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down