Skip to content

Commit 05e0884

Browse files
committed
up to ReScript v11 and introduce proper JSON.t
1 parent 96a3366 commit 05e0884

16 files changed

+154
-62
lines changed

bsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rescript/core",
3-
"version": "0.5.0",
3+
"version": "1.0.0",
44
"sources": [
55
{
66
"dir": "src",

package-lock.json

Lines changed: 11 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"src/**/*.mjs"
2424
],
2525
"peerDependencies": {
26-
"rescript": "^10.1.0 || ^11.0.0-alpha.0 || next"
26+
"rescript": ">= 11.0.0-alpha.4"
2727
},
2828
"devDependencies": {
29-
"rescript": "10.1.4",
30-
"@babel/code-frame": "7.18.6"
29+
"@babel/code-frame": "7.18.6",
30+
"rescript": "11.0.0-alpha.6"
3131
}
3232
}

src/Core__Error.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var $$TypeError = {};
1414
var $$URIError = {};
1515

1616
function panic(msg) {
17-
throw new Error("Panic! " + msg + "");
17+
throw new Error("Panic! " + msg);
1818
}
1919

2020
export {

src/Core__JSON.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@ function classify(value) {
77
switch (match) {
88
case "[object Array]" :
99
return {
10-
TAG: /* Array */4,
10+
TAG: "Array",
1111
_0: value
1212
};
1313
case "[object Boolean]" :
1414
return {
15-
TAG: /* Bool */0,
15+
TAG: "Bool",
1616
_0: value
1717
};
1818
case "[object Null]" :
19-
return /* Null */0;
19+
return "Null";
2020
case "[object Number]" :
2121
return {
22-
TAG: /* Number */2,
22+
TAG: "Number",
2323
_0: value
2424
};
2525
case "[object String]" :
2626
return {
27-
TAG: /* String */1,
27+
TAG: "String",
2828
_0: value
2929
};
3030
default:
3131
return {
32-
TAG: /* Object */3,
32+
TAG: "Object",
3333
_0: value
3434
};
3535
}

src/Core__JSON.res

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
type t = Js.Json.t
1+
@unboxed
2+
type rec t = Js.Json.t =
3+
| @as(false) False
4+
| @as(true) True
5+
| @as(null) Null
6+
| String(string)
7+
| Number(float)
8+
| Object(Js.Dict.t<t>)
9+
| Array(array<t>)
210

311
@raises @val external parseExn: string => t = "JSON.parse"
412
@raises @val external parseExnWithReviver: (string, (string, t) => t) => t = "JSON.parse"

src/Core__JSON.resi

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ Functions for interacting with JSON.
33
*/
44

55
/**
6-
A type representing a JSON object.
6+
A type representing a valid JSON value.
77
*/
8-
type t = Js.Json.t
8+
@unboxed
9+
type rec t = Js.Json.t =
10+
| @as(false) False
11+
| @as(true) True
12+
| @as(null) Null
13+
| String(string)
14+
| Number(float)
15+
| Object(Js.Dict.t<t>)
16+
| Array(array<t>)
917

1018
/**
1119
`parseExn(string)`

src/Core__Result.mjs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as Curry from "rescript/lib/es6/curry.js";
44

55
function getExn(x) {
6-
if (x.TAG === /* Ok */0) {
6+
if (x.TAG === "Ok") {
77
return x._0;
88
}
99
throw {
@@ -13,17 +13,17 @@ function getExn(x) {
1313
}
1414

1515
function mapOr(opt, $$default, f) {
16-
if (opt.TAG === /* Ok */0) {
16+
if (opt.TAG === "Ok") {
1717
return Curry._1(f, opt._0);
1818
} else {
1919
return $$default;
2020
}
2121
}
2222

2323
function map(opt, f) {
24-
if (opt.TAG === /* Ok */0) {
24+
if (opt.TAG === "Ok") {
2525
return {
26-
TAG: /* Ok */0,
26+
TAG: "Ok",
2727
_0: Curry._1(f, opt._0)
2828
};
2929
} else {
@@ -32,78 +32,78 @@ function map(opt, f) {
3232
}
3333

3434
function flatMap(opt, f) {
35-
if (opt.TAG === /* Ok */0) {
35+
if (opt.TAG === "Ok") {
3636
return Curry._1(f, opt._0);
3737
} else {
3838
return opt;
3939
}
4040
}
4141

4242
function getOr(opt, $$default) {
43-
if (opt.TAG === /* Ok */0) {
43+
if (opt.TAG === "Ok") {
4444
return opt._0;
4545
} else {
4646
return $$default;
4747
}
4848
}
4949

5050
function isOk(x) {
51-
if (x.TAG === /* Ok */0) {
51+
if (x.TAG === "Ok") {
5252
return true;
5353
} else {
5454
return false;
5555
}
5656
}
5757

5858
function isError(x) {
59-
if (x.TAG === /* Ok */0) {
59+
if (x.TAG === "Ok") {
6060
return false;
6161
} else {
6262
return true;
6363
}
6464
}
6565

6666
function equal(a, b, f) {
67-
if (a.TAG === /* Ok */0) {
68-
if (b.TAG === /* Ok */0) {
67+
if (a.TAG === "Ok") {
68+
if (b.TAG === "Ok") {
6969
return Curry._2(f, a._0, b._0);
7070
} else {
7171
return false;
7272
}
73-
} else if (b.TAG === /* Ok */0) {
73+
} else if (b.TAG === "Ok") {
7474
return false;
7575
} else {
7676
return true;
7777
}
7878
}
7979

8080
function compare(a, b, f) {
81-
if (a.TAG === /* Ok */0) {
82-
if (b.TAG === /* Ok */0) {
81+
if (a.TAG === "Ok") {
82+
if (b.TAG === "Ok") {
8383
return Curry._2(f, a._0, b._0);
8484
} else {
8585
return 1;
8686
}
87-
} else if (b.TAG === /* Ok */0) {
87+
} else if (b.TAG === "Ok") {
8888
return -1;
8989
} else {
9090
return 0;
9191
}
9292
}
9393

9494
function forEach(r, f) {
95-
if (r.TAG === /* Ok */0) {
95+
if (r.TAG === "Ok") {
9696
return Curry._1(f, r._0);
9797
}
9898

9999
}
100100

101101
function mapError(r, f) {
102-
if (r.TAG === /* Ok */0) {
102+
if (r.TAG === "Ok") {
103103
return r;
104104
} else {
105105
return {
106-
TAG: /* Error */1,
106+
TAG: "Error",
107107
_0: Curry._1(f, r._0)
108108
};
109109
}

src/Core__Type.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,43 @@ function classify(value) {
66
switch (match) {
77
case "[object BigInt]" :
88
return {
9-
TAG: /* BigInt */6,
9+
TAG: "BigInt",
1010
_0: value
1111
};
1212
case "[object Boolean]" :
1313
return {
14-
TAG: /* Bool */0,
14+
TAG: "Bool",
1515
_0: value
1616
};
1717
case "[object AsyncFunction]" :
1818
case "[object Function]" :
1919
case "[object GeneratorFunction]" :
2020
return {
21-
TAG: /* Function */4,
21+
TAG: "Function",
2222
_0: value
2323
};
2424
case "[object Null]" :
25-
return /* Null */0;
25+
return "Null";
2626
case "[object Number]" :
2727
return {
28-
TAG: /* Number */2,
28+
TAG: "Number",
2929
_0: value
3030
};
3131
case "[object String]" :
3232
return {
33-
TAG: /* String */1,
33+
TAG: "String",
3434
_0: value
3535
};
3636
case "[object Symbol]" :
3737
return {
38-
TAG: /* Symbol */5,
38+
TAG: "Symbol",
3939
_0: value
4040
};
4141
case "[object Undefined]" :
42-
return /* Undefined */1;
42+
return "Undefined";
4343
default:
4444
return {
45-
TAG: /* Object */3,
45+
TAG: "Object",
4646
_0: value
4747
};
4848
}

test/JsonTests.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
import * as Test from "./Test.mjs";
4+
5+
function decodeJsonTest(param) {
6+
var json = {"someProp":{"otherProp": null, "thirdProp": [true, false]}};
7+
var decodedCorrectly;
8+
if (!Array.isArray(json) && (json === null || typeof json !== "object") && typeof json !== "number" && typeof json !== "string" || !(typeof json === "object" && !Array.isArray(json))) {
9+
decodedCorrectly = false;
10+
} else {
11+
var match = json["someProp"];
12+
if (match !== undefined && !(!Array.isArray(match) && (match === null || typeof match !== "object") && typeof match !== "number" && typeof match !== "string" || !(typeof match === "object" && !Array.isArray(match)))) {
13+
var match$1 = match["thirdProp"];
14+
if (match$1 !== undefined && !(!Array.isArray(match$1) && (match$1 === null || typeof match$1 !== "object") && typeof match$1 !== "number" && typeof match$1 !== "string" || !(Array.isArray(match$1) && match$1.length === 2))) {
15+
var match$2 = match$1[0];
16+
if (!Array.isArray(match$2) && (match$2 === null || typeof match$2 !== "object") && typeof match$2 !== "number" && typeof match$2 !== "string" && match$2 === true) {
17+
var match$3 = match$1[1];
18+
decodedCorrectly = !Array.isArray(match$3) && (match$3 === null || typeof match$3 !== "object") && typeof match$3 !== "number" && typeof match$3 !== "string" && match$3 === false ? true : false;
19+
} else {
20+
decodedCorrectly = false;
21+
}
22+
} else {
23+
decodedCorrectly = false;
24+
}
25+
} else {
26+
decodedCorrectly = false;
27+
}
28+
}
29+
Test.run([
30+
[
31+
"JsonTests.res",
32+
19,
33+
22,
34+
55
35+
],
36+
"Should decode JSON successfully"
37+
], decodedCorrectly, (function (prim0, prim1) {
38+
return prim0 === prim1;
39+
}), true);
40+
}
41+
42+
decodeJsonTest(undefined);
43+
44+
export {
45+
decodeJsonTest ,
46+
}
47+
/* Not a pure module */

0 commit comments

Comments
 (0)