diff options
Diffstat (limited to 'node_modules/pretty-format/build')
5 files changed, 672 insertions, 0 deletions
diff --git a/node_modules/pretty-format/build/index.js b/node_modules/pretty-format/build/index.js new file mode 100644 index 000000000..68492f6db --- /dev/null +++ b/node_modules/pretty-format/build/index.js @@ -0,0 +1,427 @@ +/** + * 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. + */ +/* eslint-disable max-len */ + +'use strict'; + +const style = require('ansi-styles'); + +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/ig; + +const getSymbols = Object.getOwnPropertySymbols || (obj => []); + +function isToStringedArrayType(toStringed) { + return ( + toStringed === '[object Array]' || + toStringed === '[object ArrayBuffer]' || + toStringed === '[object DataView]' || + toStringed === '[object Float32Array]' || + toStringed === '[object Float64Array]' || + toStringed === '[object Int8Array]' || + toStringed === '[object Int16Array]' || + toStringed === '[object Int32Array]' || + toStringed === '[object Uint8Array]' || + toStringed === '[object Uint8ClampedArray]' || + toStringed === '[object Uint16Array]' || + toStringed === '[object Uint32Array]'); + +} + +function printNumber(val) { + if (val != +val) { + return 'NaN'; + } + const isNegativeZero = val === 0 && 1 / val < 0; + return isNegativeZero ? '-0' : '' + val; +} + +function printFunction(val, printFunctionName) { + if (!printFunctionName) { + return '[Function]'; + } else if (val.name === '') { + return '[Function anonymous]'; + } else { + return '[Function ' + val.name + ']'; + } +} + +function printSymbol(val) { + return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); +} + +function printError(val) { + return '[' + errorToString.call(val) + ']'; +} + +function printBasicValue(val, printFunctionName, escapeRegex) { + if (val === true || val === false) { + return '' + val; + } + if (val === undefined) { + return 'undefined'; + } + if (val === null) { + return 'null'; + } + + const typeOf = typeof val; + + if (typeOf === 'number') { + return printNumber(val); + } + if (typeOf === 'string') { + return '"' + val.replace(/"|\\/g, '\\$&') + '"'; + } + 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 (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') { + return printFunction(val, printFunctionName); + } + if (toStringed === '[object Symbol]') { + return printSymbol(val); + } + if (toStringed === '[object Date]') { + return toISOString.call(val); + } + if (toStringed === '[object Error]') { + return printError(val); + } + if (toStringed === '[object RegExp]') { + if (escapeRegex) { + // https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js + return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); + } + return regExpToString.call(val); + } + if (toStringed === '[object Arguments]' && val.length === 0) { + return 'Arguments []'; + } + if (isToStringedArrayType(toStringed) && val.length === 0) { + return val.constructor.name + ' []'; + } + + if (val instanceof Error) { + return printError(val); + } + + return false; +} + +function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let body = ''; + + if (list.length) { + body += edgeSpacing; + + const innerIndent = prevIndent + indent; + + for (let i = 0; i < list.length; i++) { + body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + if (i < list.length - 1) { + body += ',' + spacing; + } + } + + body += (min ? '' : ',') + edgeSpacing + prevIndent; + } + + return '[' + body + ']'; +} + +function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let result = 'Map {'; + const iterator = val.entries(); + let current = iterator.next(); + + if (!current.done) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + while (!current.done) { + const key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + const value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + result += innerIndent + key + ' => ' + value; + + current = iterator.next(); + + if (!current.done) { + result += ',' + spacing; + } + } + + result += (min ? '' : ',') + edgeSpacing + prevIndent; + } + + return result + '}'; +} + +function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + const constructor = min ? '' : val.constructor ? val.constructor.name + ' ' : 'Object '; + let result = constructor + '{'; + let keys = Object.keys(val).sort(); + const symbols = getSymbols(val); + + if (symbols.length) { + keys = keys. + filter(key => !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]')). + concat(symbols); + } + + if (keys.length) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + const value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + result += innerIndent + name + ': ' + value; + + if (i < keys.length - 1) { + result += ',' + spacing; + } + } + + result += (min ? '' : ',') + edgeSpacing + prevIndent; + } + + return result + '}'; +} + +function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let result = 'Set {'; + const iterator = val.entries(); + let current = iterator.next(); + + if (!current.done) { + result += edgeSpacing; + + const innerIndent = prevIndent + indent; + + while (!current.done) { + result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + + current = iterator.next(); + + if (!current.done) { + result += ',' + spacing; + } + } + + result += (min ? '' : ',') + edgeSpacing + prevIndent; + } + + return result + '}'; +} + +function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + refs = refs.slice(); + if (refs.indexOf(val) > -1) { + return '[Circular]'; + } else { + refs.push(val); + } + + currentDepth++; + + const hitMaxDepth = currentDepth > maxDepth; + + if (callToJSON && !hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') { + return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } + + const toStringed = toString.call(val); + if (toStringed === '[object Arguments]') { + return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (isToStringedArrayType(toStringed)) { + return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (toStringed === '[object Map]') { + return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } else if (toStringed === '[object Set]') { + return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } + + return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + let match = false; + let plugin; + + for (let p = 0; p < plugins.length; p++) { + plugin = plugins[p]; + + if (plugin.test(val)) { + match = true; + break; + } + } + + if (!match) { + return false; + } + + function boundPrint(val) { + return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + } + + function boundIndent(str) { + const indentation = prevIndent + indent; + return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation); + } + + const opts = { + edgeSpacing, + min, + spacing }; + + return plugin.print(val, boundPrint, boundIndent, opts, colors); +} + +function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors) { + const basic = printBasicValue(val, printFunctionName, escapeRegex); + if (basic) { + return basic; + } + + const plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); + if (plugin) { + return plugin; + } + + return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min, callToJSON, printFunctionName, escapeRegex, colors); +} + +const DEFAULTS = { + callToJSON: true, + escapeRegex: false, + highlight: false, + indent: 2, + maxDepth: Infinity, + min: false, + plugins: [], + printFunctionName: true, + theme: { + content: 'reset', + prop: 'yellow', + tag: 'cyan', + value: 'green' } }; + + + +function validateOptions(opts) { + Object.keys(opts).forEach(key => { + if (!DEFAULTS.hasOwnProperty(key)) { + throw new Error('prettyFormat: Invalid option: ' + key); + } + }); + + if (opts.min && opts.indent !== undefined && opts.indent !== 0) { + throw new Error('prettyFormat: Cannot run with min option and indent'); + } +} + +function normalizeOptions(opts) { + const result = {}; + + Object.keys(DEFAULTS).forEach(key => + result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key]); + + + if (result.min) { + result.indent = 0; + } + + return result; +} + +function createIndent(indent) { + return new Array(indent + 1).join(' '); +} + +function prettyFormat(val, opts) { + if (!opts) { + opts = DEFAULTS; + } else { + validateOptions(opts); + opts = normalizeOptions(opts); + } + + const colors = {}; + Object.keys(opts.theme).forEach(key => { + if (opts.highlight) { + colors[key] = style[opts.theme[key]]; + } else { + colors[key] = { close: '', open: '' }; + } + }); + + let indent; + let refs; + const prevIndent = ''; + const currentDepth = 0; + const spacing = opts.min ? ' ' : '\n'; + const edgeSpacing = opts.min ? '' : '\n'; + + if (opts && opts.plugins.length) { + indent = createIndent(opts.indent); + refs = []; + const pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex, colors); + if (pluginsResult) { + return pluginsResult; + } + } + + const basicResult = printBasicValue(val, opts.printFunctionName, opts.escapeRegex); + if (basicResult) { + return basicResult; + } + + if (!indent) { + indent = createIndent(opts.indent); + } + if (!refs) { + refs = []; + } + return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min, opts.callToJSON, opts.printFunctionName, opts.escapeRegex, colors); +} + +module.exports = prettyFormat;
\ No newline at end of file diff --git a/node_modules/pretty-format/build/plugins/AsymmetricMatcher.js b/node_modules/pretty-format/build/plugins/AsymmetricMatcher.js new file mode 100644 index 000000000..ec529fbc3 --- /dev/null +++ b/node_modules/pretty-format/build/plugins/AsymmetricMatcher.js @@ -0,0 +1,54 @@ +/** + * 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. + * + */ + +'use strict'; + +const asymmetricMatcher = Symbol.for('jest.asymmetricMatcher'); +const SPACE = ' '; + +class ArrayContaining extends Array {} +class ObjectContaining extends Object {} + +const printAsymmetricMatcher = ( +val, +print, +indent, +opts, +colors) => +{ + const stringedValue = val.toString(); + + if (stringedValue === 'ArrayContaining') { + const array = ArrayContaining.from(val.sample); + return opts.spacing === SPACE ? + stringedValue + SPACE + print(array) : + print(array); + } + + if (stringedValue === 'ObjectContaining') { + const object = Object.assign(new ObjectContaining(), val.sample); + return opts.spacing === SPACE ? + stringedValue + SPACE + print(object) : + print(object); + } + + if (stringedValue === 'StringMatching') { + return stringedValue + SPACE + print(val.sample); + } + + if (stringedValue === 'StringContaining') { + return stringedValue + SPACE + print(val.sample); + } + + return val.toAsymmetricMatcher(); +}; + +module.exports = { + print: printAsymmetricMatcher, + test: object => object && object.$$typeof === asymmetricMatcher };
\ No newline at end of file diff --git a/node_modules/pretty-format/build/plugins/ReactElement.js b/node_modules/pretty-format/build/plugins/ReactElement.js new file mode 100644 index 000000000..76f3350ac --- /dev/null +++ b/node_modules/pretty-format/build/plugins/ReactElement.js @@ -0,0 +1,95 @@ +/** + * 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. + */ +/* eslint-disable max-len */ +'use strict'; + +const escapeHTML = require('./escapeHTML'); + +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); + } +} + +function printChildren(flatChildren, print, indent, colors, opts) { + return flatChildren.map(node => { + if (typeof node === 'object') { + return printElement(node, print, indent, colors, opts); + } else if (typeof node === 'string') { + return colors.content.open + escapeHTML(node) + colors.content.close; + } else { + return print(node); + } + }).join(opts.edgeSpacing); +} + +function printProps(props, print, indent, colors, opts) { + return Object.keys(props).sort().map(name => { + if (name === 'children') { + return ''; + } + + const prop = props[name]; + let printed = print(prop); + + 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; + }).join(''); +} + +function printElement(element, print, indent, colors, opts) { + 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; +} + +module.exports = { + print(val, print, indent, opts, colors) { + return printElement(val, print, indent, colors, opts); + }, + test(object) { + return object && object.$$typeof === reactElement; + } };
\ No newline at end of file diff --git a/node_modules/pretty-format/build/plugins/ReactTestComponent.js b/node_modules/pretty-format/build/plugins/ReactTestComponent.js new file mode 100644 index 000000000..fdf31b6d5 --- /dev/null +++ b/node_modules/pretty-format/build/plugins/ReactTestComponent.js @@ -0,0 +1,80 @@ +/** + * 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. + * + * + */ +/* eslint-disable max-len */ +'use strict'; + +const escapeHTML = require('./escapeHTML'); + +const reactTestInstance = Symbol.for('react.test.json'); + + + + + + + +// Child can be `number` in Stack renderer but not in Fiber renderer. + + +function printChildren(children, print, indent, colors, opts) { + return children.map(child => printInstance(child, print, indent, colors, opts)).join(opts.edgeSpacing); +} + +function printProps(props, print, indent, colors, opts) { + return Object.keys(props).sort().map(name => { + const prop = props[name]; + let printed = print(prop); + + 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; + }).join(''); +} + +function printInstance(instance, print, indent, colors, opts) { + if (typeof instance == 'number') { + return print(instance); + } else if (typeof instance === 'string') { + return colors.content.open + escapeHTML(instance) + colors.content.close; + } + + let closeInNewLine = false; + let result = colors.tag.open + '<' + instance.type + colors.tag.close; + + if (instance.props) { + // If assignments are in opposite order, Flow 0.39.0 finds incorrect error: + // element of Object.keys. Expected object instead of possibly undefined value + 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; +} + +module.exports = { + print(val, print, indent, opts, colors) { + return printInstance(val, print, indent, colors, opts); + }, + test(object) { + return object && object.$$typeof === reactTestInstance; + } };
\ No newline at end of file diff --git a/node_modules/pretty-format/build/plugins/escapeHTML.js b/node_modules/pretty-format/build/plugins/escapeHTML.js new file mode 100644 index 000000000..de6dda184 --- /dev/null +++ b/node_modules/pretty-format/build/plugins/escapeHTML.js @@ -0,0 +1,16 @@ +/** + * 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. + * + * + */ +'use strict'; + +function escapeHTML(str) { + return str.replace(/</g, '<').replace(/>/g, '>'); +} + +module.exports = escapeHTML;
\ No newline at end of file |