Skip to content

Commit 0a12716

Browse files
authored
Merge pull request #99 from jsr-core/symbol-properties/inspect
feat[inspect]: inspects record with symbol properties
2 parents 8c2d915 + 02a38bc commit 0a12716

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

__snapshots__/_inspect_test.ts.snap

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ snapshot[`inspect > record 3`] = `
3030

3131
snapshot[`inspect > record 4`] = `"{a: {b: {c: 0}}}"`;
3232

33+
snapshot[`inspect > record 5`] = `"{Symbol(a): 0}"`;
34+
35+
snapshot[`inspect > record 6`] = `
36+
"{
37+
a: 0,
38+
c: true,
39+
Symbol(b): 1
40+
}"
41+
`;
42+
43+
snapshot[`inspect > record 7`] = `
44+
"{
45+
Symbol(a): {
46+
Symbol(b): {Symbol(c): 0}
47+
}
48+
}"
49+
`;
50+
3351
snapshot[`inspect > function 1`] = `"inspect"`;
3452

3553
snapshot[`inspect > function 2`] = `"(anonymous)"`;

_inspect.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ function inspectRecord(
4444
options: InspectOptions,
4545
): string {
4646
const { threshold = defaultThreshold } = options;
47-
const vs = Object.entries(value).map(([k, v]) =>
48-
`${k}: ${inspect(v, options)}`
49-
);
47+
const vs = [...Object.keys(value), ...Object.getOwnPropertySymbols(value)]
48+
.map((k) => `${k.toString()}: ${inspect(value[k], options)}`);
5049
const s = vs.join(", ");
5150
if (s.length <= threshold) return `{${s}}`;
5251
const m = vs.join(",\n");

_inspect_test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Deno.test("inspect", async (t) => {
2525
await assertSnapshot(t, inspect({ a: 0, b: 1, c: 2 }));
2626
await assertSnapshot(t, inspect({ a: "a", b: 1, c: true }));
2727
await assertSnapshot(t, inspect({ a: { b: { c: 0 } } }));
28+
await assertSnapshot(t, inspect({ [Symbol("a")]: 0 }));
29+
await assertSnapshot(t, inspect({ a: 0, [Symbol("b")]: 1, c: true }));
30+
await assertSnapshot(
31+
t,
32+
inspect({ [Symbol("a")]: { [Symbol("b")]: { [Symbol("c")]: 0 } } }),
33+
);
2834
});
2935
await t.step("function", async (t) => {
3036
await assertSnapshot(t, inspect(inspect));

0 commit comments

Comments
 (0)