Skip to content

Commit af0fbfc

Browse files
committed
up to ReScript v11 and introduce proper JSON.t
1 parent 3727d63 commit af0fbfc

15 files changed

+145
-56
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.3.0",
3+
"version": "1.0.0",
44
"sources": [
55
{
66
"dir": "src",

package-lock.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@rescript/core",
3-
"version": "0.3.0",
3+
"version": "1.0.0",
44
"scripts": {
55
"clean": "rescript clean",
66
"build": "rescript",
@@ -22,10 +22,10 @@
2222
"src/**/*.resi"
2323
],
2424
"peerDependencies": {
25-
"rescript": ">= 10.1.0"
25+
"rescript": ">= 11.0.0-alpha.4"
2626
},
2727
"devDependencies": {
28-
"rescript": "10.1.4",
29-
"@babel/code-frame": "7.18.6"
28+
"@babel/code-frame": "7.18.6",
29+
"rescript": "11.0.0-alpha.4"
3030
}
3131
}

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 {
@@ -14,7 +14,7 @@ function getExn(x) {
1414

1515
function mapWithDefault(opt, $$default, f) {
1616
var f$1 = Curry.__1(f);
17-
if (opt.TAG === /* Ok */0) {
17+
if (opt.TAG === "Ok") {
1818
return f$1(opt._0);
1919
} else {
2020
return $$default;
@@ -23,49 +23,49 @@ function mapWithDefault(opt, $$default, f) {
2323

2424
function map(opt, f) {
2525
var f$1 = Curry.__1(f);
26-
if (opt.TAG === /* Ok */0) {
26+
if (opt.TAG === "Ok") {
2727
return {
28-
TAG: /* Ok */0,
28+
TAG: "Ok",
2929
_0: f$1(opt._0)
3030
};
3131
} else {
3232
return {
33-
TAG: /* Error */1,
33+
TAG: "Error",
3434
_0: opt._0
3535
};
3636
}
3737
}
3838

3939
function flatMap(opt, f) {
4040
var f$1 = Curry.__1(f);
41-
if (opt.TAG === /* Ok */0) {
41+
if (opt.TAG === "Ok") {
4242
return f$1(opt._0);
4343
} else {
4444
return {
45-
TAG: /* Error */1,
45+
TAG: "Error",
4646
_0: opt._0
4747
};
4848
}
4949
}
5050

5151
function getWithDefault(opt, $$default) {
52-
if (opt.TAG === /* Ok */0) {
52+
if (opt.TAG === "Ok") {
5353
return opt._0;
5454
} else {
5555
return $$default;
5656
}
5757
}
5858

5959
function isOk(x) {
60-
if (x.TAG === /* Ok */0) {
60+
if (x.TAG === "Ok") {
6161
return true;
6262
} else {
6363
return false;
6464
}
6565
}
6666

6767
function isError(x) {
68-
if (x.TAG === /* Ok */0) {
68+
if (x.TAG === "Ok") {
6969
return false;
7070
} else {
7171
return true;
@@ -74,13 +74,13 @@ function isError(x) {
7474

7575
function eq(a, b, f) {
7676
var f$1 = Curry.__2(f);
77-
if (a.TAG === /* Ok */0) {
78-
if (b.TAG === /* Ok */0) {
77+
if (a.TAG === "Ok") {
78+
if (b.TAG === "Ok") {
7979
return f$1(a._0, b._0);
8080
} else {
8181
return false;
8282
}
83-
} else if (b.TAG === /* Ok */0) {
83+
} else if (b.TAG === "Ok") {
8484
return false;
8585
} else {
8686
return true;
@@ -89,21 +89,21 @@ function eq(a, b, f) {
8989

9090
function cmp(a, b, f) {
9191
var f$1 = Curry.__2(f);
92-
if (a.TAG === /* Ok */0) {
93-
if (b.TAG === /* Ok */0) {
92+
if (a.TAG === "Ok") {
93+
if (b.TAG === "Ok") {
9494
return f$1(a._0, b._0);
9595
} else {
9696
return 1;
9797
}
98-
} else if (b.TAG === /* Ok */0) {
98+
} else if (b.TAG === "Ok") {
9999
return -1;
100100
} else {
101101
return 0;
102102
}
103103
}
104104

105105
function forEach(r, f) {
106-
if (r.TAG === /* Ok */0) {
106+
if (r.TAG === "Ok") {
107107
return Curry._1(f, r._0);
108108
}
109109

src/Core__Type.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,38 @@ function classify(value) {
66
switch (match) {
77
case "[object Boolean]" :
88
return {
9-
TAG: /* Bool */0,
9+
TAG: "Bool",
1010
_0: value
1111
};
1212
case "[object AsyncFunction]" :
1313
case "[object Function]" :
1414
case "[object GeneratorFunction]" :
1515
return {
16-
TAG: /* Function */4,
16+
TAG: "Function",
1717
_0: value
1818
};
1919
case "[object Null]" :
20-
return /* Null */0;
20+
return "Null";
2121
case "[object Number]" :
2222
return {
23-
TAG: /* Number */2,
23+
TAG: "Number",
2424
_0: value
2525
};
2626
case "[object String]" :
2727
return {
28-
TAG: /* String */1,
28+
TAG: "String",
2929
_0: value
3030
};
3131
case "[object Symbol]" :
3232
return {
33-
TAG: /* Symbol */5,
33+
TAG: "Symbol",
3434
_0: value
3535
};
3636
case "[object Undefined]" :
37-
return /* Undefined */1;
37+
return "Undefined";
3838
default:
3939
return {
40-
TAG: /* Object */3,
40+
TAG: "Object",
4141
_0: value
4242
};
4343
}

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") {
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")) {
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)