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 34c686b

Browse filesBrowse files
miguelmarcondesfaduh95
authored andcommitted
lib: update inspect output format for subclasses
PR-URL: #59687 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent c9cde35 commit 34c686b
Copy full SHA for 34c686b

File tree

Expand file treeCollapse file tree

3 files changed

+40
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+40
-7
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
+13-3Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -780,10 +780,20 @@ function getPrefix(constructor, tag, fallback, size = '') {
780780
return `[${fallback}${size}: null prototype] `;
781781
}
782782

783-
if (tag !== '' && constructor !== tag) {
784-
return `${constructor}${size} [${tag}] `;
783+
let result = `${constructor}${size} `;
784+
if (tag !== '') {
785+
const position = constructor.indexOf(tag);
786+
if (position === -1) {
787+
result += `[${tag}] `;
788+
} else {
789+
const endPos = position + tag.length;
790+
if (endPos !== constructor.length &&
791+
constructor[endPos] === constructor[endPos].toLowerCase()) {
792+
result += `[${tag}] `;
793+
}
794+
}
785795
}
786-
return `${constructor}${size} `;
796+
return result;
787797
}
788798

789799
// Look up the keys of the object.
Collapse file

‎test/es-module/test-esm-loader-with-syntax-error.mjs‎

Copy file name to clipboardExpand all lines: test/es-module/test-esm-loader-with-syntax-error.mjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARAL
1313
path('print-error-message.js'),
1414
]);
1515

16-
match(stderr, /SyntaxError \[Error\]:/);
16+
match(stderr, /SyntaxError/);
1717
ok(!stderr.includes('Bad command or file name'));
1818
notStrictEqual(code, 0);
1919
});
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-util-inspect.js
+26-3Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,11 @@ if (typeof Symbol !== 'undefined') {
14131413
assert.strictEqual(util.inspect(new ArraySubclass(1, 2, 3)),
14141414
'ArraySubclass(3) [ 1, 2, 3 ]');
14151415
assert.strictEqual(util.inspect(new SetSubclass([1, 2, 3])),
1416-
'SetSubclass(3) [Set] { 1, 2, 3 }');
1416+
'SetSubclass(3) { 1, 2, 3 }');
14171417
assert.strictEqual(util.inspect(new MapSubclass([['foo', 42]])),
1418-
"MapSubclass(1) [Map] { 'foo' => 42 }");
1418+
"MapSubclass(1) { 'foo' => 42 }");
14191419
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
1420-
'PromiseSubclass [Promise] { <pending> }');
1420+
'PromiseSubclass { <pending> }');
14211421
assert.strictEqual(util.inspect(new SymbolNameClass()),
14221422
'Symbol(name) {}');
14231423
assert.strictEqual(
@@ -1428,6 +1428,29 @@ if (typeof Symbol !== 'undefined') {
14281428
util.inspect(Object.setPrototypeOf(x, null)),
14291429
'[ObjectSubclass: null prototype] { foo: 42 }'
14301430
);
1431+
1432+
class MiddleErrorPart extends Error {}
1433+
assert(util.inspect(new MiddleErrorPart('foo')).includes('MiddleErrorPart: foo'));
1434+
1435+
class MapClass extends Map {}
1436+
assert.strictEqual(util.inspect(new MapClass([['key', 'value']])),
1437+
"MapClass(1) { 'key' => 'value' }");
1438+
1439+
class AbcMap extends Map {}
1440+
assert.strictEqual(util.inspect(new AbcMap([['key', 'value']])),
1441+
"AbcMap(1) { 'key' => 'value' }");
1442+
1443+
class SetAbc extends Set {}
1444+
assert.strictEqual(util.inspect(new SetAbc([1, 2, 3])),
1445+
'SetAbc(3) { 1, 2, 3 }');
1446+
1447+
class FooSet extends Set {}
1448+
assert.strictEqual(util.inspect(new FooSet([1, 2, 3])),
1449+
'FooSet(3) { 1, 2, 3 }');
1450+
1451+
class Settings extends Set {}
1452+
assert.strictEqual(util.inspect(new Settings([1, 2, 3])),
1453+
'Settings(3) [Set] { 1, 2, 3 }');
14311454
}
14321455

14331456
// Empty and circular before depth.

0 commit comments

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