From 701e68e6afd737852fc9c031a5ab865a10e760e2 Mon Sep 17 00:00:00 2001 From: kuroljov Date: Sun, 2 Jul 2017 23:48:47 +0300 Subject: [PATCH 1/2] assert: replace many if's with if-else statement If assert.fail has less than 3 arguments then some conditions will be applied. However after applying one of them there is no need to check for others. --- lib/assert.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 04b742c19a063a..5e8b997428ee33 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -62,18 +62,20 @@ function innerFail(actual, expected, message, operator, stackStartFunction) { } function fail(actual, expected, message, operator, stackStartFunction) { - if (arguments.length === 0) { + const args = arguments.length; + + if (args === 0) { message = 'Failed'; - } - if (arguments.length === 1) { + } else if (args === 1) { message = actual; actual = undefined; - } - if (arguments.length === 2) { + } else if (args === 2) { operator = '!='; } + innerFail(actual, expected, message, operator, stackStartFunction || fail); } + assert.fail = fail; // The AssertionError is defined in internal/error. From 73c630ccedfecd38fb9a8414031fc49fc3256911 Mon Sep 17 00:00:00 2001 From: kuroljov Date: Mon, 3 Jul 2017 21:52:34 +0300 Subject: [PATCH 2/2] assert: rename args to argsLen --- lib/assert.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 5e8b997428ee33..902bb82ce2b113 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -62,14 +62,14 @@ function innerFail(actual, expected, message, operator, stackStartFunction) { } function fail(actual, expected, message, operator, stackStartFunction) { - const args = arguments.length; + const argsLen = arguments.length; - if (args === 0) { + if (argsLen === 0) { message = 'Failed'; - } else if (args === 1) { + } else if (argsLen === 1) { message = actual; actual = undefined; - } else if (args === 2) { + } else if (argsLen === 2) { operator = '!='; }