Skip to content

Commit 396cc8e

Browse files
miguelmarcondesftargos
authored andcommitted
lib: update inspect output format for subclasses
PR-URL: #59687 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 69b5607 commit 396cc8e

3 files changed

Lines changed: 40 additions & 7 deletions

File tree

‎lib/internal/util/inspect.js‎

Lines 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+
letresult=`${constructor}${size} `;
784+
if(tag!==''){
785+
constposition=constructor.indexOf(tag);
786+
if(position===-1){
787+
result+=`[${tag}] `;
788+
}else{
789+
constendPos=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+
returnresult;
787797
}
788798

789799
// Look up the keys of the object.

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

Lines 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
});

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,11 +1415,11 @@ if (typeof Symbol !== 'undefined') {
14151415
assert.strictEqual(util.inspect(newArraySubclass(1,2,3)),
14161416
'ArraySubclass(3) [ 1, 2, 3 ]');
14171417
assert.strictEqual(util.inspect(newSetSubclass([1,2,3])),
1418-
'SetSubclass(3) [Set] { 1, 2, 3 }');
1418+
'SetSubclass(3) { 1, 2, 3 }');
14191419
assert.strictEqual(util.inspect(newMapSubclass([['foo',42]])),
1420-
"MapSubclass(1) [Map] { 'foo' => 42 }");
1420+
"MapSubclass(1) { 'foo' => 42 }");
14211421
assert.strictEqual(util.inspect(newPromiseSubclass(()=>{})),
1422-
'PromiseSubclass [Promise] { <pending> }');
1422+
'PromiseSubclass { <pending> }');
14231423
assert.strictEqual(util.inspect(newSymbolNameClass()),
14241424
'Symbol(name) {}');
14251425
assert.strictEqual(
@@ -1430,6 +1430,29 @@ if (typeof Symbol !== 'undefined') {
14301430
util.inspect(Object.setPrototypeOf(x,null)),
14311431
'[ObjectSubclass: null prototype] { foo: 42 }'
14321432
);
1433+
1434+
classMiddleErrorPartextendsError{}
1435+
assert(util.inspect(newMiddleErrorPart('foo')).includes('MiddleErrorPart: foo'));
1436+
1437+
classMapClassextendsMap{}
1438+
assert.strictEqual(util.inspect(newMapClass([['key','value']])),
1439+
"MapClass(1) { 'key' => 'value' }");
1440+
1441+
classAbcMapextendsMap{}
1442+
assert.strictEqual(util.inspect(newAbcMap([['key','value']])),
1443+
"AbcMap(1) { 'key' => 'value' }");
1444+
1445+
classSetAbcextendsSet{}
1446+
assert.strictEqual(util.inspect(newSetAbc([1,2,3])),
1447+
'SetAbc(3) { 1, 2, 3 }');
1448+
1449+
classFooSetextendsSet{}
1450+
assert.strictEqual(util.inspect(newFooSet([1,2,3])),
1451+
'FooSet(3) { 1, 2, 3 }');
1452+
1453+
classSettingsextendsSet{}
1454+
assert.strictEqual(util.inspect(newSettings([1,2,3])),
1455+
'Settings(3) [Set] { 1, 2, 3 }');
14331456
}
14341457

14351458
// Empty and circular before depth.

0 commit comments

Comments
 (0)