pretty-format
Advanced tools
Comparing version 29.1.2 to 29.2.0
@@ -10,3 +10,2 @@ 'use strict'; | ||
exports.printObjectProperties = printObjectProperties; | ||
/** | ||
@@ -19,6 +18,6 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const getKeysOfEnumerableProperties = (object, compareKeys) => { | ||
const rawKeys = Object.keys(object); | ||
const keys = compareKeys !== null ? rawKeys.sort(compareKeys) : rawKeys; | ||
if (Object.getOwnPropertySymbols) { | ||
@@ -31,5 +30,5 @@ Object.getOwnPropertySymbols(object).forEach(symbol => { | ||
} | ||
return keys; | ||
}; | ||
/** | ||
@@ -40,3 +39,2 @@ * Return entries (for example, of a map) | ||
*/ | ||
function printIteratorEntries( | ||
@@ -48,3 +46,4 @@ iterator, | ||
refs, | ||
printer, // Too bad, so sad that separator for ECMAScript Map has been ' => ' | ||
printer, | ||
// Too bad, so sad that separator for ECMAScript Map has been ' => ' | ||
// What a distracting diff if you change a data structure to/from | ||
@@ -57,10 +56,7 @@ // ECMAScript Object or Immutable.Map/OrderedMap which use the default. | ||
let current = iterator.next(); | ||
if (!current.done) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
while (!current.done) { | ||
result += indentationNext; | ||
if (width++ === config.maxWidth) { | ||
@@ -70,3 +66,2 @@ result += '…'; | ||
} | ||
const name = printer( | ||
@@ -88,3 +83,2 @@ current.value[0], | ||
current = iterator.next(); | ||
if (!current.done) { | ||
@@ -96,8 +90,7 @@ result += `,${config.spacingInner}`; | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
/** | ||
@@ -108,3 +101,2 @@ * Return values (for example, of a set) | ||
*/ | ||
function printIteratorValues( | ||
@@ -121,10 +113,7 @@ iterator, | ||
let current = iterator.next(); | ||
if (!current.done) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
while (!current.done) { | ||
result += indentationNext; | ||
if (width++ === config.maxWidth) { | ||
@@ -134,6 +123,4 @@ result += '…'; | ||
} | ||
result += printer(current.value, config, indentationNext, depth, refs); | ||
current = iterator.next(); | ||
if (!current.done) { | ||
@@ -145,8 +132,7 @@ result += `,${config.spacingInner}`; | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
/** | ||
@@ -157,13 +143,9 @@ * Return items (for example, of an array) | ||
**/ | ||
function printListItems(list, config, indentation, depth, refs, printer) { | ||
let result = ''; | ||
if (list.length) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
for (let i = 0; i < list.length; i++) { | ||
result += indentationNext; | ||
if (i === config.maxWidth) { | ||
@@ -173,7 +155,5 @@ result += '…'; | ||
} | ||
if (i in list) { | ||
result += printer(list[i], config, indentationNext, depth, refs); | ||
} | ||
if (i < list.length - 1) { | ||
@@ -185,8 +165,7 @@ result += `,${config.spacingInner}`; | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
/** | ||
@@ -197,11 +176,8 @@ * Return properties of an object | ||
*/ | ||
function printObjectProperties(val, config, indentation, depth, refs, printer) { | ||
let result = ''; | ||
const keys = getKeysOfEnumerableProperties(val, config.compareKeys); | ||
if (keys.length) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
for (let i = 0; i < keys.length; i++) { | ||
@@ -212,3 +188,2 @@ const key = keys[i]; | ||
result += `${indentationNext + name}: ${value}`; | ||
if (i < keys.length - 1) { | ||
@@ -220,7 +195,5 @@ result += `,${config.spacingInner}`; | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} |
@@ -9,27 +9,17 @@ 'use strict'; | ||
exports.plugins = void 0; | ||
var _ansiStyles = _interopRequireDefault(require('ansi-styles')); | ||
var _collections = require('./collections'); | ||
var _AsymmetricMatcher = _interopRequireDefault( | ||
require('./plugins/AsymmetricMatcher') | ||
); | ||
var _DOMCollection = _interopRequireDefault(require('./plugins/DOMCollection')); | ||
var _DOMElement = _interopRequireDefault(require('./plugins/DOMElement')); | ||
var _Immutable = _interopRequireDefault(require('./plugins/Immutable')); | ||
var _ReactElement = _interopRequireDefault(require('./plugins/ReactElement')); | ||
var _ReactTestComponent = _interopRequireDefault( | ||
require('./plugins/ReactTestComponent') | ||
); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -43,2 +33,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
/* eslint-disable local/ban-types-eventually */ | ||
const toString = Object.prototype.toString; | ||
@@ -48,2 +39,3 @@ const toISOString = Date.prototype.toISOString; | ||
const regExpToString = RegExp.prototype.toString; | ||
/** | ||
@@ -53,14 +45,10 @@ * Explicitly comparing typeof constructor to function avoids undefined as name | ||
*/ | ||
const getConstructorName = val => | ||
(typeof val.constructor === 'function' && val.constructor.name) || 'Object'; | ||
/* global window */ | ||
/** Is val is equal to global window object? Works even if it does not exist :) */ | ||
const isWindow = val => typeof window !== 'undefined' && val === window; | ||
const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; | ||
const NEWLINE_REGEXP = /\n/gi; | ||
class PrettyFormatPluginError extends Error { | ||
@@ -73,3 +61,2 @@ constructor(message, stack) { | ||
} | ||
function isToStringedArrayType(toStringed) { | ||
@@ -91,11 +78,8 @@ return ( | ||
} | ||
function printNumber(val) { | ||
return Object.is(val, -0) ? '-0' : String(val); | ||
} | ||
function printBigInt(val) { | ||
return String(`${val}n`); | ||
} | ||
function printFunction(val, printFunctionName) { | ||
@@ -105,13 +89,11 @@ if (!printFunctionName) { | ||
} | ||
return `[Function ${val.name || 'anonymous'}]`; | ||
} | ||
function printSymbol(val) { | ||
return String(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); | ||
} | ||
function printError(val) { | ||
return `[${errorToString.call(val)}]`; | ||
} | ||
/** | ||
@@ -121,3 +103,2 @@ * The first port of call for printing an object, handles most of the | ||
*/ | ||
function printBasicValue(val, printFunctionName, escapeRegex, escapeString) { | ||
@@ -127,21 +108,15 @@ if (val === true || val === false) { | ||
} | ||
if (val === undefined) { | ||
return 'undefined'; | ||
} | ||
if (val === null) { | ||
return 'null'; | ||
} | ||
const typeOf = typeof val; | ||
if (typeOf === 'number') { | ||
return printNumber(val); | ||
} | ||
if (typeOf === 'bigint') { | ||
return printBigInt(val); | ||
} | ||
if (typeOf === 'string') { | ||
@@ -151,24 +126,17 @@ if (escapeString) { | ||
} | ||
return `"${val}"`; | ||
} | ||
if (typeOf === 'function') { | ||
return printFunction(val, printFunctionName); | ||
} | ||
if (typeOf === 'symbol') { | ||
return printSymbol(val); | ||
} | ||
const toStringed = toString.call(val); | ||
if (toStringed === '[object WeakMap]') { | ||
return 'WeakMap {}'; | ||
} | ||
if (toStringed === '[object WeakSet]') { | ||
return 'WeakSet {}'; | ||
} | ||
if ( | ||
@@ -180,15 +148,11 @@ toStringed === '[object Function]' || | ||
} | ||
if (toStringed === '[object Symbol]') { | ||
return printSymbol(val); | ||
} | ||
if (toStringed === '[object Date]') { | ||
return isNaN(+val) ? 'Date { NaN }' : toISOString.call(val); | ||
} | ||
if (toStringed === '[object Error]') { | ||
return printError(val); | ||
} | ||
if (toStringed === '[object RegExp]') { | ||
@@ -199,12 +163,10 @@ if (escapeRegex) { | ||
} | ||
return regExpToString.call(val); | ||
} | ||
if (val instanceof Error) { | ||
return printError(val); | ||
} | ||
return null; | ||
} | ||
/** | ||
@@ -214,3 +176,2 @@ * Handles more complex objects ( such as objects with circular references. | ||
*/ | ||
function printComplexValue( | ||
@@ -227,3 +188,2 @@ val, | ||
} | ||
refs = refs.slice(); | ||
@@ -233,3 +193,2 @@ refs.push(val); | ||
const min = config.min; | ||
if ( | ||
@@ -244,5 +203,3 @@ config.callToJSON && | ||
} | ||
const toStringed = toString.call(val); | ||
if (toStringed === '[object Arguments]') { | ||
@@ -260,3 +217,2 @@ return hitMaxDepth | ||
} | ||
if (isToStringedArrayType(toStringed)) { | ||
@@ -280,3 +236,2 @@ return hitMaxDepth | ||
} | ||
if (toStringed === '[object Map]') { | ||
@@ -295,3 +250,2 @@ return hitMaxDepth | ||
} | ||
if (toStringed === '[object Set]') { | ||
@@ -308,5 +262,6 @@ return hitMaxDepth | ||
)}}`; | ||
} // Avoid failure to serialize global window object in jsdom test environment. | ||
} | ||
// Avoid failure to serialize global window object in jsdom test environment. | ||
// For example, not even relevant if window is prop of React element. | ||
return hitMaxDepth || isWindow(val) | ||
@@ -329,10 +284,7 @@ ? `[${getConstructorName(val)}]` | ||
} | ||
function isNewPlugin(plugin) { | ||
return plugin.serialize != null; | ||
} | ||
function printPlugin(plugin, val, config, indentation, depth, refs) { | ||
let printed; | ||
try { | ||
@@ -361,3 +313,2 @@ printed = isNewPlugin(plugin) | ||
} | ||
if (typeof printed !== 'string') { | ||
@@ -368,6 +319,4 @@ throw new Error( | ||
} | ||
return printed; | ||
} | ||
function findPlugin(plugins, val) { | ||
@@ -383,13 +332,9 @@ for (let p = 0; p < plugins.length; p++) { | ||
} | ||
return null; | ||
} | ||
function printer(val, config, indentation, depth, refs, hasCalledToJSON) { | ||
const plugin = findPlugin(config.plugins, val); | ||
if (plugin !== null) { | ||
return printPlugin(plugin, val, config, indentation, depth, refs); | ||
} | ||
const basicResult = printBasicValue( | ||
@@ -401,7 +346,5 @@ val, | ||
); | ||
if (basicResult !== null) { | ||
return basicResult; | ||
} | ||
return printComplexValue( | ||
@@ -416,3 +359,2 @@ val, | ||
} | ||
const DEFAULT_THEME = { | ||
@@ -425,6 +367,6 @@ comment: 'gray', | ||
}; | ||
const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME); // could be replaced by `satisfies` operator in the future: https://github.com/microsoft/TypeScript/issues/47920 | ||
const DEFAULT_THEME_KEYS = Object.keys(DEFAULT_THEME); | ||
// could be replaced by `satisfies` operator in the future: https://github.com/microsoft/TypeScript/issues/47920 | ||
const toOptionsSubtype = options => options; | ||
const DEFAULT_OPTIONS = toOptionsSubtype({ | ||
@@ -446,3 +388,2 @@ callToJSON: true, | ||
exports.DEFAULT_OPTIONS = DEFAULT_OPTIONS; | ||
function validateOptions(options) { | ||
@@ -454,3 +395,2 @@ Object.keys(options).forEach(key => { | ||
}); | ||
if (options.min && options.indent !== undefined && options.indent !== 0) { | ||
@@ -461,3 +401,2 @@ throw new Error( | ||
} | ||
if (options.theme !== undefined) { | ||
@@ -467,3 +406,2 @@ if (options.theme === null) { | ||
} | ||
if (typeof options.theme !== 'object') { | ||
@@ -476,3 +414,2 @@ throw new Error( | ||
} | ||
const getColorsHighlight = options => | ||
@@ -485,3 +422,2 @@ DEFAULT_THEME_KEYS.reduce((colors, key) => { | ||
const color = value && _ansiStyles.default[value]; | ||
if ( | ||
@@ -498,6 +434,4 @@ color && | ||
} | ||
return colors; | ||
}, Object.create(null)); | ||
const getColorsEmpty = () => | ||
@@ -511,12 +445,8 @@ DEFAULT_THEME_KEYS.reduce((colors, key) => { | ||
}, Object.create(null)); | ||
const getPrintFunctionName = options => | ||
options?.printFunctionName ?? DEFAULT_OPTIONS.printFunctionName; | ||
const getEscapeRegex = options => | ||
options?.escapeRegex ?? DEFAULT_OPTIONS.escapeRegex; | ||
const getEscapeString = options => | ||
options?.escapeString ?? DEFAULT_OPTIONS.escapeString; | ||
const getConfig = options => ({ | ||
@@ -543,6 +473,6 @@ callToJSON: options?.callToJSON ?? DEFAULT_OPTIONS.callToJSON, | ||
}); | ||
function createIndent(indent) { | ||
return new Array(indent + 1).join(' '); | ||
} | ||
/** | ||
@@ -553,10 +483,7 @@ * Returns a presentation string of your `val` object | ||
*/ | ||
function format(val, options) { | ||
if (options) { | ||
validateOptions(options); | ||
if (options.plugins) { | ||
const plugin = findPlugin(options.plugins, val); | ||
if (plugin !== null) { | ||
@@ -567,3 +494,2 @@ return printPlugin(plugin, val, getConfig(options), '', 0, []); | ||
} | ||
const basicResult = printBasicValue( | ||
@@ -575,10 +501,7 @@ val, | ||
); | ||
if (basicResult !== null) { | ||
return basicResult; | ||
} | ||
return printComplexValue(val, getConfig(options), '', 0, []); | ||
} | ||
const plugins = { | ||
@@ -585,0 +508,0 @@ AsymmetricMatcher: _AsymmetricMatcher.default, |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var _collections = require('../collections'); | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -17,6 +15,4 @@ const asymmetricMatcher = | ||
const SPACE = ' '; | ||
const serialize = (val, config, indentation, depth, refs, printer) => { | ||
const stringedValue = val.toString(); | ||
if ( | ||
@@ -29,3 +25,2 @@ stringedValue === 'ArrayContaining' || | ||
} | ||
return `${stringedValue + SPACE}[${(0, _collections.printListItems)( | ||
@@ -40,3 +35,2 @@ val.sample, | ||
} | ||
if ( | ||
@@ -49,3 +43,2 @@ stringedValue === 'ObjectContaining' || | ||
} | ||
return `${stringedValue + SPACE}{${(0, _collections.printObjectProperties)( | ||
@@ -60,3 +53,2 @@ val.sample, | ||
} | ||
if ( | ||
@@ -72,3 +64,2 @@ stringedValue === 'StringMatching' || | ||
} | ||
if ( | ||
@@ -84,3 +75,2 @@ stringedValue === 'StringContaining' || | ||
} | ||
if (typeof val.toAsymmetricMatcher !== 'function') { | ||
@@ -91,10 +81,6 @@ throw new Error( | ||
} | ||
return val.toAsymmetricMatcher(); | ||
}; | ||
exports.serialize = serialize; | ||
const test = val => val && val.$$typeof === asymmetricMatcher; | ||
exports.test = test; | ||
@@ -101,0 +87,0 @@ const plugin = { |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var _collections = require('../collections'); | ||
/** | ||
@@ -17,9 +15,8 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const SPACE = ' '; | ||
const OBJECT_NAMES = ['DOMStringMap', 'NamedNodeMap']; | ||
const ARRAY_REGEXP = /^(HTML\w*Collection|NodeList)$/; | ||
const testName = name => | ||
OBJECT_NAMES.indexOf(name) !== -1 || ARRAY_REGEXP.test(name); | ||
const test = val => | ||
@@ -30,15 +27,10 @@ val && | ||
testName(val.constructor.name); | ||
exports.test = test; | ||
const isNamedNodeMap = collection => | ||
collection.constructor.name === 'NamedNodeMap'; | ||
const serialize = (collection, config, indentation, depth, refs, printer) => { | ||
const name = collection.constructor.name; | ||
if (++depth > config.maxDepth) { | ||
return `[${name}]`; | ||
} | ||
return ( | ||
@@ -53,3 +45,5 @@ (config.min ? '' : name + SPACE) + | ||
}, {}) | ||
: {...collection}, | ||
: { | ||
...collection | ||
}, | ||
config, | ||
@@ -71,3 +65,2 @@ indentation, | ||
}; | ||
exports.serialize = serialize; | ||
@@ -74,0 +67,0 @@ const plugin = { |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var _markup = require('./lib/markup'); | ||
/** | ||
@@ -17,2 +15,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
const ELEMENT_NODE = 1; | ||
@@ -23,3 +22,2 @@ const TEXT_NODE = 3; | ||
const ELEMENT_REGEXP = /^((HTML|SVG)\w*)?Element$/; | ||
const testHasAttribute = val => { | ||
@@ -32,3 +30,2 @@ try { | ||
}; | ||
const testNode = val => { | ||
@@ -48,19 +45,13 @@ const constructorName = val.constructor.name; | ||
}; | ||
const test = val => val?.constructor?.name && testNode(val); | ||
exports.test = test; | ||
function nodeIsText(node) { | ||
return node.nodeType === TEXT_NODE; | ||
} | ||
function nodeIsComment(node) { | ||
return node.nodeType === COMMENT_NODE; | ||
} | ||
function nodeIsFragment(node) { | ||
return node.nodeType === FRAGMENT_NODE; | ||
} | ||
const serialize = (node, config, indentation, depth, refs, printer) => { | ||
@@ -70,15 +61,11 @@ if (nodeIsText(node)) { | ||
} | ||
if (nodeIsComment(node)) { | ||
return (0, _markup.printComment)(node.data, config); | ||
} | ||
const type = nodeIsFragment(node) | ||
? 'DocumentFragment' | ||
: node.tagName.toLowerCase(); | ||
if (++depth > config.maxDepth) { | ||
return (0, _markup.printElementAsLeaf)(type, config); | ||
} | ||
return (0, _markup.printElement)( | ||
@@ -116,3 +103,2 @@ type, | ||
}; | ||
exports.serialize = serialize; | ||
@@ -119,0 +105,0 @@ const plugin = { |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var _collections = require('../collections'); | ||
/** | ||
@@ -17,2 +15,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// SENTINEL constants are from https://github.com/facebook/immutable-js | ||
@@ -25,11 +24,7 @@ const IS_ITERABLE_SENTINEL = '@@__IMMUTABLE_ITERABLE__@@'; | ||
const IS_RECORD_SENTINEL = '@@__IMMUTABLE_RECORD__@@'; // immutable v4 | ||
const IS_SEQ_SENTINEL = '@@__IMMUTABLE_SEQ__@@'; | ||
const IS_SET_SENTINEL = '@@__IMMUTABLE_SET__@@'; | ||
const IS_STACK_SENTINEL = '@@__IMMUTABLE_STACK__@@'; | ||
const getImmutableName = name => `Immutable.${name}`; | ||
const printAsLeaf = name => `[${name}]`; | ||
const SPACE = ' '; | ||
@@ -57,5 +52,6 @@ const LAZY = '…'; // Seq is lazy if it calls a method like filter | ||
printer | ||
)}}`; // Record has an entries method because it is a collection in immutable v3. | ||
)}}`; | ||
// Record has an entries method because it is a collection in immutable v3. | ||
// Return an iterator for Immutable Record from version v3 or v4. | ||
function getRecordEntries(val) { | ||
@@ -72,3 +68,2 @@ let i = 0; | ||
} | ||
return { | ||
@@ -81,3 +76,2 @@ done: true, | ||
} | ||
const printImmutableRecord = ( | ||
@@ -105,10 +99,7 @@ val, | ||
}; | ||
const printImmutableSeq = (val, config, indentation, depth, refs, printer) => { | ||
const name = getImmutableName('Seq'); | ||
if (++depth > config.maxDepth) { | ||
return printAsLeaf(name); | ||
} | ||
if (val[IS_KEYED_SENTINEL]) { | ||
@@ -129,7 +120,9 @@ return `${name + SPACE}{${ | ||
} | ||
return `${name + SPACE}[${ | ||
val._iter || // from Immutable collection of values | ||
val._array || // from ECMAScript array | ||
val._collection || // from ECMAScript collection in immutable v4 | ||
val._iter || | ||
// from Immutable collection of values | ||
val._array || | ||
// from ECMAScript array | ||
val._collection || | ||
// from ECMAScript collection in immutable v4 | ||
val._iterable // from ECMAScript collection in immutable v3 | ||
@@ -147,3 +140,2 @@ ? (0, _collections.printIteratorValues)( | ||
}; | ||
const printImmutableValues = ( | ||
@@ -169,3 +161,2 @@ val, | ||
)}]`; | ||
const serialize = (val, config, indentation, depth, refs, printer) => { | ||
@@ -183,3 +174,2 @@ if (val[IS_MAP_SENTINEL]) { | ||
} | ||
if (val[IS_LIST_SENTINEL]) { | ||
@@ -196,3 +186,2 @@ return printImmutableValues( | ||
} | ||
if (val[IS_SET_SENTINEL]) { | ||
@@ -209,3 +198,2 @@ return printImmutableValues( | ||
} | ||
if (val[IS_STACK_SENTINEL]) { | ||
@@ -222,17 +210,16 @@ return printImmutableValues( | ||
} | ||
if (val[IS_SEQ_SENTINEL]) { | ||
return printImmutableSeq(val, config, indentation, depth, refs, printer); | ||
} // For compatibility with immutable v3 and v4, let record be the default. | ||
} | ||
// For compatibility with immutable v3 and v4, let record be the default. | ||
return printImmutableRecord(val, config, indentation, depth, refs, printer); | ||
}; // Explicitly comparing sentinel properties to true avoids false positive | ||
}; | ||
// Explicitly comparing sentinel properties to true avoids false positive | ||
// when mock identity-obj-proxy returns the key as the value for any key. | ||
exports.serialize = serialize; | ||
const test = val => | ||
val && | ||
(val[IS_ITERABLE_SENTINEL] === true || val[IS_RECORD_SENTINEL] === true); | ||
exports.test = test; | ||
@@ -239,0 +226,0 @@ const plugin = { |
@@ -7,3 +7,2 @@ 'use strict'; | ||
exports.default = escapeHTML; | ||
/** | ||
@@ -15,4 +14,5 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
function escapeHTML(str) { | ||
return str.replace(/</g, '<').replace(/>/g, '>'); | ||
} |
@@ -13,9 +13,6 @@ 'use strict'; | ||
void 0; | ||
var _escapeHTML = _interopRequireDefault(require('./escapeHTML')); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj}; | ||
} | ||
/** | ||
@@ -27,2 +24,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// Return empty string if keys is empty. | ||
@@ -36,3 +34,2 @@ const printProps = (keys, props, config, indentation, depth, refs, printer) => { | ||
let printed = printer(value, config, indentationNext, depth, refs); | ||
if (typeof value !== 'string') { | ||
@@ -47,6 +44,4 @@ if (printed.indexOf('\n') !== -1) { | ||
} | ||
printed = `{${printed}}`; | ||
} | ||
return `${ | ||
@@ -61,6 +56,6 @@ config.spacingInner + | ||
.join(''); | ||
}; // Return empty string if children is empty. | ||
}; | ||
// Return empty string if children is empty. | ||
exports.printProps = printProps; | ||
const printChildren = (children, config, indentation, depth, refs, printer) => | ||
@@ -77,5 +72,3 @@ children | ||
.join(''); | ||
exports.printChildren = printChildren; | ||
const printText = (text, config) => { | ||
@@ -87,5 +80,3 @@ const contentColor = config.colors.content; | ||
}; | ||
exports.printText = printText; | ||
const printComment = (comment, config) => { | ||
@@ -96,9 +87,9 @@ const commentColor = config.colors.comment; | ||
}`; | ||
}; // Separate the functions to format props, children, and element, | ||
}; | ||
// Separate the functions to format props, children, and element, | ||
// so a plugin could override a particular function, if needed. | ||
// Too bad, so sad: the traditional (but unnecessary) space | ||
// in a self-closing tagColor requires a second test of printedProps. | ||
exports.printComment = printComment; | ||
const printElement = ( | ||
@@ -125,5 +116,3 @@ type, | ||
}; | ||
exports.printElement = printElement; | ||
const printElementAsLeaf = (type, config) => { | ||
@@ -133,3 +122,2 @@ const tagColor = config.colors.tag; | ||
}; | ||
exports.printElementAsLeaf = printElementAsLeaf; |
@@ -7,7 +7,4 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var ReactIs = _interopRequireWildcard(require('react-is')); | ||
var _markup = require('./lib/markup'); | ||
function _getRequireWildcardCache(nodeInterop) { | ||
@@ -21,3 +18,2 @@ if (typeof WeakMap !== 'function') return null; | ||
} | ||
function _interopRequireWildcard(obj, nodeInterop) { | ||
@@ -55,3 +51,2 @@ if (!nodeInterop && obj && obj.__esModule) { | ||
} | ||
/** | ||
@@ -63,2 +58,3 @@ * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
*/ | ||
// Given element.props.children, or subtree during recursive traversal, | ||
@@ -74,25 +70,18 @@ // return flattened array of children. | ||
} | ||
return children; | ||
}; | ||
const getType = element => { | ||
const type = element.type; | ||
if (typeof type === 'string') { | ||
return type; | ||
} | ||
if (typeof type === 'function') { | ||
return type.displayName || type.name || 'Unknown'; | ||
} | ||
if (ReactIs.isFragment(element)) { | ||
return 'React.Fragment'; | ||
} | ||
if (ReactIs.isSuspense(element)) { | ||
return 'React.Suspense'; | ||
} | ||
if (typeof type === 'object' && type !== null) { | ||
@@ -102,7 +91,5 @@ if (ReactIs.isContextProvider(element)) { | ||
} | ||
if (ReactIs.isContextConsumer(element)) { | ||
return 'Context.Consumer'; | ||
} | ||
if (ReactIs.isForwardRef(element)) { | ||
@@ -112,7 +99,5 @@ if (type.displayName) { | ||
} | ||
const functionName = type.render.displayName || type.render.name || ''; | ||
return functionName !== '' ? `ForwardRef(${functionName})` : 'ForwardRef'; | ||
} | ||
if (ReactIs.isMemo(element)) { | ||
@@ -124,6 +109,4 @@ const functionName = | ||
} | ||
return 'UNDEFINED'; | ||
}; | ||
const getPropKeys = element => { | ||
@@ -135,3 +118,2 @@ const {props} = element; | ||
}; | ||
const serialize = (element, config, indentation, depth, refs, printer) => | ||
@@ -162,7 +144,4 @@ ++depth > config.maxDepth | ||
); | ||
exports.serialize = serialize; | ||
const test = val => val != null && ReactIs.isElement(val); | ||
exports.test = test; | ||
@@ -169,0 +148,0 @@ const plugin = { |
@@ -7,5 +7,3 @@ 'use strict'; | ||
exports.test = exports.serialize = exports.default = void 0; | ||
var _markup = require('./lib/markup'); | ||
var Symbol = globalThis['jest-symbol-do-not-touch'] || globalThis.Symbol; | ||
@@ -16,3 +14,2 @@ const testSymbol = | ||
: 0xea71357; | ||
const getPropKeys = object => { | ||
@@ -26,3 +23,2 @@ const {props} = object; | ||
}; | ||
const serialize = (object, config, indentation, depth, refs, printer) => | ||
@@ -57,7 +53,4 @@ ++depth > config.maxDepth | ||
); | ||
exports.serialize = serialize; | ||
const test = val => val && val.$$typeof === testSymbol; | ||
exports.test = test; | ||
@@ -64,0 +57,0 @@ const plugin = { |
{ | ||
"name": "pretty-format", | ||
"version": "29.1.2", | ||
"version": "29.2.0", | ||
"repository": { | ||
@@ -31,3 +31,3 @@ "type": "git", | ||
"immutable": "^4.0.0", | ||
"jest-util": "^29.1.2", | ||
"jest-util": "^29.2.0", | ||
"react": "17.0.2", | ||
@@ -43,3 +43,3 @@ "react-dom": "^17.0.1", | ||
}, | ||
"gitHead": "3c31dd619e8c022cde53f40fa12ea2a67f4752ce" | ||
"gitHead": "ee5b37a4f4433afcfffb0356cea47739d8092287" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1566
60414