Skip to content

Commit 6e86a70

Browse files
viktor-kutniessen
authored andcommitted
assert: replace many if's with if-else statement
Replace multiple mutually exclusive `if` statements with if-else statements. PR-URL: #14043 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: David Cai <[email protected]>
1 parent b01ac75 commit 6e86a70

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/assert.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@ function innerFail(actual, expected, message, operator, stackStartFunction) {
6262
}
6363

6464
function fail(actual, expected, message, operator, stackStartFunction) {
65-
if (arguments.length === 0) {
65+
const argsLen = arguments.length;
66+
67+
if (argsLen === 0) {
6668
message = 'Failed';
67-
}
68-
if (arguments.length === 1) {
69+
} else if (argsLen === 1) {
6970
message = actual;
7071
actual = undefined;
71-
}
72-
if (arguments.length === 2) {
72+
} else if (argsLen === 2) {
7373
operator = '!=';
7474
}
75+
7576
innerFail(actual, expected, message, operator, stackStartFunction || fail);
7677
}
78+
7779
assert.fail = fail;
7880

7981
// The AssertionError is defined in internal/error.

0 commit comments

Comments
 (0)