Skip to content

Commit 57ae88b

Browse files
committed
util: simpler module namespace code
This removes a special casing for this data type in the main function. PR-URL: nodejs#25255 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5db3228 commit 57ae88b

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

lib/internal/util/inspect.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ function formatRaw(ctx, value, recurseTimes) {
556556
let braces;
557557
let noIterator = true;
558558
let i = 0;
559-
let skip = false;
560559
const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE;
561560

562561
let extrasType = kObjectType;
@@ -697,7 +696,6 @@ function formatRaw(ctx, value, recurseTimes) {
697696
} else if (isModuleNamespaceObject(value)) {
698697
braces[0] = `[${tag}] {`;
699698
formatter = formatNamespaceObject;
700-
skip = true;
701699
} else if (isBoxedPrimitive(value)) {
702700
let type;
703701
if (isNumberObject(value)) {
@@ -757,11 +755,9 @@ function formatRaw(ctx, value, recurseTimes) {
757755
const indentationLvl = ctx.indentationLvl;
758756
try {
759757
output = formatter(ctx, value, recurseTimes, keys);
760-
if (skip === false) {
761-
for (i = 0; i < keys.length; i++) {
762-
output.push(
763-
formatProperty(ctx, value, recurseTimes, keys[i], extrasType));
764-
}
758+
for (i = 0; i < keys.length; i++) {
759+
output.push(
760+
formatProperty(ctx, value, recurseTimes, keys[i], extrasType));
765761
}
766762
} catch (err) {
767763
return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl);
@@ -871,9 +867,8 @@ function formatError(value) {
871867
}
872868

873869
function formatNamespaceObject(ctx, value, recurseTimes, keys) {
874-
const len = keys.length;
875-
const output = new Array(len);
876-
for (var i = 0; i < len; i++) {
870+
const output = new Array(keys.length);
871+
for (var i = 0; i < keys.length; i++) {
877872
try {
878873
output[i] = formatProperty(ctx, value, recurseTimes, keys[i],
879874
kObjectType);
@@ -893,6 +888,8 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) {
893888
ctx.stylize('<uninitialized>', 'special');
894889
}
895890
}
891+
// Reset the keys to an empty array. This prevents duplicated inspection.
892+
keys.length = 0;
896893
return output;
897894
}
898895

0 commit comments

Comments
 (0)