Skip to content

Commit

Permalink
inspect: Handle 'null' explicitly (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov authored Jun 12, 2019
1 parent 462ce07 commit b31099e
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/jsutils/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function formatValue(value, seenValues) {
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 @@ -29,29 +32,25 @@ function formatObjectValue(value, previouslySeenValues) {
if (previouslySeenValues.indexOf(value) !== -1) {
return '[Circular]';
}
const seenValues = [...previouslySeenValues, value];

if (value) {
const customInspectFn = getCustomFn(value);
const seenValues = [...previouslySeenValues, value];
const customInspectFn = getCustomFn(value);

if (customInspectFn !== undefined) {
// $FlowFixMe(>=0.90.0)
const customValue = customInspectFn.call(value);
if (customInspectFn !== undefined) {
// $FlowFixMe(>=0.90.0)
const customValue = customInspectFn.call(value);

// check for infinite recursion
if (customValue !== value) {
return typeof customValue === 'string'
? customValue
: formatValue(customValue, seenValues);
}
} else if (Array.isArray(value)) {
return formatArray(value, seenValues);
// check for infinite recursion
if (customValue !== value) {
return typeof customValue === 'string'
? customValue
: formatValue(customValue, seenValues);
}

return formatObject(value, seenValues);
} else if (Array.isArray(value)) {
return formatArray(value, seenValues);
}

return String(value);
return formatObject(value, seenValues);
}

function formatObject(object, seenValues) {
Expand Down

0 comments on commit b31099e

Please sign in to comment.