Skip to content

Commit

Permalink
Fix undefined being emitted instead of null (#7112)
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt authored Oct 20, 2024
1 parent a3dee73 commit 6d9df0f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
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

1 comment on commit 6d9df0f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Syntax Benchmarks

Benchmark suite Current: 6d9df0f Previous: e1b7fb7 Ratio
Parse RedBlackTree.res - time/run 1.2308920466666666 ms 1.2123143266666667 ms 1.02
Parse RedBlackTree.res - allocs/run 199057 words 199057 words 1
Print RedBlackTree.res - time/run 2.3184141266666667 ms 2.3104395133333333 ms 1.00
Print RedBlackTree.res - allocs/run 236403 words 236403 words 1
Print RedBlackTreeNoComments.res - time/run 2.0952284933333334 ms 2.10057036 ms 1.00
Print RedBlackTreeNoComments.res - allocs/run 249186 words 249186 words 1
Parse Napkinscript.res - time/run 39.76025602 ms 39.28006235333333 ms 1.01
Parse Napkinscript.res - allocs/run 8670066 words 8670066 words 1
Print Napkinscript.res - time/run 77.24931494666666 ms 77.00100409999999 ms 1.00
Print Napkinscript.res - allocs/run 9776327 words 9776327 words 1
Parse HeroGraphic.res - time/run 5.087775586666667 ms 5.13472718 ms 0.99
Parse HeroGraphic.res - allocs/run 1219326 words 1219326 words 1
Print HeroGraphic.res - time/run 8.752348373333332 ms 8.775952553333333 ms 1.00
Print HeroGraphic.res - allocs/run 1396466 words 1396466 words 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.