Skip to content

Commit e577618

Browse files
ljharbnodejs-github-bot
authored andcommitted
util: inspect: enumerable Symbols no longer have square brackets
Implements https://github.com/orgs/nodejs/discussions/41283#discussioncomment-11188239 PR-URL: #55778 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 23275cc commit e577618

14 files changed

+53
-56
lines changed

doc/api/assert.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 });
878878
// AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:
879879
//
880880
// {
881-
// [Symbol()]: 1
881+
// Symbol(): 1
882882
// }
883883

884884
const weakMap1 = new WeakMap();
@@ -970,7 +970,7 @@ assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 });
970970
// AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:
971971
//
972972
// {
973-
// [Symbol()]: 1
973+
// Symbol(): 1
974974
// }
975975

976976
const weakMap1 = new WeakMap();

doc/api/events.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ myEmitter.on('event', function(a, b) {
7373
// _events: [Object: null prototype] { event: [Function (anonymous)] },
7474
// _eventsCount: 1,
7575
// _maxListeners: undefined,
76-
// [Symbol(shapeMode)]: false,
77-
// [Symbol(kCapture)]: false
76+
// Symbol(shapeMode): false,
77+
// Symbol(kCapture): false
7878
// } true
7979
});
8080
myEmitter.emit('event', 'a', 'b');
@@ -91,8 +91,8 @@ myEmitter.on('event', function(a, b) {
9191
// _events: [Object: null prototype] { event: [Function (anonymous)] },
9292
// _eventsCount: 1,
9393
// _maxListeners: undefined,
94-
// [Symbol(shapeMode)]: false,
95-
// [Symbol(kCapture)]: false
94+
// Symbol(shapeMode): false,
95+
// Symbol(kCapture): false
9696
// } true
9797
});
9898
myEmitter.emit('event', 'a', 'b');

lib/internal/util/inspect.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,21 +1999,16 @@ function formatProperty(ctx, value, recurseTimes, key, type, desc,
19991999
SymbolPrototypeToString(key),
20002000
escapeFn,
20012001
);
2002-
name = `[${ctx.stylize(tmp, 'symbol')}]`;
2003-
} else if (key === '__proto__') {
2004-
name = "['__proto__']";
2005-
} else if (desc.enumerable === false) {
2006-
const tmp = RegExpPrototypeSymbolReplace(
2007-
strEscapeSequencesReplacer,
2008-
key,
2009-
escapeFn,
2010-
);
2011-
name = `[${tmp}]`;
2002+
name = ctx.stylize(tmp, 'symbol');
20122003
} else if (RegExpPrototypeExec(keyStrRegExp, key) !== null) {
2013-
name = ctx.stylize(key, 'name');
2004+
name = key === '__proto__' ? "['__proto__']" : ctx.stylize(key, 'name');
20142005
} else {
20152006
name = ctx.stylize(strEscape(key), 'string');
20162007
}
2008+
2009+
if (desc.enumerable === false) {
2010+
name = `[${name}]`;
2011+
}
20172012
return `${name}:${extra}${str}`;
20182013
}
20192014

test/fixtures/test-runner/output/describe_it.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ not ok 50 - custom inspect symbol that throws fail
454454
error: |-
455455
{
456456
foo: 1,
457-
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
457+
Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]
458458
}
459459
code: 'ERR_TEST_FAILURE'
460460
...

test/fixtures/test-runner/output/dot_reporter.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Failed tests:
137137
✖ custom inspect symbol fail (*ms)
138138
customized
139139
✖ custom inspect symbol that throws fail (*ms)
140-
{ foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
140+
{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]] }
141141
✖ sync throw fails at first (*ms)
142142
Error: thrown from subtest sync throw fails at first
143143
*

test/fixtures/test-runner/output/junit_reporter.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,15 +319,15 @@ Error [ERR_TEST_FAILURE]: thrown from callback async throw
319319
[Error [ERR_TEST_FAILURE]: customized] { code: 'ERR_TEST_FAILURE', failureType: 'testCodeFailure', cause: customized }
320320
</failure>
321321
</testcase>
322-
<testcase name="custom inspect symbol that throws fail" time="*" classname="test" failure="{ foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]}">
323-
<failure type="testCodeFailure" message="{ foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]}">
322+
<testcase name="custom inspect symbol that throws fail" time="*" classname="test" failure="{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]}">
323+
<failure type="testCodeFailure" message="{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]}">
324324
[Error [ERR_TEST_FAILURE]: {
325325
foo: 1,
326-
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
326+
Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]
327327
}] {
328328
code: 'ERR_TEST_FAILURE',
329329
failureType: 'testCodeFailure',
330-
cause: { foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
330+
cause: { foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]] }
331331
}
332332
</failure>
333333
</testcase>

test/fixtures/test-runner/output/output.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ not ok 51 - custom inspect symbol that throws fail
502502
error: |-
503503
{
504504
foo: 1,
505-
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
505+
Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]
506506
}
507507
code: 'ERR_TEST_FAILURE'
508508
...

test/fixtures/test-runner/output/output_cli.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ not ok 51 - custom inspect symbol that throws fail
509509
error: |-
510510
{
511511
foo: 1,
512-
[Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]]
512+
Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]]
513513
}
514514
code: 'ERR_TEST_FAILURE'
515515
...

test/fixtures/test-runner/output/spec_reporter.snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@
194194
customized
195195

196196
custom inspect symbol that throws fail (*ms)
197-
{ foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
197+
{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]] }
198198

199199
subtest sync throw fails
200200
sync throw fails at first (*ms)
@@ -476,7 +476,7 @@
476476

477477
*
478478
custom inspect symbol that throws fail (*ms)
479-
{ foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
479+
{ foo: 1, Symbol(nodejs.util.inspect.custom): [Function: [nodejs.util.inspect.custom]] }
480480

481481
*
482482
sync throw fails at first (*ms)

test/parallel/test-assert.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ test('Test strict assert', () => {
801801
'\n' +
802802
'+ {}\n' +
803803
'- {\n' +
804-
'- [Symbol(nodejs.util.inspect.custom)]: [Function (anonymous)],\n' +
804+
'- Symbol(nodejs.util.inspect.custom): [Function (anonymous)],\n' +
805805
"- loop: 'forever'\n" +
806806
'- }\n'
807807
});

0 commit comments

Comments
 (0)