Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/jsutils/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ function formatValue(value: mixed, seenValues: Array<mixed>): string {
case 'function':
return value.name ? `[function ${value.name}]` : '[function]';
case 'object':
if (value === null) {
return 'null';
}
return formatObjectValue(value, seenValues);
default:
return String(value);
Expand All @@ -30,14 +27,18 @@ function formatObjectValue(
value: Object,
previouslySeenValues: Array<mixed>,
): string {
if (value === null) {
return 'null';
}

if (previouslySeenValues.indexOf(value) !== -1) {
return '[Circular]';
}

const seenValues = [...previouslySeenValues, value];

if (typeof value.toJSON === 'function') {
const jsonValue = value.toJSON(value);
const jsonValue = (value.toJSON: () => mixed)();

// check for infinite recursion
if (jsonValue !== value) {
Expand Down