-
Currently, in node v17.3: let e = new Error('a', { cause: 'b' });
e.stack = '';
e.enumerable = true;
e[Symbol('enumerable')] = true;
assert(Object.prototype.propertyIsEnumerable.call(e, Symbol.iterator));
// symbols can be enumerable too; it affects Object.assign and object spread semantics
Object.defineProperty(e, Symbol('non-enumerable'), { enumerable: false, value: true });
assert.equal(util.inspect(e), `[Error: a] {
enumerable: true,
[Symbol(enumerable)]: true
[cause]: 'b'
}`); The brackets on "cause" are apparently to denote that it's non-enumerable - but there's also brackets on the enumerable symbol, and the non-enumerable symbol is omitted entirely. Should perhaps non-enumerability be indicated with something that doesn't have an existing meaning? cc @nodejs/util |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
If you like to change that, I think best would be a concrete suggestion. Non-enumerable and enumerable properties are currently distinguished with colors: We currently use all kinds of brackets ( Non-enumerable properties are not visible by default using |
Beta Was this translation helpful? Give feedback.
-
Thinking about it: we could remove the brackets around symbols. They would still be distinguishable from regular properties due to their round brackets without quotes. |
Beta Was this translation helpful? Give feedback.
We discussed this at the Collab Summit this week, and due to the following considerations:
__proto__
property,Symbol.toStringTag
values, null objects, etc, so we already wouldn't be able to have square brackets mean only "computed properties"Therefore, let's go with "enumerable Symbols do not have square brackets", so that all non-enumerables use square brackets. (there's also another inconsistency discovered during this investigation where bracketed string keys aren't escaped the same way as unbracketed ones are, so i'll fix that as well in the same PR)