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
16 changes: 13 additions & 3 deletions lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1031,10 +1031,20 @@ function getPrefix(constructor, tag, fallback, size = '') {
return `[${fallback}${size}: null prototype] `;
}

if (tag !== '' && constructor !== tag) {
return `${constructor}${size} [${tag}] `;
let result = `${constructor}${size} `;
if (tag !== '') {
const position = constructor.indexOf(tag);
if (position === -1) {
result += `[${tag}] `;
} else {
const endPos = position + tag.length;
if (endPos !== constructor.length &&
constructor[endPos] === constructor[endPos].toLowerCase()) {
result += `[${tag}] `;
}
}
}
return `${constructor}${size} `;
return result;
}

// Look up the keys of the object.
Expand Down
2 changes: 1 addition & 1 deletion test/es-module/test-esm-loader-with-syntax-error.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('ESM: loader with syntax error', { concurrency: !process.env.TEST_PARAL
path('print-error-message.js'),
]);

match(stderr, /SyntaxError \[Error\]:/);
match(stderr, /SyntaxError/);
ok(!stderr.includes('Bad command or file name'));
notStrictEqual(code, 0);
});
Expand Down
29 changes: 26 additions & 3 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -1415,11 +1415,11 @@ if (typeof Symbol !== 'undefined') {
assert.strictEqual(util.inspect(new ArraySubclass(1, 2, 3)),
'ArraySubclass(3) [ 1, 2, 3 ]');
assert.strictEqual(util.inspect(new SetSubclass([1, 2, 3])),
'SetSubclass(3) [Set] { 1, 2, 3 }');
'SetSubclass(3) { 1, 2, 3 }');
assert.strictEqual(util.inspect(new MapSubclass([['foo', 42]])),
"MapSubclass(1) [Map] { 'foo' => 42 }");
"MapSubclass(1) { 'foo' => 42 }");
assert.strictEqual(util.inspect(new PromiseSubclass(() => {})),
'PromiseSubclass [Promise] { <pending> }');
'PromiseSubclass { <pending> }');
assert.strictEqual(util.inspect(new SymbolNameClass()),
'Symbol(name) {}');
assert.strictEqual(
Expand All @@ -1430,6 +1430,29 @@ if (typeof Symbol !== 'undefined') {
util.inspect(Object.setPrototypeOf(x, null)),
'[ObjectSubclass: null prototype] { foo: 42 }'
);

class MiddleErrorPart extends Error {}
assert(util.inspect(new MiddleErrorPart('foo')).includes('MiddleErrorPart: foo'));

class MapClass extends Map {}
assert.strictEqual(util.inspect(new MapClass([['key', 'value']])),
"MapClass(1) { 'key' => 'value' }");

class AbcMap extends Map {}
assert.strictEqual(util.inspect(new AbcMap([['key', 'value']])),
"AbcMap(1) { 'key' => 'value' }");

class SetAbc extends Set {}
assert.strictEqual(util.inspect(new SetAbc([1, 2, 3])),
'SetAbc(3) { 1, 2, 3 }');

class FooSet extends Set {}
assert.strictEqual(util.inspect(new FooSet([1, 2, 3])),
'FooSet(3) { 1, 2, 3 }');

class Settings extends Set {}
assert.strictEqual(util.inspect(new Settings([1, 2, 3])),
'Settings(3) [Set] { 1, 2, 3 }');
}

// Empty and circular before depth.
Expand Down
Loading