* d3 counts as a constructor
* adds test
* Tweak wording
* docs: fix linting
* updates test
* no $ special case
* renames function
* shorter function name
* removes trailing white space
This was only accounting for a single element in the first group. Now it handles arbitrary elements. Only the last element being capitalized matters.
This fixes one issue in #3107
* fix: support sequential CallExpressions in member chains
fixes#2832
* test: add additional test cases for sequential CallExpressions
* test: regenerate method-chain snapshot
Fixes#2775.
This commit will make conditional expressions to match the behavior of
logical expression in method chains:
```js
(a ? b : c).map()
// if the conditional fits in oneline
(a ? b : c)
.map()
// if the conditional doesn't fit
(a
? b
: c)
.map()
```
It turns out that leading comment is attached to the CallExpression which is the last one and not the first one if they fit in a single line, so we want to not check that one.
Fixes#1892
I kept adding places where comments could be but more use cases kept creeping in. So now this is a holistical approach, we check all the comments that can be between two nodes. This way we should be good to go :)
I've tried a lot of places where to fix this and this is the only one that gives correct results. This is likely not exhaustive but works for that use case. It's been reported twice in issues and I've seen it happen a few other times so we probably want to get it fixed.
Fixes#922Fixes#797
* 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.
We already had a special case for it for a group of 2 elements but now that we are also going in this codepath for 3 if we merge, then we need to do the same here.
Fixes#930
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
* Implement new logic for wrapping binary op in arrowFunctionExpression.
* Add new test cases.
* Reuse new helper function in order to fix#917.
* Add new test case.
* Extend heuristic to dive deeper into mixed types.
* Add new test.
* Enhance logic to cover more cases.
* Add new test cases.
* Disable Flow as it gets BindExpression as an unexpected token.
* Simplify getCombinedDeepest function.
* Add missing case.
* Extract all conditions in switch cases to one top level condition.
* Refactor implementation to make it cleaner and also handle ExpressionStatement.
* Update related test cases.
* Add new test case.
* Make condition less expensive.
* Clean up unecessary conditions, simplify condition involving startsWithOpenCurlyBrace.
* Update and add new test cases for better coverage.
* Remove unecessary condition, refactor canBeFirstInStatement to drop some useless parens.
* Update test cases accordingly 🚀.
I'm not really sure what a general rule is for those, but starting with LogicalExpressions should be good. Outside of identifiers, function calls and logical expressions, there aren't a lot of things you'd put there in real code anyway.
Fixes#822
Printing a merged group indented was actually not the right fix. The right fix was to print them in a single line. It used to have this behavior when I was mutating the first group but now that I don't anymore I need to reproduce this condition.
Fixes#823
In addition to Observable, $ or _, we should also add `this` to the list of things that are likely factory and not objects you want to apply things on directly.
I added a way to make the function call break on its own line when it doesn't fit in one line and indent. But I think that only having the indentation is enough, having the call on its own line feels weird.
Fixes#777
When there is a comment right before the first `.`, we want to force break such that the comment is printed on its own line.
Note: this needs to be based on-top of #667 as it always indent the first `.`
Fixes#613
Before, we would always concatenate the first `.call()` if the identifier started with a capital letter, but we do want to break if the content of the call doesn't fit in one line.
Fixes#639
There are currently three issues related to suboptimal rendering of MemberExpression chains. The previous implementation was trying to flatten only a single group at the same time, but it didn't work well because we didn't have the full context to be able to make decisions.
In this implementation, I'm going through the entire chain at the same time and group it into logical units and make decisions based on this. It solves all the problems I can think of and if we need to tweak it in the future, it should be easy.
Fixes#268Fixes#212Fixes#21
* new_tests
* move_all_clobbered_tests
* remove all the tests that no longer exist
* re-run flow tests
* Move all the flow tests to tests/flow and prettier to tests/
* Move prettier tests to their own folders
* Add jsfmt files
* run prettier snapshot tests