Skip to content

Commit

Permalink
JSX maintains spaces that matter (fixes #30 and thus part of #73)
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex committed Jan 12, 2017
1 parent fffb358 commit e033326
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/printer.js
Expand Up @@ -1971,7 +1971,7 @@ function printJSXElement(path, options, print) {

children.push(
beginBreak ? hardline : "",
child.value.replace(/^\s+|\s+$/g, ""),
child.value.replace(/^\s+|\s+$/g, endBreak ? "" : " "),
endBreak ? hardline : ""
);
} else if (/\n/.test(child.value)) {
Expand Down
15 changes: 13 additions & 2 deletions tests/prettier/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -60,13 +60,24 @@ const comp4 = (
<div
style={styles}
key=\"something\"
>Create wrapping parens and indent<strong>all the things</strong>.</div>
>Create wrapping parens and indent <strong>all the things</strong>.</div>
);
const comp5 = <div>Keep it on one line.</div>;
"
`;

exports[`test jsx-significant-space.js 1`] = `
"<span>
foo <span>bar</span>
</span>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<span>
foo <span>bar</span>
</span>;
"
`;

exports[`test jsx-split-attrs.js 1`] = `
"long_closed =
<BaseForm url=\"/auth/google\" method=\"GET\" colour=\"blue\" size=\"large\" submitLabel=\"Sign in with Google\"/>
Expand Down Expand Up @@ -155,7 +166,7 @@ const render4 = ({ styles }) => (
<div
style={styles}
key=\"something\"
>Create wrapping parens and indent<strong>all the things</strong>.</div>
>Create wrapping parens and indent <strong>all the things</strong>.</div>
);
const render5 = ({ styles }) => <div>Keep it on one line.</div>;
Expand Down
3 changes: 3 additions & 0 deletions tests/prettier/jsx-significant-space.js
@@ -0,0 +1,3 @@
<span>
foo <span>bar</span>
</span>

0 comments on commit e033326

Please sign in to comment.