pretty-format
Advanced tools
Comparing version 20.1.0-delta.5 to 20.1.0-echo.1
@@ -25,24 +25,25 @@ 'use strict'; | ||
var _collections = require('./collections'); | ||
var _asymmetric_matcher = require('./plugins/asymmetric_matcher');var _asymmetric_matcher2 = _interopRequireDefault(_asymmetric_matcher); | ||
var _convert_ansi = require('./plugins/convert_ansi');var _convert_ansi2 = _interopRequireDefault(_convert_ansi); | ||
var _html_element = require('./plugins/html_element');var _html_element2 = _interopRequireDefault(_html_element); | ||
var _immutable_plugins = require('./plugins/immutable_plugins');var _immutable_plugins2 = _interopRequireDefault(_immutable_plugins); | ||
var _immutable = require('./plugins/immutable');var _immutable2 = _interopRequireDefault(_immutable); | ||
var _react_element = require('./plugins/react_element');var _react_element2 = _interopRequireDefault(_react_element); | ||
var _react_test_component = require('./plugins/react_test_component');var _react_test_component2 = _interopRequireDefault(_react_test_component);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const toString = Object.prototype.toString;const toISOString = Date.prototype.toISOString;const errorToString = Error.prototype.toString;const regExpToString = RegExp.prototype.toString;const symbolToString = Symbol.prototype.toString;const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; | ||
const NEWLINE_REGEXP = /\n/gi; | ||
var _react_test_component = require('./plugins/react_test_component');var _react_test_component2 = _interopRequireDefault(_react_test_component);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
const getSymbols = Object.getOwnPropertySymbols || (obj => []); | ||
const isSymbol = key => | ||
// $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value | ||
typeof key === 'symbol' || toString.call(key) === '[object Symbol]'; | ||
const toString = Object.prototype.toString; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const toISOString = Date.prototype.toISOString;const errorToString = Error.prototype.toString;const regExpToString = RegExp.prototype.toString;const symbolToString = Symbol.prototype.toString;const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/;const NEWLINE_REGEXP = /\n/gi; | ||
function isToStringedArrayType(toStringed) { | ||
@@ -156,158 +157,2 @@ return ( | ||
function printListItems( | ||
list, | ||
config, | ||
indentation, | ||
depth, | ||
refs) | ||
{ | ||
let result = ''; | ||
if (list.length) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
for (let i = 0; i < list.length; i++) { | ||
result += | ||
indentationNext + print(list[i], config, indentationNext, depth, refs); | ||
if (i < list.length - 1) { | ||
result += ',' + config.spacingInner; | ||
} else if (!config.min) { | ||
result += ','; | ||
} | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
function printMapEntries( | ||
val, | ||
config, | ||
indentation, | ||
depth, | ||
refs) | ||
{ | ||
let result = ''; | ||
const iterator = val.entries(); | ||
let current = iterator.next(); | ||
if (!current.done) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
while (!current.done) { | ||
const name = print( | ||
current.value[0], | ||
config, | ||
indentationNext, | ||
depth, | ||
refs); | ||
const value = print( | ||
current.value[1], | ||
config, | ||
indentationNext, | ||
depth, | ||
refs); | ||
result += indentationNext + name + ' => ' + value; | ||
current = iterator.next(); | ||
if (!current.done) { | ||
result += ',' + config.spacingInner; | ||
} else if (!config.min) { | ||
result += ','; | ||
} | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
function printObjectProperties( | ||
val, | ||
config, | ||
indentation, | ||
depth, | ||
refs) | ||
{ | ||
let result = ''; | ||
let keys = Object.keys(val).sort(); | ||
const symbols = getSymbols(val); | ||
if (symbols.length) { | ||
keys = keys.filter(key => !isSymbol(key)).concat(symbols); | ||
} | ||
if (keys.length) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
const name = print(key, config, indentationNext, depth, refs); | ||
const value = print(val[key], config, indentationNext, depth, refs); | ||
result += indentationNext + name + ': ' + value; | ||
if (i < keys.length - 1) { | ||
result += ',' + config.spacingInner; | ||
} else if (!config.min) { | ||
result += ','; | ||
} | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
function printSetValues( | ||
val, | ||
config, | ||
indentation, | ||
depth, | ||
refs) | ||
{ | ||
let result = ''; | ||
const iterator = val.values(); | ||
let current = iterator.next(); | ||
if (!current.done) { | ||
result += config.spacingOuter; | ||
const indentationNext = indentation + config.indent; | ||
while (!current.done) { | ||
result += | ||
indentationNext + | ||
print(current.value, config, indentationNext, depth, refs); | ||
current = iterator.next(); | ||
if (!current.done) { | ||
result += ',' + config.spacingInner; | ||
} else if (!config.min) { | ||
result += ','; | ||
} | ||
} | ||
result += config.spacingOuter + indentation; | ||
} | ||
return result; | ||
} | ||
function printComplexValue( | ||
@@ -335,3 +180,3 @@ val, | ||
{ | ||
return print(val.toJSON(), config, indentation, depth, refs); | ||
return printer(val.toJSON(), config, indentation, depth, refs); | ||
} | ||
@@ -345,3 +190,3 @@ | ||
'[' + | ||
printListItems(val, config, indentation, depth, refs) + | ||
(0, _collections.printListItems)(val, config, indentation, depth, refs, printer) + | ||
']'; | ||
@@ -354,3 +199,3 @@ } | ||
'[' + | ||
printListItems(val, config, indentation, depth, refs) + | ||
(0, _collections.printListItems)(val, config, indentation, depth, refs, printer) + | ||
']'; | ||
@@ -361,3 +206,13 @@ } | ||
'[Map]' : | ||
'Map {' + printMapEntries(val, config, indentation, depth, refs) + '}'; | ||
'Map {' + | ||
(0, _collections.printIteratorEntries)( | ||
val.entries(), | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer, | ||
' => ') + | ||
'}'; | ||
} | ||
@@ -367,3 +222,12 @@ if (toStringed === '[object Set]') { | ||
'[Set]' : | ||
'Set {' + printSetValues(val, config, indentation, depth, refs) + '}'; | ||
'Set {' + | ||
(0, _collections.printIteratorValues)( | ||
val.values(), | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) + | ||
'}'; | ||
} | ||
@@ -375,3 +239,3 @@ | ||
'{' + | ||
printObjectProperties(val, config, indentation, depth, refs) + | ||
(0, _collections.printObjectProperties)(val, config, indentation, depth, refs, printer) + | ||
'}'; | ||
@@ -388,24 +252,19 @@ } | ||
{ | ||
function boundPrint(val) { | ||
return print(val, config, indentation, depth, refs); | ||
} | ||
function boundIndent(str) { | ||
const printed = plugin.serialize ? | ||
plugin.serialize(val, config, indentation, depth, refs, printer) : | ||
plugin.print( | ||
val, | ||
valChild => printer(valChild, config, indentation, depth, refs), | ||
str => { | ||
const indentationNext = indentation + config.indent; | ||
return ( | ||
indentationNext + str.replace(NEWLINE_REGEXP, '\n' + indentationNext)); | ||
indentationNext + | ||
str.replace(NEWLINE_REGEXP, '\n' + indentationNext)); | ||
} | ||
const opts = { | ||
}, | ||
{ | ||
edgeSpacing: config.spacingOuter, | ||
min: config.min, | ||
spacing: config.spacingInner }; | ||
spacing: config.spacingInner }, | ||
const printed = plugin.print( | ||
val, | ||
boundPrint, | ||
boundIndent, | ||
opts, | ||
config.colors); | ||
@@ -431,3 +290,3 @@ | ||
function print( | ||
function printer( | ||
val, | ||
@@ -604,3 +463,3 @@ config, | ||
HTMLElement: _html_element2.default, | ||
Immutable: _immutable_plugins2.default, | ||
Immutable: _immutable2.default, | ||
ReactElement: _react_element2.default, | ||
@@ -607,0 +466,0 @@ ReactTestComponent: _react_test_component2.default }; |
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true }); | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.serialize = undefined; | ||
@@ -13,20 +13,14 @@ | ||
const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher'); /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const SPACE = ' ';class ArrayContaining extends Array {}class ObjectContaining extends Object {}const print = exports.print = (val, print, | ||
indent, | ||
opts, | ||
colors) => | ||
var _collections = require('../collections'); /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher');const SPACE = ' ';const serialize = exports.serialize = (val, config, indentation, | ||
depth, | ||
refs, | ||
printer) => | ||
{ | ||
@@ -36,21 +30,48 @@ const stringedValue = val.toString(); | ||
if (stringedValue === 'ArrayContaining') { | ||
const array = ArrayContaining.from(val.sample); | ||
return opts.spacing === SPACE ? | ||
stringedValue + SPACE + print(array) : | ||
print(array); | ||
if (++depth > config.maxDepth) { | ||
return '[' + stringedValue + ']'; | ||
} | ||
return ( | ||
stringedValue + | ||
SPACE + | ||
'[' + | ||
(0, _collections.printListItems)(val.sample, config, indentation, depth, refs, printer) + | ||
']'); | ||
} | ||
if (stringedValue === 'ObjectContaining') { | ||
const object = Object.assign(new ObjectContaining(), val.sample); | ||
return opts.spacing === SPACE ? | ||
stringedValue + SPACE + print(object) : | ||
print(object); | ||
if (++depth > config.maxDepth) { | ||
return '[' + stringedValue + ']'; | ||
} | ||
return ( | ||
stringedValue + | ||
SPACE + | ||
'{' + | ||
(0, _collections.printObjectProperties)( | ||
val.sample, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) + | ||
'}'); | ||
} | ||
if (stringedValue === 'StringMatching') { | ||
return stringedValue + SPACE + print(val.sample); | ||
return ( | ||
stringedValue + | ||
SPACE + | ||
printer(val.sample, config, indentation, depth, refs)); | ||
} | ||
if (stringedValue === 'StringContaining') { | ||
return stringedValue + SPACE + print(val.sample); | ||
return ( | ||
stringedValue + | ||
SPACE + | ||
printer(val.sample, config, indentation, depth, refs)); | ||
} | ||
@@ -61,5 +82,4 @@ | ||
const test = exports.test = object => | ||
object && object.$$typeof === asymmetricMatcher;exports.default = | ||
const test = exports.test = val => val && val.$$typeof === asymmetricMatcher;exports.default = | ||
{ print, test }; | ||
{ serialize, test }; |
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.print = exports.test = undefined; | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.serialize = exports.test = undefined; | ||
@@ -13,2 +13,4 @@ | ||
var _escape_html = require('./lib/escape_html');var _escape_html2 = _interopRequireDefault(_escape_html); | ||
var _markup = require('./lib/markup');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} | ||
@@ -20,11 +22,2 @@ | ||
var _escape_html = require('./lib/escape_html');var _escape_html2 = _interopRequireDefault(_escape_html);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/ | ||
@@ -45,61 +38,44 @@ | ||
const HTML_ELEMENT_REGEXP = /(HTML\w*?Element)|Text|Comment/; | ||
const test = exports.test = isHTMLElement; | ||
function isHTMLElement(value) { | ||
return ( | ||
value !== undefined && | ||
value !== null && ( | ||
value.nodeType === 1 || value.nodeType === 3 || value.nodeType === 8) && | ||
value.constructor !== undefined && | ||
value.constructor.name !== undefined && | ||
HTML_ELEMENT_REGEXP.test(value.constructor.name)); | ||
const HTML_ELEMENT_REGEXP = /(HTML\w*?Element)|Text|Comment/; /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const test = exports.test = val => val !== undefined && val !== null && (val.nodeType === 1 || val.nodeType === 3 || val.nodeType === 8) && val.constructor !== undefined && val.constructor.name !== undefined && HTML_ELEMENT_REGEXP.test(val.constructor.name); | ||
} | ||
// Return empty string if children is empty. | ||
function printChildren(children, config, indentation, depth, refs, printer) { | ||
const colors = config.colors; | ||
return children. | ||
map( | ||
node => | ||
typeof node === 'string' ? | ||
colors.content.open + (0, _escape_html2.default)(node) + colors.content.close : | ||
printer(node, config, indentation, depth, refs)). | ||
function printChildren(flatChildren, print, indent, colors, opts) { | ||
return flatChildren. | ||
map(node => { | ||
if (typeof node === 'string') { | ||
return colors.content.open + (0, _escape_html2.default)(node) + colors.content.close; | ||
} else { | ||
return print(node); | ||
} | ||
}). | ||
filter(value => value.trim().length). | ||
join(opts.edgeSpacing); | ||
map(value => config.spacingOuter + indentation + value). | ||
join(''); | ||
} | ||
function printAttributes( | ||
attributes, | ||
print, | ||
indent, | ||
colors, | ||
opts) | ||
{ | ||
return attributes. | ||
sort( | ||
(attributeA, attributeB) => | ||
attributeA.name === attributeB.name ? | ||
0 : | ||
attributeA.name < attributeB.name ? -1 : 1). | ||
const getType = element => element.tagName.toLowerCase(); | ||
map(attribute => { | ||
return ( | ||
opts.spacing + | ||
indent(colors.prop.open + attribute.name + colors.prop.close + '=') + | ||
colors.value.open + | ||
print(attribute.value) + | ||
colors.value.close); | ||
// Convert array of attribute objects to keys array and props object. | ||
const keysMapper = attribute => attribute.name; | ||
const propsReducer = (props, attribute) => { | ||
props[attribute.name] = attribute.value; | ||
return props; | ||
}; | ||
}). | ||
join(''); | ||
} | ||
const print = exports.print = ( | ||
const serialize = exports.serialize = ( | ||
element, | ||
print, | ||
indent, | ||
opts, | ||
colors) => | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) => | ||
{ | ||
@@ -112,3 +88,6 @@ if (element.nodeType === 3) { | ||
join(' '); | ||
} else if (element.nodeType === 8) { | ||
} | ||
const colors = config.colors; | ||
if (element.nodeType === 8) { | ||
return ( | ||
@@ -123,41 +102,30 @@ colors.comment.open + | ||
let result = colors.tag.open + '<'; | ||
const elementName = element.tagName.toLowerCase(); | ||
result += elementName + colors.tag.close; | ||
const hasAttributes = element.attributes && element.attributes.length; | ||
if (hasAttributes) { | ||
const attributes = Array.prototype.slice.call(element.attributes); | ||
result += printAttributes(attributes, print, indent, colors, opts); | ||
if (++depth > config.maxDepth) { | ||
return (0, _markup.printElementAsLeaf)(getType(element), config); | ||
} | ||
const flatChildren = Array.prototype.slice.call(element.childNodes); | ||
if (!flatChildren.length && element.textContent) { | ||
flatChildren.push(element.textContent); | ||
} | ||
return (0, _markup.printElement)( | ||
getType(element), | ||
(0, _markup.printProps)( | ||
Array.prototype.map.call(element.attributes, keysMapper).sort(), | ||
Array.prototype.reduce.call(element.attributes, propsReducer, {}), | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer), | ||
const closeInNewLine = hasAttributes && !opts.min; | ||
if (flatChildren.length) { | ||
const children = printChildren(flatChildren, print, indent, colors, opts); | ||
result += | ||
colors.tag.open + ( | ||
closeInNewLine ? '\n' : '') + | ||
'>' + | ||
colors.tag.close + | ||
opts.edgeSpacing + | ||
indent(children) + | ||
opts.edgeSpacing + | ||
colors.tag.open + | ||
'</' + | ||
elementName + | ||
'>' + | ||
colors.tag.close; | ||
} else { | ||
result += | ||
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close; | ||
} | ||
printChildren( | ||
Array.prototype.slice.call(element.childNodes), | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer), | ||
return result; | ||
config, | ||
indentation); | ||
};exports.default = | ||
{ print, test }; | ||
{ serialize, test }; |
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.print = undefined; | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.serialize = undefined; | ||
@@ -13,122 +13,69 @@ | ||
var _markup = require('./lib/markup'); /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const elementSymbol = Symbol.for('react.element'); | ||
// Given element.props.children, or subtree during recursive traversal, | ||
// return flattened array of children. | ||
const getChildren = function (arg) {let children = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (Array.isArray(arg)) { | ||
arg.forEach(item => { | ||
getChildren(item, children); | ||
}); | ||
} else if (arg != null && arg !== false) { | ||
children.push(arg); | ||
} | ||
return children; | ||
}; | ||
var _escape_html = require('./lib/escape_html');var _escape_html2 = _interopRequireDefault(_escape_html);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const reactElement = Symbol.for('react.element');function traverseChildren(opaqueChildren, cb) {if (Array.isArray(opaqueChildren)) {opaqueChildren.forEach(child => traverseChildren(child, cb));} else if (opaqueChildren != null && opaqueChildren !== false) {cb(opaqueChildren); | ||
const getType = element => { | ||
if (typeof element.type === 'string') { | ||
return element.type; | ||
} | ||
} | ||
if (typeof element.type === 'function') { | ||
return element.type.displayName || element.type.name || 'Unknown'; | ||
} | ||
return 'Unknown'; | ||
}; | ||
function printChildren(flatChildren, print, indent, colors, opts) { | ||
return flatChildren. | ||
map(node => { | ||
if (typeof node === 'string') { | ||
return colors.content.open + (0, _escape_html2.default)(node) + colors.content.close; | ||
} else { | ||
return print(node); | ||
} | ||
}). | ||
join(opts.edgeSpacing); | ||
} | ||
const serialize = exports.serialize = ( | ||
element, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) => | ||
function printProps(props, print, indent, colors, opts) { | ||
return Object.keys(props). | ||
sort(). | ||
map(name => { | ||
if (name === 'children') { | ||
return ''; | ||
} | ||
++depth > config.maxDepth ? | ||
(0, _markup.printElementAsLeaf)(getType(element), config) : | ||
(0, _markup.printElement)( | ||
getType(element), | ||
(0, _markup.printProps)( | ||
Object.keys(element.props).filter(key => key !== 'children').sort(), | ||
element.props, | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer), | ||
const prop = props[name]; | ||
let printed = print(prop); | ||
(0, _markup.printChildren)( | ||
getChildren(element.props.children), | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer), | ||
if (typeof prop !== 'string') { | ||
if (printed.indexOf('\n') !== -1) { | ||
printed = | ||
'{' + | ||
opts.edgeSpacing + | ||
indent(indent(printed) + opts.edgeSpacing + '}'); | ||
} else { | ||
printed = '{' + printed + '}'; | ||
} | ||
} | ||
config, | ||
indentation); | ||
return ( | ||
opts.spacing + | ||
indent(colors.prop.open + name + colors.prop.close + '=') + | ||
colors.value.open + | ||
printed + | ||
colors.value.close); | ||
}). | ||
join(''); | ||
} | ||
const test = exports.test = val => val && val.$$typeof === elementSymbol;exports.default = | ||
const print = exports.print = ( | ||
element, | ||
print, | ||
indent, | ||
opts, | ||
colors) => | ||
{ | ||
let result = colors.tag.open + '<'; | ||
let elementName; | ||
if (typeof element.type === 'string') { | ||
elementName = element.type; | ||
} else if (typeof element.type === 'function') { | ||
elementName = element.type.displayName || element.type.name || 'Unknown'; | ||
} else { | ||
elementName = 'Unknown'; | ||
} | ||
result += elementName + colors.tag.close; | ||
result += printProps(element.props, print, indent, colors, opts); | ||
const opaqueChildren = element.props.children; | ||
const hasProps = !!Object.keys(element.props).filter( | ||
propName => propName !== 'children'). | ||
length; | ||
const closeInNewLine = hasProps && !opts.min; | ||
if (opaqueChildren) { | ||
const flatChildren = []; | ||
traverseChildren(opaqueChildren, child => { | ||
flatChildren.push(child); | ||
}); | ||
const children = printChildren(flatChildren, print, indent, colors, opts); | ||
result += | ||
colors.tag.open + ( | ||
closeInNewLine ? '\n' : '') + | ||
'>' + | ||
colors.tag.close + | ||
opts.edgeSpacing + | ||
indent(children) + | ||
opts.edgeSpacing + | ||
colors.tag.open + | ||
'</' + | ||
elementName + | ||
'>' + | ||
colors.tag.close; | ||
} else { | ||
result += | ||
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close; | ||
} | ||
return result; | ||
}; | ||
// Disabling lint rule as we don't know type ahead of time. | ||
/* eslint-disable flowtype/no-weak-types */ | ||
const test = exports.test = object => object && object.$$typeof === reactElement; | ||
/* eslint-enable flowtype/no-weak-types */exports.default = | ||
{ print, test }; | ||
{ serialize, test }; |
@@ -1,2 +0,2 @@ | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.print = undefined; | ||
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports.test = exports.serialize = undefined; | ||
@@ -19,102 +19,53 @@ | ||
var _markup = require('./lib/markup'); /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const testSymbol = Symbol.for('react.test.json'); | ||
const serialize = exports.serialize = ( | ||
object, | ||
config, | ||
indentation, | ||
depth, | ||
refs, | ||
printer) => | ||
++depth > config.maxDepth ? | ||
(0, _markup.printElementAsLeaf)(object.type, config) : | ||
(0, _markup.printElement)( | ||
object.type, | ||
object.props ? | ||
(0, _markup.printProps)( | ||
Object.keys(object.props).sort(), | ||
// Despite ternary expression, Flow 0.51.0 found incorrect error: | ||
// undefined is incompatible with the expected param type of Object | ||
// $FlowFixMe | ||
object.props, | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer) : | ||
var _escape_html = require('./lib/escape_html');var _escape_html2 = _interopRequireDefault(_escape_html);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };} /** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* | ||
*/const reactTestInstance = Symbol.for('react.test.json');function printChildren(children, print, indent, colors, | ||
opts) | ||
{ | ||
return children. | ||
map(node => { | ||
if (typeof node === 'string') { | ||
return colors.content.open + (0, _escape_html2.default)(node) + colors.content.close; | ||
} else { | ||
return print(node); | ||
} | ||
}). | ||
join(opts.edgeSpacing); | ||
} | ||
'', | ||
object.children ? | ||
(0, _markup.printChildren)( | ||
object.children, | ||
config, | ||
indentation + config.indent, | ||
depth, | ||
refs, | ||
printer) : | ||
function printProps(props, print, indent, colors, opts) { | ||
return Object.keys(props). | ||
sort(). | ||
map(name => { | ||
const prop = props[name]; | ||
let printed = print(prop); | ||
'', | ||
config, | ||
indentation); | ||
if (typeof prop !== 'string') { | ||
if (printed.indexOf('\n') !== -1) { | ||
printed = | ||
'{' + | ||
opts.edgeSpacing + | ||
indent(indent(printed) + opts.edgeSpacing + '}'); | ||
} else { | ||
printed = '{' + printed + '}'; | ||
} | ||
} | ||
return ( | ||
opts.spacing + | ||
indent(colors.prop.open + name + colors.prop.close + '=') + | ||
colors.value.open + | ||
printed + | ||
colors.value.close); | ||
const test = exports.test = val => val && val.$$typeof === testSymbol;exports.default = | ||
}). | ||
join(''); | ||
} | ||
const print = exports.print = ( | ||
instance, | ||
print, | ||
indent, | ||
opts, | ||
colors) => | ||
{ | ||
let closeInNewLine = false; | ||
let result = colors.tag.open + '<' + instance.type + colors.tag.close; | ||
if (instance.props) { | ||
closeInNewLine = !!Object.keys(instance.props).length && !opts.min; | ||
result += printProps(instance.props, print, indent, colors, opts); | ||
} | ||
if (instance.children) { | ||
const children = printChildren( | ||
instance.children, | ||
print, | ||
indent, | ||
colors, | ||
opts); | ||
result += | ||
colors.tag.open + ( | ||
closeInNewLine ? '\n' : '') + | ||
'>' + | ||
colors.tag.close + | ||
opts.edgeSpacing + | ||
indent(children) + | ||
opts.edgeSpacing + | ||
colors.tag.open + | ||
'</' + | ||
instance.type + | ||
'>' + | ||
colors.tag.close; | ||
} else { | ||
result += | ||
colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close; | ||
} | ||
return result; | ||
}; | ||
const test = exports.test = object => | ||
object && object.$$typeof === reactTestInstance;exports.default = | ||
{ print, test }; | ||
{ serialize, test }; |
{ | ||
"name": "pretty-format", | ||
"version": "20.1.0-delta.5", | ||
"version": "20.1.0-echo.1", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
394068
16
4968