console: remove unreachable code by Trott · Pull Request #26906 · nodejs/node (original) (raw)
In the current code, line 497 checks if item
is null
or undefined
.
However, item
is guaranteed to be a non-null object or function at
that point.
- Lines 484/485 set
primitive
totrue
ifitem
is null or
undefined. - Line 486 skips line 497 if
primitive
is true (which it will always
be ifitem
is null or undefined) andproperties
is undefined. So
the only way to get to line 497 whenitem
is null or undefined is ifproperties
is specified. - Line 494 skips line 497 if
primitive
is true (which it will always
be ifitem
is null or undefined) andproperties
are specified
(which will always be the case or else thiselse
block is skipped.)
Here are the current lines 484 through 497:
const primitive = item === null ||
(typeof item !== 'function' && typeof item !== 'object');
if (properties === undefined && primitive) {
hasPrimitives = true;
valuesKeyArray[i] = _inspect(item);
} else {
const keys = properties || ObjectKeys(item);
for (const key of keys) {
if (map[key] === undefined)
map[key] = [];
if ((primitive && properties) || !hasOwnProperty(item, key))
map[key][i] = '';
else
map[key][i] = item == null ? item : _inspect(item[key]);
This change removes the unnecessary ternary in that final line,
simplifying it to:
map[key][i] = _inspect(item[key]);
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes- commit message follows commit guidelines