Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a333272

Browse filesBrowse files
BridgeARaddaleax
authored andcommitted
util: code cleanup
Remove some dead code plus some minor refactoring for readability. The constructor can not be an empty string anymore, so just remove that check. PR-URL: #25255 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 7696d1f commit a333272
Copy full SHA for a333272

File tree

Expand file treeCollapse file tree

2 files changed

+30
-41
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-41
lines changed
Open diff view settings
Collapse file

‎lib/internal/util/inspect.js‎

Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js
+30-40Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -211,34 +211,34 @@ Object.defineProperty(inspect, 'defaultOptions', {
211211

212212
// http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
213213
inspect.colors = Object.assign(Object.create(null), {
214-
'bold': [1, 22],
215-
'italic': [3, 23],
216-
'underline': [4, 24],
217-
'inverse': [7, 27],
218-
'white': [37, 39],
219-
'grey': [90, 39],
220-
'black': [30, 39],
221-
'blue': [34, 39],
222-
'cyan': [36, 39],
223-
'green': [32, 39],
224-
'magenta': [35, 39],
225-
'red': [31, 39],
226-
'yellow': [33, 39]
214+
bold: [1, 22],
215+
italic: [3, 23],
216+
underline: [4, 24],
217+
inverse: [7, 27],
218+
white: [37, 39],
219+
grey: [90, 39],
220+
black: [30, 39],
221+
blue: [34, 39],
222+
cyan: [36, 39],
223+
green: [32, 39],
224+
magenta: [35, 39],
225+
red: [31, 39],
226+
yellow: [33, 39]
227227
});
228228

229229
// Don't use 'blue' not visible on cmd.exe
230230
inspect.styles = Object.assign(Object.create(null), {
231-
'special': 'cyan',
232-
'number': 'yellow',
233-
'bigint': 'yellow',
234-
'boolean': 'yellow',
235-
'undefined': 'grey',
236-
'null': 'bold',
237-
'string': 'green',
238-
'symbol': 'green',
239-
'date': 'magenta',
231+
special: 'cyan',
232+
number: 'yellow',
233+
bigint: 'yellow',
234+
boolean: 'yellow',
235+
undefined: 'grey',
236+
null: 'bold',
237+
string: 'green',
238+
symbol: 'green',
239+
date: 'magenta',
240240
// "name": intentionally not styling
241-
'regexp': 'red'
241+
regexp: 'red'
242242
});
243243

244244
function addQuotes(str, quotes) {
@@ -358,14 +358,10 @@ function getPrefix(constructor, tag, fallback) {
358358
return `[${fallback}: null prototype] `;
359359
}
360360

361-
if (constructor !== '') {
362-
if (tag !== '' && constructor !== tag) {
363-
return `${constructor} [${tag}] `;
364-
}
365-
return `${constructor} `;
361+
if (tag !== '' && constructor !== tag) {
362+
return `${constructor} [${tag}] `;
366363
}
367-
368-
return '';
364+
return `${constructor} `;
369365
}
370366

371367
const getBoxedValue = formatPrimitive.bind(null, stylizeNoColor);
@@ -619,16 +615,12 @@ function formatRaw(ctx, value, recurseTimes, typedArray) {
619615
braces = ['{', '}'];
620616
if (constructor === 'Object') {
621617
if (isArgumentsObject(value)) {
622-
if (keys.length === 0)
623-
return '[Arguments] {}';
624618
braces[0] = '[Arguments] {';
625619
} else if (tag !== '') {
626620
braces[0] = `${getPrefix(constructor, tag, 'Object')}{`;
627-
if (keys.length === 0) {
628-
return `${braces[0]}}`;
629-
}
630-
} else if (keys.length === 0) {
631-
return '{}';
621+
}
622+
if (keys.length === 0) {
623+
return `${braces[0]}}`;
632624
}
633625
} else if (typeof value === 'function') {
634626
const type = constructor || tag || 'Function';
@@ -822,9 +814,7 @@ function handleMaxCallStackSize(ctx, err, constructor, tag, indentationLvl) {
822814

823815
function formatNumber(fn, value) {
824816
// Format -0 as '-0'. Checking `value === -0` won't distinguish 0 from -0.
825-
if (Object.is(value, -0))
826-
return fn('-0', 'number');
827-
return fn(`${value}`, 'number');
817+
return fn(Object.is(value, -0) ? '-0' : `${value}`, 'number');
828818
}
829819

830820
function formatBigInt(fn, value) {
Collapse file

‎test/parallel/test-util-inspect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,7 +1853,6 @@ assert.strictEqual(
18531853
util.inspect(new StorageObject()),
18541854
'<[Object: null prototype] {}> {}'
18551855
);
1856-
18571856
}
18581857

18591858
// Check that the fallback always works.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.