Skip to content

fix #3154 #3155

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 2 commits into from
Nov 17, 2018
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
4 changes: 3 additions & 1 deletion jscomp/cleanlib.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
var cp = require('child_process')
var fs = require('fs')
exports.run = function () {
function run() {
cp.execSync(`make clean`)
if (fs.existsSync(`stdlib-406`)) {
cp.execSync(`git clean -dfx stdlib-406`)
Expand All @@ -13,3 +13,5 @@ exports.run = function () {
if(require.main === module){
run()
}

exports.run = run
9 changes: 6 additions & 3 deletions jscomp/others/js_dict.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,19 @@ type 'a t
(** The key type, an alias of string *)
type key = string

(** [get dict key] returns the value associated with [key] in [dict] *)
external get : 'a t -> key -> 'a option = "" [@@bs.get_index] [@@bs.return {undefined_to_opt}]

(** [unsafeGet dict key] returns the value associated with [key] in [dict]

This function will return an invalid value ([undefined]) if [key] does not exist in [dict]. It
will not throw an error.
*)
external unsafeGet : 'a t -> key -> 'a = "" [@@bs.get_index]

(** [get dict key] returns the value associated with [key] in [dict] *)
let get (type u) (dict : u t) (k : key) : u option =
if [%raw {|k in dict|}] then
Some (unsafeGet dict k)
else None

(** [set dict key value] sets the value of [key] in [dict] to [value] *)
external set : 'a t -> key -> 'a -> unit = "" [@@bs.set_index]

Expand Down
4 changes: 2 additions & 2 deletions jscomp/others/js_dict.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type 'a t
type key = string
(** Key type *)

external get :
val get :
'a t ->
key ->
'a option = "" [@@bs.get_index] [@@bs.return {undefined_to_opt}]
'a option
(** [get dict key] returns [None] if the [key] is not found in the
dictionary, [Some value] otherwise *)

Expand Down
3 changes: 2 additions & 1 deletion jscomp/test/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ gpr_2789_test.cmj : mt.cmj
gpr_2863_test.cmj : ../others/belt.cmj
gpr_2931_test.cmj : mt.cmj
gpr_3142_test.cmj : mt.cmj
gpr_3154_test.cmj : mt.cmj ../runtime/js.cmj
gpr_405_test.cmj : gpr_405_test.cmi
gpr_441.cmj :
gpr_459_test.cmj : mt.cmj
Expand Down Expand Up @@ -467,7 +468,7 @@ rec_module_test.cmj : mt.cmj
rec_value_test.cmj : mt.cmj ../runtime/js.cmj
record_debug_test.cmj : ../runtime/js.cmj ../others/belt.cmj
record_with_test.cmj : mt.cmj
recursive_module.cmj :
recursive_module.cmj : mt.cmj
recursive_module_test.cmj : mt.cmj
regression_print.cmj :
return_check.cmj : ../runtime/js.cmj
Expand Down
1 change: 1 addition & 0 deletions jscomp/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ OTHERS := test_literals a test_ari test_export2 test_internalOO test_obj_simple_
406_primitive_test\
fun_pattern_match\
gpr_3142_test\
gpr_3154_test\
ocaml_typedtree_test
# ocaml_typedtree_test is not cross version due to camlinternalFormat
# bs_uncurry_test
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/adt_optimize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function f11(x) {
Caml_builtin_exceptions.assert_failure,
/* tuple */[
"adt_optimize_test.ml",
155,
191,
9
]
];
Expand Down
2 changes: 2 additions & 0 deletions jscomp/test/g
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
BS_DEBUG_FILE=$1 ../../lib/bsc.exe -I ../others/ -I ../stdlib-402 -I ../runtime/ -c $1
46 changes: 46 additions & 0 deletions jscomp/test/gpr_3154_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

var Mt = require("./mt.js");
var Js_dict = require("../../lib/js/js_dict.js");
var Js_primitive = require("../../lib/js/js_primitive.js");

var suites = /* record */[/* contents : [] */0];

var test_id = /* record */[/* contents */0];

function eq(loc, x, y) {
return Mt.eq_suites(test_id, suites, loc, x, y);
}

function b(loc, x) {
return Mt.bool_suites(test_id, suites, loc, x);
}

var d = { };

d["foo"] = undefined;

var match = Js_dict.get(d, "foo");

if (match !== undefined && Js_primitive.valFromOption(match) === undefined) {
b("File \"gpr_3154_test.ml\", line 12, characters 19-26", true);
} else {
b("File \"gpr_3154_test.ml\", line 13, characters 11-18", false);
}

var d0 = { };

d0["foo"] = undefined;

eq("File \"gpr_3154_test.ml\", line 18, characters 5-12", Js_dict.get(d0, "foo"), Js_primitive.some(undefined));

Mt.from_pair_suites("gpr_3154_test.ml", suites[0]);

var J = 0;

exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.b = b;
exports.J = J;
/* Not a pure module */
22 changes: 22 additions & 0 deletions jscomp/test/gpr_3154_test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y
let b loc x = Mt.bool_suites ~test_id ~suites loc x

module J = Js.Dict

let () =
let d = Js.Dict.empty () in
J.set d "foo" None;
match J.get d "foo" with
Some None -> b __LOC__ true
| _ -> b __LOC__ false

let () =
let d0 = Js.Dict.empty () in
J.set d0 "foo" None ;
eq __LOC__ (J.get d0 "foo") (Some None)

let () =
Mt.from_pair_suites __FILE__ !suites

19 changes: 9 additions & 10 deletions jscomp/test/js_dict_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var Mt = require("./mt.js");
var Block = require("../../lib/js/block.js");
var Js_dict = require("../../lib/js/js_dict.js");
var Js_primitive = require("../../lib/js/js_primitive.js");

function obj(param) {
return {
Expand All @@ -28,10 +27,10 @@ var suites_001 = /* :: */[
(function (param) {
return /* Eq */Block.__(0, [
43,
Js_primitive.undefined_to_opt(({
foo: 43,
bar: 86
})["foo"])
Js_dict.get({
foo: 43,
bar: 86
}, "foo")
]);
})
],
Expand All @@ -41,10 +40,10 @@ var suites_001 = /* :: */[
(function (param) {
return /* Eq */Block.__(0, [
undefined,
Js_primitive.undefined_to_opt(({
foo: 43,
bar: 86
})["baz"])
Js_dict.get({
foo: 43,
bar: 86
}, "baz")
]);
})
],
Expand Down Expand Up @@ -72,7 +71,7 @@ var suites_001 = /* :: */[
o["foo"] = 36;
return /* Eq */Block.__(0, [
36,
Js_primitive.undefined_to_opt(o["foo"])
Js_dict.get(o, "foo")
]);
})
],
Expand Down
11 changes: 6 additions & 5 deletions jscomp/test/js_json_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var Mt = require("./mt.js");
var $$Array = require("../../lib/js/array.js");
var Block = require("../../lib/js/block.js");
var Js_dict = require("../../lib/js/js_dict.js");
var Js_json = require("../../lib/js/js_json.js");
var Caml_array = require("../../lib/js/caml_array.js");
var Js_primitive = require("../../lib/js/js_primitive.js");
Expand Down Expand Up @@ -53,9 +54,9 @@ add_test("File \"js_json_test.ml\", line 23, characters 11-18", (function (param
if (typeof ty === "number" || ty.tag !== 2) {
return /* Ok */Block.__(4, [false]);
} else {
var match = ty[0]["x"];
var match = Js_dict.get(ty[0], "x");
if (match !== undefined) {
var ty2 = Js_json.classify(match);
var ty2 = Js_json.classify(Js_primitive.valFromOption(match));
if (typeof ty2 === "number" || ty2.tag !== 3) {
return /* Ok */Block.__(4, [false]);
} else {
Expand Down Expand Up @@ -224,7 +225,7 @@ if (typeof ty$4 === "number") {
}));
} else if (ty$4.tag === 2) {
var x = ty$4[0];
var ta = Js_json.classify(option_get(Js_primitive.undefined_to_opt(x["a"])));
var ta = Js_json.classify(option_get(Js_dict.get(x, "a")));
if (typeof ta === "number") {
add_test("File \"js_json_test.ml\", line 132, characters 18-25", (function (param) {
return /* Ok */Block.__(4, [false]);
Expand All @@ -238,7 +239,7 @@ if (typeof ty$4 === "number") {
return /* Ok */Block.__(4, [false]);
}));
} else {
var ty$5 = Js_json.classify(option_get(Js_primitive.undefined_to_opt(x["b"])));
var ty$5 = Js_json.classify(option_get(Js_dict.get(x, "b")));
if (typeof ty$5 === "number") {
add_test("File \"js_json_test.ml\", line 130, characters 22-29", (function (param) {
return /* Ok */Block.__(4, [false]);
Expand Down Expand Up @@ -460,7 +461,7 @@ if (typeof ty$6 === "number") {
return /* Ok */Block.__(4, [false]);
}));
} else if (ty$7.tag === 2) {
var ty$8 = Js_json.classify(option_get(Js_primitive.undefined_to_opt(ty$7[0]["a"])));
var ty$8 = Js_json.classify(option_get(Js_dict.get(ty$7[0], "a")));
if (typeof ty$8 === "number") {
add_test("File \"js_json_test.ml\", line 278, characters 20-27", (function (param) {
return /* Ok */Block.__(4, [false]);
Expand Down
10 changes: 1 addition & 9 deletions jscomp/test/local_exception_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ var d = [
3
];

var A$1 = Caml_exceptions.create("Local_exception_test.A");

var x = [
A$1,
3
];

var u = B;

exports.A = A;
exports.v = v;
exports.B = B;
exports.u = u;
exports.D = D;
exports.d = d;
exports.A = A$1;
exports.x = x;
/* No side effect */
38 changes: 36 additions & 2 deletions jscomp/test/recursive_module.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
'use strict';

var Mt = require("./mt.js");
var Curry = require("../../lib/js/curry.js");
var Js_exn = require("../../lib/js/js_exn.js");
var Caml_module = require("../../lib/js/caml_module.js");
var Caml_builtin_exceptions = require("../../lib/js/caml_builtin_exceptions.js");

var suites = /* record */[/* contents : [] */0];

var test_id = /* record */[/* contents */0];

function eq(loc, x, y) {
return Mt.eq_suites(test_id, suites, loc, x, y);
}

var Int32 = Caml_module.init_mod([
"recursive_module.ml",
9,
14,
6
], [[
0,
Expand All @@ -24,12 +36,34 @@ Caml_module.update_mod([[

var Int3 = Caml_module.init_mod([
"recursive_module.ml",
14,
19,
6
], [[0]]);

Caml_module.update_mod([[0]], Int3, Int3);

var tmp;

try {
Curry._1(Int3[/* u */0], 3);
tmp = 3;
}
catch (raw_exn){
var exn = Js_exn.internalToOCamlException(raw_exn);
if (exn[0] === Caml_builtin_exceptions.undefined_recursive_module) {
tmp = 4;
} else {
throw exn;
}
}

eq("File \"recursive_module.ml\", line 24, characters 6-13", 4, tmp);

Mt.from_pair_suites("recursive_module.ml", suites[0]);

exports.suites = suites;
exports.test_id = test_id;
exports.eq = eq;
exports.Int32 = Int32;
exports.Int3 = Int3;
/* Int32 Not a pure module */
9 changes: 9 additions & 0 deletions lib/js/js_dict.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
'use strict';

var Js_primitive = require("./js_primitive.js");

function get(dict, k) {
if ((k in dict)) {
return Js_primitive.some(dict[k]);
}

}

var unsafeDeleteKey = (
function(dict,key){
Expand Down Expand Up @@ -69,6 +77,7 @@ function map(f, source) {
return target;
}

exports.get = get;
exports.unsafeDeleteKey = unsafeDeleteKey;
exports.entries = entries;
exports.values = values;
Expand Down