It outputted which is completely wrong
```js
<FlatList
renderItem={info => <span>{info.item.widget.missingProp // $FlowExpectedError - bad widgetCount type 6, should be Object
}</span>}
/>;
```
* Allow JSX lines to be recombined
* Add test case for `<br />` breaking expression
* Fix issue where JSX whitespace could be dropped
* Newlines were incorrectly being preserved when JSX contained text
We completely butcher comments inside of template literals. The fix is to not be able to attach comments to TemplateExpression nodes and to avoid comments that are ine one expression to be moved to another expression. We now have the boundary to prevent outputting invalid code.
Fixes#1617
* Don't let trailing template literal comments escape
This might not be the best-looking solution, but it's a start, and it
passes `AST_COMPARE=1 npm test`
Fixes https://github.com/prettier/prettier/issues/1559
* Add trailing space when changing line comment to block
* Be more discerning about template literal comment placement
Try to maintain the previous behavior if possible.
* Revert "Add trailing space when changing line comment to block"
This reverts commit 1eb42c24819a296c93a79b92a358d30a2aacc16c.
All of the discussions around ternaries are for the form
```js
cond1 ? elem1_if : cond2 ? elem2_if : elem_else
```
but some of them are for the form
```js
cond1 ? cond2 ? elem2_if : elem2_else : elem1_else
```
which is more rare and would be good to call out by adding parenthesis.
```js
cond1 ? (cond2 ? elem2_if : elem2_else) : elem1_else
```
Note that we only want parenthesis if it's written inline, otherwise the indentation is good enough to understand the flow:
```js
cond1
? cond2 ? elem2_if : elem2_else
: elem1_else
```
We need to call the `skipToLineEnd` which skips `,` after an inline comment. So we have to put it inside of the while loop as you can have many comments, a comma and then many more comments.
Fixes#964
* Verify parsers against same snapshot
- Reworked run_spec, now accepts 3th optional array argument for
additional parsers to verify against
- Merged duplicate run_spec configs
- Removed duplicate snapshot data
* Formatted run_spec.js with prettier
* Fixed node4 incompatibility
* Revert "Remove mutation in `printBinaryishExpressions` (#1067)"
This reverts commit e7312ad7b2.
* Revert "Make it clear what parser was used in each snapshot (#1068)"
This reverts commit 4f7ae4815b.
The root cause is that we're calling `printComments` with an empty string, meaning that the leading/trailing comments are not correctly inserted at the right location.
So, the way to fix it is to call `p => concat(parts)` but because we're mutating the array in place, it doesn't work. We need to mutate it and create a copy. But, the root call is actually checking the shape of the parts array which our code is now breaking...
```js
// Don't include the initial expression in the indentation
// level. The first item is guaranteed to be the first
// left-most expression.
parts.length > 0 ? parts[0] : "",
```
The consequence is that binary expressions are no longer indented if the first expression has a comment (but now it places the comment properly!), which seems like a good trade-off.
I'm not sure if we should merge this one or instead refactor this code such that it doesn't rely on mutation and looking at the shape of the printed tree. `printMemberChain` is a good thing to reference for inspiration.
Fixes#946
Right now it's only doing one test for begin/end, but in the issue #1037, we have two nodes that have the same start but different end. The current implementation incorrectly sorts them and the identifier ends up being before the container and therefore the comment search doesn't recurse into it.
Fixes#1037
* Refactor condition in printStatementSequence, add new helper function.
* Add new test cases.
* Move logic in SwitchCase case.
* Revert unrelated changes, remove unecessary variables.
* Use util.getLast helper function.
* Move variables out of the loop.
* Simplify code.
* Fix mapping with mutated path.
In practice, trying to allow calls to be inlined is causing a lot of code to look very weird and unstable as seen by the four issues this is fixing. It also requires us to add a conditional group and do hackery around it.
Fixes#959Fixes#760Fixes#615Fixes#625
* Add new handleOnlyComments function.
* Update tests.
* Update test as the printer forces a trailing newline if there were any contents.
* Implement a different heuristic.
* Update tests.
* Add directives checking in handleOnlyComments function.
* Add directives checking in handleOnlyComments function (amend to retrigger CI).
* Remove duplicate.
* Add new helper function to convert comments as blocks in ExportNamedDeclaration.
* Add new test.
* Switch to a leading position.
* Update test accordingly.
The comments infra has been architected with trailing operators and fails for leading `|`. Instead of having leading comments, we can put trailing comments on the previous one and use the same technique as assignment to deal with the indentation.
Fixes#849
In #596, I fixed a bunch of jsx expression comment edge cases and happened to add a softline there. But it turns out that it's not needed and is actually harmful :)
Fixes#712
* Add new handleFunctionDeclarationComments function.
* Add dangling comments printing for function params.
* Add new test case.
* Update tests.
* Refactor handleFunctionDeclarationComments to only addDanglingComment when no params.
* Remove unecessary helper function, only attach dangling comments when no params.
* Reset flow tests, no more regression.
* Add handleTemplateLiteralComment helper function.
* Fix handleTemplateLiteralComment function.
* Extend handleTemplateLiteralComment to deal with trailing comments 🚀.
* Add test.
* Make handle comments function naming more consistent, fix merge conflicts.
* Update tests.
* Add better comment injection in Template Literal.
* Pass options to attach function.
* Update tests to match new implementation.
* Fix let -> var in findExpressionIndexForComment for NodeJS v4.
* Reorder after merge conflicts.
* Drop old tests for dangling arrays.
* Replace redundant conditional by a boolean 🚀.
* Refactor implementation.
* Add handleAssignmentPatternComments helper function.
* Add new tests 🎉.
* Remove unecessary arg in function.
* Reorder it.
* Experimental fix for key comments in the printComments function.
* Pull master and switch to @vjeux implementation.
* Fix bad rebase.
* Add additional checking for enclosingNode in handleObjectProperty function.
There is an off by one error which made the algorithm not work all the time. In many cases, it actually is the opposite, so whenever you save, it adds/removes that line. I noticed it during the --debug-check run on our codebase but didn't investigate.
Fixes#723