Skip to content

Commit 41e2fd6

Browse files
committed
Simplfy e?true:false to e
1 parent 7d10374 commit 41e2fd6

22 files changed

+38
-141
lines changed

compiler/core/js_exp_make.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,7 @@ let rec econd ?comment (pred : t) (ifso : t) (ifnot : t) : t =
977977
| (Number _ | Array _ | Caml_block _), _, _ when no_side_effect pred ->
978978
ifso (* a block can not be false in OCAML, CF - relies on flow inference*)
979979
| Bool true, _, _ -> ifso
980+
| _, Bool true, Bool false -> pred
980981
| _, Cond (pred1, ifso1, ifnot1), _
981982
when Js_analyzer.eq_expression ifnot1 ifnot ->
982983
(* {[

lib/es6/Belt_Result.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ function getWithDefault(opt, $$default) {
5353
}
5454

5555
function isOk(x) {
56-
if (x.TAG === "Ok") {
57-
return true;
58-
} else {
59-
return false;
60-
}
56+
return x.TAG === "Ok";
6157
}
6258

6359
function isError(x) {

lib/es6/Result.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ function getOr(opt, $$default) {
4747
}
4848

4949
function isOk(x) {
50-
if (x.TAG === "Ok") {
51-
return true;
52-
} else {
53-
return false;
54-
}
50+
return x.TAG === "Ok";
5551
}
5652

5753
function isError(x) {

lib/js/Belt_Result.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,7 @@ function getWithDefault(opt, $$default) {
5353
}
5454

5555
function isOk(x) {
56-
if (x.TAG === "Ok") {
57-
return true;
58-
} else {
59-
return false;
60-
}
56+
return x.TAG === "Ok";
6157
}
6258

6359
function isError(x) {

lib/js/Result.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,7 @@ function getOr(opt, $$default) {
4747
}
4848

4949
function isOk(x) {
50-
if (x.TAG === "Ok") {
51-
return true;
52-
} else {
53-
return false;
54-
}
50+
return x.TAG === "Ok";
5551
}
5652

5753
function isError(x) {

tests/tests/src/bdd.mjs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ function $$eval(_bdd, vars) {
77
while (true) {
88
let bdd = _bdd;
99
if (typeof bdd !== "object") {
10-
if (bdd === "One") {
11-
return true;
12-
} else {
13-
return false;
14-
}
10+
return bdd === "One";
1511
}
1612
if (Primitive_array.get(vars, bdd._1)) {
1713
_bdd = bdd._3;
@@ -366,11 +362,7 @@ function random_vars(n) {
366362

367363
function bool_equal(a, b) {
368364
if (a) {
369-
if (b) {
370-
return true;
371-
} else {
372-
return false;
373-
}
365+
return b;
374366
} else if (b) {
375367
return false;
376368
} else {

tests/tests/src/caml_compare_test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ try {
1010
function_equal_test = Primitive_object.equal(x => x + 1 | 0, x => x + 2 | 0);
1111
} catch (raw_exn) {
1212
let exn = Primitive_exceptions.internalToException(raw_exn);
13-
function_equal_test = exn.RE_EXN_ID === "Invalid_argument" && exn._1 === "equal: functional value" ? true : false;
13+
function_equal_test = exn.RE_EXN_ID === "Invalid_argument" ? exn._1 === "equal: functional value" : false;
1414
}
1515

1616
let suites = {

tests/tests/src/core/Core_JsonTests.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function decodeJsonTest() {
1717
decodedCorrectly = false;
1818
} else {
1919
let match$3 = match$1[1];
20-
decodedCorrectly = match$3 === null || !(typeof match$3 === "boolean" && !match$3) ? false : true;
20+
decodedCorrectly = match$3 === null ? false : typeof match$3 === "boolean" && !match$3;
2121
}
2222
} else {
2323
decodedCorrectly = false;

tests/tests/src/core/Core_NullableTests.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function shouldHandleNullableValues() {
77
let tUndefined = undefined;
88
let tValue = "hello";
99
let tmp;
10-
tmp = tNull === null ? true : false;
10+
tmp = tNull === null || tNull === undefined ? tNull === null : false;
1111
Test.run([
1212
[
1313
"Core_NullableTests.res",
@@ -18,7 +18,7 @@ function shouldHandleNullableValues() {
1818
"Should handle null"
1919
], tmp, (prim0, prim1) => prim0 === prim1, true);
2020
let tmp$1;
21-
tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null ? true : false;
21+
tmp$1 = (tUndefined === null || tUndefined === undefined) && tUndefined !== null;
2222
Test.run([
2323
[
2424
"Core_NullableTests.res",
@@ -29,7 +29,7 @@ function shouldHandleNullableValues() {
2929
"Should handle undefined"
3030
], tmp$1, (prim0, prim1) => prim0 === prim1, true);
3131
let tmp$2;
32-
tmp$2 = tValue === null || tValue === undefined || tValue !== "hello" ? false : true;
32+
tmp$2 = tValue === null || tValue === undefined ? false : tValue === "hello";
3333
Test.run([
3434
[
3535
"Core_NullableTests.res",

tests/tests/src/core/Core_PromiseTest.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ function testExnThrow() {
171171
Error: new Error()
172172
};
173173
}), e => {
174-
let isTestErr = e.RE_EXN_ID === TestError && e._1 === "Thrown exn" ? true : false;
174+
let isTestErr = e.RE_EXN_ID === TestError ? e._1 === "Thrown exn" : false;
175175
Test.run([
176176
[
177177
"Core_PromiseTest.res",

0 commit comments

Comments
 (0)