Skip to content

Commit 59b2ed7

Browse files
committed
rebased on #7135
1 parent 387bfe4 commit 59b2ed7

File tree

1 file changed

+18
-54
lines changed

1 file changed

+18
-54
lines changed

tests/tests/src/json_decoders.mjs

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,50 @@
33
import * as $$Array from "rescript/lib/es6/Array.js";
44

55
function decodeUser(json) {
6-
if (json === null) {
7-
return;
8-
}
96
if (!(typeof json === "object" && !Array.isArray(json))) {
107
return;
118
}
12-
let match = json.id;
13-
if (match === undefined) {
14-
return;
15-
}
16-
if (match === null) {
17-
return;
18-
}
19-
if (typeof match !== "string") {
20-
return;
21-
}
22-
let match$1 = json.name;
23-
if (match$1 === undefined) {
24-
return;
25-
}
26-
if (match$1 === null) {
27-
return;
28-
}
29-
if (typeof match$1 !== "string") {
9+
let id = json.id;
10+
if (typeof id !== "string") {
3011
return;
3112
}
32-
let match$2 = json.age;
33-
if (match$2 === undefined) {
13+
let name = json.name;
14+
if (typeof name !== "string") {
3415
return;
3516
}
36-
if (match$2 === null) {
37-
return;
38-
}
39-
if (typeof match$2 !== "number") {
17+
let age = json.age;
18+
if (typeof age !== "number") {
4019
return;
4120
}
4221
let email = json.email;
4322
let tmp;
4423
tmp = typeof email === "string" ? email : undefined;
4524
return {
46-
id: match,
47-
name: match$1,
48-
age: match$2 | 0,
25+
id: id,
26+
name: name,
27+
age: age | 0,
4928
email: tmp
5029
};
5130
}
5231

5332
function decodeGroup(json) {
54-
if (json === null) {
55-
return;
56-
}
5733
if (!(typeof json === "object" && !Array.isArray(json))) {
5834
return;
5935
}
60-
let match = json.id;
61-
if (match === undefined) {
62-
return;
63-
}
64-
if (match === null) {
65-
return;
66-
}
67-
if (typeof match !== "string") {
68-
return;
69-
}
70-
let match$1 = json.name;
71-
if (match$1 === undefined) {
72-
return;
73-
}
74-
if (match$1 === null) {
36+
let id = json.id;
37+
if (typeof id !== "string") {
7538
return;
7639
}
77-
if (typeof match$1 !== "string") {
40+
let name = json.name;
41+
if (typeof name !== "string") {
7842
return;
7943
}
80-
let match$2 = json.users;
81-
if (match$2 !== undefined && !(match$2 === null || !Array.isArray(match$2))) {
44+
let users = json.users;
45+
if (Array.isArray(users)) {
8246
return {
83-
id: match,
84-
name: match$1,
85-
users: $$Array.filterMap(match$2, decodeUser)
47+
id: id,
48+
name: name,
49+
users: $$Array.filterMap(users, decodeUser)
8650
};
8751
}
8852

0 commit comments

Comments
 (0)