Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2520,7 +2520,8 @@ function formatExtraProperties(ctx, value, recurseTimes, key, typedArray) {
ctx.indentationLvl -= 2;

// These entries are mainly getters. Should they be formatted like getters?
return ctx.stylize(`[${key}]: ${str}`, 'string');
const name = ctx.stylize(`[${key}]`, 'string');
return `${name}: ${str}`;
}

function formatProperty(ctx, value, recurseTimes, key, type, desc,
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2391,6 +2391,20 @@ assert.strictEqual(
inspect.styles.string = stringStyle;
}

// Special (extra) properties follow normal coloring:
// only the name is colored, ":" and space are unstyled.
{
const [open, close] = inspect.colors[inspect.styles.string];
const keyPattern = (k) => new RegExp(
`\\u001b\\[${open}m\\[${k}\\]\\u001b\\[${close}m: `
);
const colored = util.inspect(new Uint8Array(0), { showHidden: true, colors: true });
assert.match(colored, keyPattern('BYTES_PER_ELEMENT'));
assert.match(colored, keyPattern('length'));
assert.match(colored, keyPattern('byteLength'));
assert.match(colored, keyPattern('byteOffset'));
}

assert.strictEqual(
inspect([1, 3, 2], { sorted: true }),
inspect([1, 3, 2])
Expand Down
Loading