diff --git a/src/doc-builders.js b/src/doc-builders.js
index 0f1526be8175..629d17a5a804 100644
--- a/src/doc-builders.js
+++ b/src/doc-builders.js
@@ -57,6 +57,16 @@ function conditionalGroup(states, opts) {
);
}
+function fill(parts) {
+ if (parts.length === 0) {
+ return '';
+ }
+
+ parts.forEach(assertDoc);
+
+ return { type: "fill", parts };
+}
+
function ifBreak(breakContents, flatContents) {
if (breakContents) {
assertDoc(breakContents);
@@ -106,6 +116,7 @@ module.exports = {
literalline,
group,
conditionalGroup,
+ fill,
lineSuffix,
lineSuffixBoundary,
breakParent,
diff --git a/src/doc-debug.js b/src/doc-debug.js
index df3dd2794d8a..e0732d2a54d1 100644
--- a/src/doc-debug.js
+++ b/src/doc-debug.js
@@ -101,6 +101,13 @@ function printDoc(doc) {
);
}
+ if (doc.type === "fill") {
+ return ("fill") +
+ "(" +
+ doc.parts.map(printDoc).join(", ") +
+ ")";
+ }
+
if (doc.type === "line-suffix") {
return "lineSuffix(" + printDoc(doc.contents) + ")";
}
diff --git a/src/doc-printer.js b/src/doc-printer.js
index 7e5acad251c7..a9ab98410d0b 100644
--- a/src/doc-printer.js
+++ b/src/doc-printer.js
@@ -1,5 +1,12 @@
"use strict";
+var docBuilders = require("./doc-builders");
+var concat = docBuilders.concat;
+var line = docBuilders.line;
+var softline = docBuilders.softline;
+var fill = docBuilders.fill;
+var ifBreak = docBuilders.ifBreak;
+
const MODE_BREAK = 1;
const MODE_FLAT = 2;
@@ -30,7 +37,7 @@ function makeAlign(ind, n) {
};
}
-function fits(next, restCommands, width) {
+function fits(next, restCommands, width, mustBeFlat = false) {
let restIdx = restCommands.length;
const cmds = [next];
while (width >= 0) {
@@ -70,8 +77,19 @@ function fits(next, restCommands, width) {
break;
case "group":
+ if (mustBeFlat && doc.break) {
+ return false;
+ }
cmds.push([ind, doc.break ? MODE_BREAK : mode, doc.contents]);
+ break;
+ case "fill":
+ // include number of spaces
+ cmds.push([ind, mode, " ".repeat(doc.parts.length - 1)]);
+ for (var i = doc.parts.length - 1; i >= 0; i--) {
+ cmds.push([ind, mode, doc.parts[i]]);
+ }
+
break;
case "if-break":
if (mode === MODE_BREAK) {
@@ -210,6 +228,51 @@ function printDocToString(doc, options) {
break;
}
break;
+ case "fill":
+ // shouldRemeasure = false;
+ let rem = width - pos;
+
+ const parts = doc.parts;
+ if (parts.length === 1) {
+ cmds.push([ind, MODE_BREAK, parts[0]]);
+ break;
+ }
+
+ const first = parts[0];
+ const second = parts[1];
+ const remaining = parts.slice(1);
+ const firstCmd = [ind, MODE_FLAT, first];
+ const remainingCmd = [ind, MODE_BREAK, fill(remaining)];
+
+ const firstAndSecondCmd = [ind, MODE_FLAT, concat([first, second])];
+
+ if (fits(firstAndSecondCmd, cmds, rem, true)) {
+ // console.log('first and second fit', [first, second]);
+ cmds.push(remainingCmd)
+ cmds.push([ind, MODE_FLAT, line]);
+ cmds.push(firstCmd);
+ } else if (fits(firstCmd, cmds, width - rem, true)) {
+ // console.log('only first fits', [first, second]);
+ cmds.push(remainingCmd)
+ if (typeof second !== 'string' || typeof first !== 'string') {
+ cmds.push([ind, MODE_BREAK, "{' '}"]);
+ }
+ cmds.push([ind, MODE_BREAK, line]);
+ cmds.push(firstCmd);
+ } else {
+ // console.log('neither fit', [first, second]);
+ out.push(newLine + " ".repeat(ind));
+ pos = ind;
+
+ cmds.push(remainingCmd);
+ if (typeof first !== 'string') {
+ cmds.push([ind, MODE_BREAK, line]);
+ cmds.push([ind, MODE_BREAK, "{' '}"]);
+ }
+ cmds.push([ind, MODE_BREAK, line]);
+ cmds.push([ind, MODE_BREAK, first]);
+ }
+ break;
case "if-break":
if (mode === MODE_BREAK) {
if (doc.breakContents) {
diff --git a/src/printer.js b/src/printer.js
index bc31fab36bdd..6543c09e531c 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -17,6 +17,7 @@ var group = docBuilders.group;
var indent = docBuilders.indent;
var align = docBuilders.align;
var conditionalGroup = docBuilders.conditionalGroup;
+var fill = docBuilders.fill;
var ifBreak = docBuilders.ifBreak;
var breakParent = docBuilders.breakParent;
var lineSuffixBoundary = docBuilders.lineSuffixBoundary;
@@ -2873,62 +2874,88 @@ function printJSXChildren(path, options, print, jsxWhitespace) {
: util.htmlEscapeInsideAngleBracket(child.value);
const value = partiallyEscapedValue.replace(/\u00a0/g, " ");
- if (/\S/.test(value)) {
- // treat each line of text as its own entity
- value.split(/(\r?\n\s*)/).forEach(line => {
- const newlines = line.match(/\n/g);
- if (newlines) {
- children.push(hardline);
-
- // allow one extra newline
- if (newlines.length > 1) {
- children.push(hardline);
- }
- return;
- }
-
- const beginSpace = /^\s+/.test(line);
- if (beginSpace) {
- children.push(jsxWhitespace);
- children.push(softline);
- }
+ // if (/\S/.test(value)) {
+ // // treat each line of text as its own entity
+ // value.split(/(\r?\n\s*)/).forEach(line => {
+ // const newlines = line.match(/\n/g);
+ // if (newlines) {
+ // children.push(hardline);
+ //
+ // // allow one extra newline
+ // if (newlines.length > 1) {
+ // children.push(hardline);
+ // }
+ // return;
+ // }
+ //
+ // const beginSpace = /^\s+/.test(line);
+ // if (beginSpace) {
+ // children.push(jsxWhitespace);
+ // children.push(softline);
+ // }
+ //
+ // const stripped = line.replace(/^\s+|\s+$/g, "");
+ // if (stripped) {
+ // children.push(stripped);
+ // }
+ //
+ // const endSpace = /\s+$/.test(line);
+ // if (endSpace) {
+ // children.push(softline);
+ // children.push(jsxWhitespace);
+ // }
+ // });
+ //
+ // if (!isLineNext(util.getLast(children))) {
+ // children.push(softline);
+ // }
+ // } else if (/\n/.test(value)) {
+ // children.push(hardline);
+ //
+ // // allow one extra newline
+ // if (value.match(/\n/g).length > 1) {
+ // children.push(hardline);
+ // }
+ // } else if (/\s/.test(value)) {
+ // // whitespace-only without newlines,
+ // // eg; a single space separating two elements
+ // children.push(jsxWhitespace);
+ // children.push(softline);
+ // }
+
+ value.replace(/^\s+|\s+$/g, "").split(/(\s+)/).forEach(word => {
+ if (word.length === 0) {
+ return;
+ }
- const stripped = line.replace(/^\s+|\s+$/g, "");
- if (stripped) {
- children.push(stripped);
- }
+ const newlines = word.match(/\n/g);
+ if (newlines) {
+ children.push(hardline);
- const endSpace = /\s+$/.test(line);
- if (endSpace) {
- children.push(softline);
- children.push(jsxWhitespace);
+ // allow one extra newline
+ if (newlines.length > 1) {
+ children.push(hardline);
}
- });
-
- if (!isLineNext(util.getLast(children))) {
- children.push(softline);
+ return;
}
- } else if (/\n/.test(value)) {
- children.push(hardline);
- // allow one extra newline
- if (value.match(/\n/g).length > 1) {
- children.push(hardline);
+ const space = /^\s+$/.test(word);
+ if (space) {
+ // children.push(line);
+ return;
}
- } else if (/\s/.test(value)) {
- // whitespace-only without newlines,
- // eg; a single space separating two elements
- children.push(jsxWhitespace);
- children.push(softline);
- }
+
+ children.push(word);
+ });
+
} else {
children.push(print(childPath));
- // add a line unless it's followed by a JSX newline
- let next = n.children[i + 1];
- if (!(next && /^\s*\n/.test(next.value))) {
- children.push(softline);
- }
+ // // add a line unless it's followed by a JSX newline
+ // let next = n.children[i + 1];
+ // if (!(next && /^\s*\n/.test(next.value))) {
+ // children.push(softline);
+ // }
}
}, "children");
@@ -3055,9 +3082,9 @@ function printJSXElement(path, options, print) {
concat(
groups.map(
contents =>
- (Array.isArray(contents)
- ? conditionalGroup([concat(contents)])
- : contents)
+ Array.isArray(contents)
+ ? fill(contents)
+ : contents
)
)
];
@@ -3076,7 +3103,7 @@ function printJSXElement(path, options, print) {
}
return conditionalGroup([
- group(concat([openingLines, concat(children), closingLines])),
+ group(concat([openingLines, fill(children), closingLines])),
multiLineElem
]);
}
diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap
index 823e4548d9ee..d61eaa3946a3 100644
--- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap
@@ -200,14 +200,11 @@ function render() {
function render() {
return (
-
- this.setState({
+ this.setState({
progress: Math.round(
100 * e.nativeEvent.loaded / e.nativeEvent.total
)
- })}
- />
+ })} />
);
}
@@ -215,14 +212,11 @@ function render() {
function render() {
return (
-
- this.setState({
+ this.setState({
progress: Math.round(
100 * e.nativeEvent.loaded / e.nativeEvent.total
)
- })}
- />
+ })} />
);
}
diff --git a/tests/comments/__snapshots__/jsfmt.spec.js.snap b/tests/comments/__snapshots__/jsfmt.spec.js.snap
index 377bb50d83b3..38f6dcd99929 100644
--- a/tests/comments/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/comments/__snapshots__/jsfmt.spec.js.snap
@@ -489,9 +489,7 @@ Observable.of(process)
.takeUntil(exit);
// Comments disappear inside of JSX
-
- {/* Some comment */}
-
;
+{/* Some comment */}
;
// Comments in JSX tag are placed in a non optimal way
{/*
Some very v ery very very long line to break line width limit
*/}
;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- {/* comment */}
-
;
+{/* comment */}
;
-
- {/* comment */}
-
;
+{/* comment */}
;
-
- {/* comment
-*/}
-
;
+{/* comment
+*/}
;
-
- {a /* comment
-*/}
-
;
+{a /* comment
+*/}
;
- {
- /* comment
+ {/* comment
*/
- a
- }
+ a}
;
-
- {/* comment */}
-
;
+{/* comment */}
;
-
- {/* comment */}
-
;
+{/* comment */}
;
{
diff --git a/tests/flow/more_react/App.react.js b/tests/flow/more_react/App.react.js
index 9121b661cd2b..a583a3f2b319 100644
--- a/tests/flow/more_react/App.react.js
+++ b/tests/flow/more_react/App.react.js
@@ -33,7 +33,7 @@ var App = React.createClass({
return (
{foo(x,y)}
- {foo(z,x)} // error, since z: number
+ {foo(z,x) /* error, since z: number */}
);
}
diff --git a/tests/flow/more_react/JSX.js b/tests/flow/more_react/JSX.js
index 68a256f9c3e7..0f95738ccb43 100644
--- a/tests/flow/more_react/JSX.js
+++ b/tests/flow/more_react/JSX.js
@@ -5,7 +5,7 @@ var React = require('react');
var App = require('App.react');
var app =
-
// error, y: number but foo expects string in App.react
+ {/* error, y: number but foo expects string in App.react */}
Some text.
;
diff --git a/tests/flow/more_react/__snapshots__/jsfmt.spec.js.snap b/tests/flow/more_react/__snapshots__/jsfmt.spec.js.snap
index 6afb885f1877..48bb6c5a4dfc 100644
--- a/tests/flow/more_react/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/more_react/__snapshots__/jsfmt.spec.js.snap
@@ -56,7 +56,7 @@ var App = React.createClass({
return (
{foo(x,y)}
- {foo(z,x)} // error, since z: number
+ {foo(z,x) /* error, since z: number */}
);
}
@@ -97,12 +97,7 @@ var App = React.createClass({
//this.state;
- return (
-
- {foo(x, y)}
- {foo(z, x)} // error, since z: number
-
- );
+ return {foo(x, y)} {foo(z, x) /* error, since z: number */}
;
}
});
@@ -151,7 +146,7 @@ var React = require('react');
var App = require('App.react');
var app =
- // error, y: number but foo expects string in App.react
+ {/* error, y: number but foo expects string in App.react */}
Some text.
;
@@ -164,8 +159,7 @@ var App = require("App.react");
var app = (
- {" "}// error, y: number but foo expects string in App.react
- Some text.
+ {/* error, y: number but foo expects string in App.react */} Some text.
);
diff --git a/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap b/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
index f7c656269ac1..8b8826f1779f 100644
--- a/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/new_react/__snapshots__/jsfmt.spec.js.snap
@@ -864,11 +864,7 @@ var ReactClass = React.createClass({
render: function(): any {
// Any state access here seems to make state any
this.state;
- return (
-
- {this.state.bar.qux}
-
- );
+ return {this.state.bar.qux}
;
}
});
diff --git a/tests/flow/react/__snapshots__/jsfmt.spec.js.snap b/tests/flow/react/__snapshots__/jsfmt.spec.js.snap
index 702c5b1cc110..b29f9de5f6bd 100644
--- a/tests/flow/react/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/react/__snapshots__/jsfmt.spec.js.snap
@@ -741,11 +741,7 @@ class Bar extends React.Component {
test: number
};
render() {
- return (
-
- {this.props.test}
-
- );
+ return {this.props.test}
;
}
}
diff --git a/tests/flow/react_modules/__snapshots__/jsfmt.spec.js.snap b/tests/flow/react_modules/__snapshots__/jsfmt.spec.js.snap
index 8e0c7500940d..b7adaa6f5a4c 100644
--- a/tests/flow/react_modules/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/flow/react_modules/__snapshots__/jsfmt.spec.js.snap
@@ -44,12 +44,7 @@ var HelloLocal = React.createClass({
var Callsite = React.createClass({
render: function(): React.Element<*> {
- return (
-
-
-
-
- );
+ return
;
}
});
@@ -134,12 +129,7 @@ class HelloLocal extends React.Component {
class Callsite extends React.Component {
render(): React.Element<*> {
- return (
-
-
-
-
- );
+ return
;
}
}
@@ -226,12 +216,7 @@ class HelloLocal extends React.Component {
class Callsite extends React.Component {
render(): React.Element<*> {
- return (
-
-
-
-
- );
+ return
;
}
}
diff --git a/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap
index be5efadce82e..228b7614c3b6 100644
--- a/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx-multiline-assign/__snapshots__/jsfmt.spec.js.snap
@@ -22,22 +22,12 @@ const comp4 = Create wrapping parens and ind
const comp5 =
Keep it on one line.
;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const comp1 = (
-
- Keep the wrapping parens.
-
+
Keep the wrapping parens.
);
-const comp2 = (
-
- Create wrapping parens.
-
-);
+const comp2 =
Create wrapping parens.
;
-comp2A = (
-
- Create wrapping parens.
-
-);
+comp2A =
Create wrapping parens.
;
const comp3 = (
Bump to next line without parens
@@ -45,7 +35,7 @@ const comp3 = (
const comp4 = (
- Create wrapping parens and indent all the things .
+ Create wrapping parens and indent all the things .
);
diff --git a/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap
index 49d995e1c490..71741536c45e 100644
--- a/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx-newlines/__snapshots__/jsfmt.spec.js.snap
@@ -98,8 +98,17 @@ regression_extra_newline_2 = (
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
keep = (
- Welcome to the Universal React Starter-kyt .
- This starter kyt should serve as the base for an advanced,
+ Welcome to
+the
+
+
+ Universal React Starter-kyt
+
+ {' '}
+ .
+ This starter kyt should serve as the base for an
+ advanced,
server-rendered React app.
);
@@ -118,59 +127,31 @@ newlines_text = (
newlines_text_spaced = (
-
space above
space below
-
);
newlines_elems_spaced = (
-
-
- space above
-
- space below
-
-
+
space above space below
);
newlines_mixed = (
- hi
- there
-
- how
+ hi there how
- are you
-
- are you fine today?
+ are you are you fine today?
);
-newlines_elems = (
-
-);
+newlines_elems =
;
regression_extra_newline = (
-
+
+
+ {' '}
New Messages
);
@@ -178,10 +159,12 @@ regression_extra_newline = (
regression_extra_newline_2 = (
(
-
+ {' '}
)
);
@@ -193,8 +176,6 @@ exports[`windows.js 1`] = `
Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
- Text
-
;
+Text
;
`;
diff --git a/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap
index e1bb3b167212..2709abe67762 100644
--- a/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx-significant-space/__snapshots__/jsfmt.spec.js.snap
@@ -76,32 +76,28 @@ not_broken_begin =
long text long text long text long text long text long text long text long text url long text long text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-after = (
-
- foo bar
-
-);
+after = foo bar ;
-before = (
-
- bar foo
-
-);
+before = bar foo ;
before_break1 = (
-
- {" "}
+
+
+ {' '}
foo
);
before_break2 = (
-
- {" "}
+ {' '}
foo
);
@@ -109,56 +105,48 @@ before_break2 = (
after_break = (
foo
- {" "}
-
+ {' '}
);
-within = (
-
- foo bar
-
-);
+within = foo bar ;
break_components = (
-
-
- foobar bar bar
yep
+
+
+ {' '}
+
+
+ foo bar bar bar
yep
+ {' '}
nope
);
-var x = (
-
- hello hi sdkflsdfjk
-
-);
+var x = hello hi sdkflsdfjk
;
-nest_plz = (
-
-);
+nest_plz = ;
regression_not_transformed_1 = (
- {" "}
+
);
regression_not_transformed_2 = (
- {" "}
+
);
similar_1 = (
- {" "}
);
@@ -166,7 +154,6 @@ similar_1 = (
similar_2 = (
- {" "}
);
@@ -178,22 +165,15 @@ similar_3 = (
not_broken_end = (
- long text long text long text long text long text long text long text long text
- {" "}
- url
- {" "}
- long text long text
+ long text long text long text long text long text long text long text long
+ text url long text long text
);
not_broken_begin = (
-
- {" "}
- long text long text long text long text long text long text long text long text
- url
- {" "}
- long text long text
+ long text long text long text long text long text long text long text
+ long text url long text long text
);
diff --git a/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap
index b672ecc84e8a..137b0b08fb03 100644
--- a/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx-split-attrs/__snapshots__/jsfmt.spec.js.snap
@@ -80,7 +80,8 @@ long_open_long_children = (
size="large"
submitLabel="Sign in with Google"
>
-
Hello world
-
+ {' '}
+
+
-
+ {' '}
+
+
-
+ {' '}
+
+
-
-
+ {' '}
d
+ {' '}
;
-short_open = (
-
- hello
-
-);
+short_open =
hello ;
make_self_closing = (
-
+ {' '}
- {" "}
+
);
diff --git a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap
index dd9d578781af..c49afff2e421 100644
--- a/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx-stateless-arrow-fn/__snapshots__/jsfmt.spec.js.snap
@@ -82,9 +82,7 @@ const render1 = ({ styles }) => (
);
const render2 = ({ styles }) => (
-
- Create wrapping parens.
-
+
Create wrapping parens.
);
const render3 = ({ styles }) => (
@@ -93,7 +91,7 @@ const render3 = ({ styles }) => (
const render4 = ({ styles }) => (
- Create wrapping parens and indent all the things .
+ Create wrapping parens and indent all the things .
);
@@ -101,7 +99,8 @@ const render5 = ({ styles }) =>
Keep it on one line.
;
const render6 = ({ styles }) => (
-
(
>
ddd d dd d d dddd dddd hello
-
(
>
ddd d dd d d dddd dddd hello
+ {' '}
-
(
>
ddd d dd d d dddd dddd hello
- {" "}
+ {' '}
hello
@@ -139,22 +142,17 @@ const render6 = ({ styles }) => (
const render7 = () => (
-
Dont break each elem onto its own line.
-
+
Dont break each elem onto its own line.
+ {' '}
);
-const render7A = () => (
-
-);
+const render7A = () =>
;
const render7B = () => (
- Dont break plz
- Dont break plz
- Dont break plz
+ Dont break plz Dont break plz
+ {' '}Dont break plz
);
@@ -193,7 +191,8 @@ const renderTernary = props => (
size="large"
submitLabel="Sign in with Google"
>
- {props.showTheThing
+
+{props.showTheThing
?
(
Hello world
: "hello " + "howdy! "}
- {props.showTheThing
+ {' '}
+
+{props.showTheThing
?
(
Hello world
: null}
- {props.showTheThing
+ {' '}
+
+{props.showTheThing
? null
:
(
>
Hello world
}
- {props.showTheOtherThing ?
I am here
:
}
+ {' '}
+
+{props.showTheOtherThing
+ ?
I am here
+ :
}
+ {' '}
{props.showTheOtherThing ?
I am here!!
: null}
);
diff --git a/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap b/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap
new file mode 100644
index 000000000000..818f11bccc6b
--- /dev/null
+++ b/tests/jsx-text-wrap/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,32 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`test.js 1`] = `
+x =
+
+ A
+ great and powerful monkey lord
+ attacked me!
+
+ Please state your first name part address and occupation for the board of directors and let us know if you would very much like them to contact you in future?
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+x = (
+
+ A
+ {' '}
+
+ great and powerful monkey lord
+
+ {' '}
+ attacked me!
+
+ Please state your first name part address and occupation
+ for the board of directors and let us know if you would very much like
+ {' '}them to contact you in future?
+
+);
+
+`;
diff --git a/tests/jsx-text-wrap/jsfmt.spec.js b/tests/jsx-text-wrap/jsfmt.spec.js
new file mode 100644
index 000000000000..7580dfab0b75
--- /dev/null
+++ b/tests/jsx-text-wrap/jsfmt.spec.js
@@ -0,0 +1 @@
+run_spec(__dirname, null, ["typescript"]);
diff --git a/tests/jsx-text-wrap/test.js b/tests/jsx-text-wrap/test.js
new file mode 100644
index 000000000000..f74f78d831a1
--- /dev/null
+++ b/tests/jsx-text-wrap/test.js
@@ -0,0 +1,8 @@
+x =
+
+ A
+ great and powerful monkey lord
+ attacked me!
+
+ Please state your first name part address and occupation for the board of directors and let us know if you would very much like them to contact you in future?
+
diff --git a/tests/jsx/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/__snapshots__/jsfmt.spec.js.snap
index 42b9326b0c28..4fe26b3dc5fd 100644
--- a/tests/jsx/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx/__snapshots__/jsfmt.spec.js.snap
@@ -88,29 +88,15 @@ exports[`expression.js 1`] = `
]}
/>;
-
- {() => (
-
-
-
- )}
- ;
+
{() => } ;
- {items.map(item => (
-
-
-
- ))}
+ {items.map(item => )}
;
{function() {
- return (
-
-
-
- );
+ return ;
}}
;
@@ -129,13 +115,7 @@ exports[`expression.js 1`] = `
value={option}
/>;
-
- test
-
- }
-/>;
+test} />;
`;
@@ -267,7 +247,7 @@ onClick={() => {
a;
}}
>
- {header}{showSort}
+ {header} {showSort}
;
{
a;
}}
>
- {header}
+
+{
+ header
+ }
+ {' '}
;
diff --git a/tests/jsx_escape/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_escape/__snapshots__/jsfmt.spec.js.snap
index 7764da949082..84f61c33a97c 100644
--- a/tests/jsx_escape/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx_escape/__snapshots__/jsfmt.spec.js.snap
@@ -23,7 +23,7 @@ many_raw_nbsp =
amp = foo & bar
raw_amp = foo & bar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-many_nbsp =
;
+many_nbsp =
;
single_nbsp =
;
many_raw_nbsp =
;
amp = foo & bar ;
@@ -40,7 +40,7 @@ many_raw_nbsp =
amp = foo & bar
raw_amp = foo & bar
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-many_nbsp =
;
+many_nbsp =
;
single_nbsp =
;
many_raw_nbsp =
;
diff --git a/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap
index 0ac630489e8f..e7230f07c5a4 100644
--- a/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/jsx_last_line/__snapshots__/jsfmt.spec.js.snap
@@ -18,8 +18,7 @@ exports[`last_line.js 1`] = `
onChange={this.onChange}
initialValue={this.state.initialValue}
ignoreStuff={true}>
- and the children go here
- and here too
+ and the children go here
and here too
;
`;
@@ -43,8 +42,7 @@ exports[`last_line.js 2`] = `
initialValue={this.state.initialValue}
ignoreStuff={true}
>
- and the children go here
- and here too
+ and the children go here
and here too
;
`;
diff --git a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap
index d56fb1305d91..063d3518f650 100644
--- a/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/last_argument_expansion/__snapshots__/jsfmt.spec.js.snap
@@ -283,9 +283,7 @@ const els = items.map(item => (
));
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const els = items.map(item => (
-
- {children}
-
+ {children}
));
`;
diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js
index 751a4b313b87..67126e366b97 100644
--- a/tests_config/run_spec.js
+++ b/tests_config/run_spec.js
@@ -53,6 +53,9 @@ function run_spec(dirname, options, additionalParsers) {
expect(output).toEqual(verifyOutput);
});
});
+ //
+ // const doc = prettier.__debug.printToDoc(source, options);
+ // console.log(prettier.__debug.formatDoc(doc));
}
if (RUN_AST_TESTS) {