Skip to content

Commit

Permalink
fixup! harness/deepEqual.js: Render symbol-keyed object properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Oct 16, 2024
1 parent b2a428f commit 5c93647
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion harness/deepEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ function stringFromTemplate(strings, ...subs) {
let parts = strings.map((str, i) => `${i === 0 ? '' : subs[i - 1]}${str}`);
return parts.join('');
}
function escapeKey(key) {
if (typeof key === 'symbol') return `[${String(key)}]`;
if (/^[a-zA-Z0-9_$]+$/.test(key)) return key;
return assert._formatIdentityFreeValue(key);
}

assert.deepEqual.format = function(value, seen) {
let basic = assert._formatIdentityFreeValue(value);
Expand Down Expand Up @@ -123,7 +128,7 @@ assert.deepEqual.format = function(value, seen) {
? value[Symbol.toStringTag]
: Object.getPrototypeOf(value) === null ? '[Object: null prototype]' : 'Object';
let keys = Reflect.ownKeys(value).filter(key => getOwnPropertyDescriptor(value, key).enumerable);
let contents = keys.map(key => lazyString`${String(key)}: ${format(value[key], seen)}`);
let contents = keys.map(key => lazyString`${escapeKey(key)}: ${format(value[key], seen)}`);
return lazyResult`${tag ? `${tag} ` : ''}{${contents}}`(String, join);
};

Expand Down

0 comments on commit 5c93647

Please sign in to comment.