Skip to content

Commit

Permalink
fix(whitespace): stop rendering it differently in SOME cases
Browse files Browse the repository at this point in the history
do not try to be smarter than any assertion/diff lib could be
  • Loading branch information
vvo committed Nov 8, 2015
1 parent 708723c commit 128aa95
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Features:
- sort object keys in a deterministic order (`o={{a: 1, b:2}} === o={{b:2, a:1}}`)
- handle `ref` and `key` attributes, they are always on top of props
- React's documentation indent style for JSX
- Display whitespace as `<whitespace>` when needed

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
Expand Down
4 changes: 1 addition & 3 deletions index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,7 @@ describe(`reactElementToJSXString(ReactElement)`, () => {
it(`reactElementToJSXString(<div> {false} </div>)`, () => {
expect(
reactElementToJSXString(<div> {false} </div>)
).toEqual(`<div>
<whitespace><whitespace>
</div>`);
).toEqual(`<div>\n \n</div>`);
});

it(`reactElementToJSXString(<div>{null}</div>)`, () => {
Expand Down
11 changes: 1 addition & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
let props = formatProps(ReactElement.props);
let attributes = [];
let children = React.Children.toArray(ReactElement.props.children)
.filter(onlyMeaningfulChildren)
.map(displayWhitespace);
.filter(onlyMeaningfulChildren);

if (ReactElement.ref !== null) {
attributes.push(getJSXAttribute('ref', ReactElement.ref));
Expand Down Expand Up @@ -192,11 +191,3 @@ function noChildren(propName) {
function onlyMeaningfulChildren(children) {
return children !== true && children !== false && children !== null;
}

function displayWhitespace(children) {
if (children === ' ') {
return '<whitespace>';
}

return children;
}

0 comments on commit 128aa95

Please sign in to comment.