From 45a8eb6ed3a2e6ee35fada021920f2d8014d3757 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Fri, 28 Dec 2018 02:29:18 +0100 Subject: [PATCH] util: simpler module namespace code This removes a special casing for this data type in the main function. PR-URL: https://github.com/nodejs/node/pull/25255 Reviewed-By: James M Snell --- lib/internal/util/inspect.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index ac6eb4fca1c299..8516755fa21fc6 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -557,7 +557,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { let braces; let noIterator = true; let i = 0; - let skip = false; const filter = ctx.showHidden ? ALL_PROPERTIES : ONLY_ENUMERABLE; let extrasType = kObjectType; @@ -701,7 +700,6 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { } else if (isModuleNamespaceObject(value)) { braces[0] = `[${tag}] {`; formatter = formatNamespaceObject; - skip = true; } else if (isBoxedPrimitive(value)) { let type; if (isNumberObject(value)) { @@ -761,11 +759,9 @@ function formatRaw(ctx, value, recurseTimes, typedArray) { const indentationLvl = ctx.indentationLvl; try { output = formatter(ctx, value, recurseTimes, keys); - if (skip === false) { - for (i = 0; i < keys.length; i++) { - output.push( - formatProperty(ctx, value, recurseTimes, keys[i], extrasType)); - } + for (i = 0; i < keys.length; i++) { + output.push( + formatProperty(ctx, value, recurseTimes, keys[i], extrasType)); } } catch (err) { return handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl); @@ -875,9 +871,8 @@ function formatError(value) { } function formatNamespaceObject(ctx, value, recurseTimes, keys) { - const len = keys.length; - const output = new Array(len); - for (var i = 0; i < len; i++) { + const output = new Array(keys.length); + for (var i = 0; i < keys.length; i++) { try { output[i] = formatProperty(ctx, value, recurseTimes, keys[i], kObjectType); @@ -897,6 +892,8 @@ function formatNamespaceObject(ctx, value, recurseTimes, keys) { ctx.stylize('', 'special'); } } + // Reset the keys to an empty array. This prevents duplicated inspection. + keys.length = 0; return output; }