pretty-format
Advanced tools
Comparing version 18.1.0 to 18.5.0-alpha.7da3df39
@@ -13,3 +13,2 @@ /** | ||
const style = require('ansi-styles'); | ||
const printString = require('./printString'); | ||
@@ -87,3 +86,3 @@ const toString = Object.prototype.toString; | ||
if (typeOf === 'string') { | ||
return '"' + printString(val) + '"'; | ||
return '"' + val.replace(/"|\\/g, '\\$&') + '"'; | ||
} | ||
@@ -119,3 +118,4 @@ if (typeOf === 'function') { | ||
if (escapeRegex) { | ||
return printString(regExpToString.call(val)); | ||
// https://github.com/benjamingr/RegExp.escape/blob/master/polyfill.js | ||
return regExpToString.call(val).replace(/[\\^$*+?.()|[\]{}]/g, '\\$&'); | ||
} | ||
@@ -316,2 +316,3 @@ return regExpToString.call(val); | ||
edgeSpacing, | ||
min, | ||
spacing }; | ||
@@ -318,0 +319,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
const printString = require('../printString'); | ||
const escapeHTML = require('./escapeHTML'); | ||
@@ -29,3 +29,3 @@ const reactElement = Symbol.for('react.element'); | ||
} else if (typeof node === 'string') { | ||
return printString(colors.content.open + node + colors.content.close); | ||
return colors.content.open + escapeHTML(node) + colors.content.close; | ||
} else { | ||
@@ -72,2 +72,7 @@ return print(node); | ||
const opaqueChildren = element.props.children; | ||
const hasProps = !!Object.keys(element.props). | ||
filter(propName => propName !== 'children'). | ||
length; | ||
const closeInNewLine = hasProps && !opts.min; | ||
if (opaqueChildren) { | ||
@@ -79,5 +84,5 @@ const flatChildren = []; | ||
const children = printChildren(flatChildren, print, indent, colors, opts); | ||
result += colors.tag.open + '>' + colors.tag.close + opts.edgeSpacing + indent(children) + opts.edgeSpacing + colors.tag.open + '</' + elementName + '>' + colors.tag.close; | ||
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 + ' />' + colors.tag.close; | ||
result += colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close; | ||
} | ||
@@ -84,0 +89,0 @@ |
@@ -11,3 +11,3 @@ /** | ||
const printString = require('../printString'); | ||
const escapeHTML = require('./escapeHTML'); | ||
@@ -41,3 +41,3 @@ const reactTestInstance = Symbol.for('react.test.json'); | ||
} else if (typeof instance === 'string') { | ||
return printString(colors.content.open + instance + colors.content.close); | ||
return colors.content.open + escapeHTML(instance) + colors.content.close; | ||
} | ||
@@ -51,7 +51,9 @@ | ||
const closeInNewLine = !!Object.keys(instance.props).length && !opts.min; | ||
if (instance.children) { | ||
const children = printChildren(instance.children, print, indent, colors, opts); | ||
result += colors.tag.open + '>' + colors.tag.close + opts.edgeSpacing + indent(children) + opts.edgeSpacing + colors.tag.open + '</' + instance.type + '>' + colors.tag.close; | ||
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 + ' />' + colors.tag.close; | ||
result += colors.tag.open + (closeInNewLine ? '\n' : ' ') + '/>' + colors.tag.close; | ||
} | ||
@@ -58,0 +60,0 @@ |
{ | ||
"name": "pretty-format", | ||
"version": "18.1.0", | ||
"version": "18.5.0-alpha.7da3df39", | ||
"repository": { | ||
@@ -12,9 +12,5 @@ "type": "git", | ||
"author": "James Kyle <me@thejameskyle.com>", | ||
"scripts": { | ||
"test": "../../packages/jest-cli/bin/jest.js", | ||
"perf": "node perf/test.js" | ||
}, | ||
"dependencies": { | ||
"ansi-styles": "^2.2.1" | ||
"ansi-styles": "^3.0.0" | ||
} | ||
} |
@@ -17,3 +17,3 @@ /** | ||
const React = require('react'); | ||
const ReactTestRenderer = require('react/lib/ReactTestRenderer'); | ||
const ReactTestRenderer = require('react-test-renderer'); | ||
const ReactTestComponent = require('../build/plugins/ReactTestComponent'); | ||
@@ -58,3 +58,3 @@ | ||
'prettyFormat() ', | ||
() => prettyFormat(value, prettyFormatOpts), | ||
() => prettyFormat(value, prettyFormatOpts) | ||
); | ||
@@ -78,3 +78,3 @@ | ||
const winner = results[0]; | ||
results.forEach((item, index) => { | ||
@@ -208,5 +208,5 @@ item.isWinner = index === 0; | ||
React.createElement('div', null, | ||
React.createElement('div'), | ||
), | ||
), | ||
React.createElement('div') | ||
) | ||
) | ||
); | ||
@@ -213,0 +213,0 @@ |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
287749
10
1808
2
+ Addedansi-styles@3.2.1(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
- Removedansi-styles@2.2.1(transitive)
Updatedansi-styles@^3.0.0