Commit Graph

773 Commits (28b3a4b925a2b8c012a9909d86f97289dd2740a1)

Author SHA1 Message Date
Kevin Gibbons 28b3a4b925 Break sequence expressions (#2388)
* Add SequenceExpression tests

* Clean up printing of SequenceExpressions

* Remove test and lint
2017-07-04 22:50:57 +02:00
Karl O'Keeffe 06ae32ddce Ensure there is a line break after leading JSX white space (#2348) 2017-07-03 12:43:10 +02:00
Lucas Azzola 6f9824778d Strip BOM before parsing, fixes #2362 (#2373) 2017-07-01 18:11:13 +02:00
Jarda Snajdr 3f6a232cea Fix indentation of a do-while condition (#2359)
Fixes #2353. Use the same printing code for both `WhileStatement` and `DoWhileStatement`.
Fix calculation of `isInsideParenthesis` when printing a `LogicalExpression`. There is
no such thing as `DoStatement` -- it should be `DoWhileStatement`.
2017-06-29 15:46:25 -07:00
Simone Picciani 85e0bffa7d Removed injectGlobal and keyframes (#2342) 2017-06-28 16:03:33 -07:00
Simone Picciani 067a0137bd Add support for css, keyframes and injectGlobal keywords (#2337)
* styled components now support css keyword

* added support also for keyframes

* added comment to reflect the new keywords

* modified comment

* ignore css and keyframes when testing ast manipulations

* added also injectGlobal
2017-06-28 14:31:27 -07:00
Joseph Frazier 175cde1dc5 Force trailingComma option to "none" when parser is JSON (#2335)
* Run JSON tests with `trailingComma: "all"`

* Add test of `parser: 'json', trailingComma: 'all'` with non-.json extension

See https://github.com/prettier/prettier/issues/2308#issuecomment-311707801

* Force trailingComma option to "none" when parser is JSON

This fixes https://github.com/prettier/prettier/issues/2308
2017-06-28 09:29:47 -07:00
Joseph Frazier 8e37fd76e9 Add support for range-formatting GraphQL (#2319)
* Add test for range-formatting GraphQL

See https://github.com/prettier/prettier/issues/2296#issue-238985580

* Pass test for range-formatting GraphQL

See https://facebook.github.io/graphql/#sec-Appendix-Grammar-Summary.Query-Document

This fixes https://github.com/prettier/prettier/issues/2296

* Consider *Definition GraphQL nodes to be formattable

See https://github.com/prettier/prettier/pull/2319#discussion_r124569400
2017-06-28 09:21:11 -07:00
Lucas Azzola 678964b8de fix(typescript): don't add namespace keyword to global declaration, fixes #2327 (#2329) 2017-06-28 07:53:10 -07:00
Christopher Chedeau b231948a36 GraphQL: Print directives for field declarations (#2317) 2017-06-27 20:22:03 -07:00
Christopher Chedeau 45c8e40d8a GraphQL: Implement schema (#2316) 2017-06-27 20:15:55 -07:00
Christopher Chedeau 019beb54e5 GraphQL: Fix directives separator (#2315)
I couldn't figure out what the separator was, I tried `,`, `on` but none of them worked. Turns out it is `|`!
2017-06-27 19:58:38 -07:00
Christopher Chedeau 14caabd635 GraphQL: Print arguments for FieldDefinition (#2314) 2017-06-27 19:49:59 -07:00
Christopher Chedeau bbf8f76823 GraphQL: Implement scalar (#2313) 2017-06-27 19:34:25 -07:00
Christopher Chedeau 0a2a099efe GraphQL: Implement interface (#2312) 2017-06-27 19:30:58 -07:00
Christopher Chedeau 8e31088761 GraphQL: Implement input (#2311) 2017-06-27 19:27:02 -07:00
Christopher Chedeau b63e1c2dd7 GraphQL: Implement Enum (#2310) 2017-06-27 19:20:53 -07:00
Christopher Chedeau 51c7503dae GraphQL: Implement DirectiveDefinition (#2309) 2017-06-27 19:10:07 -07:00
Christopher Chedeau fbf4c3a952 GraphQL: Support object definition implements (#2307) 2017-06-27 18:51:56 -07:00
Christopher Chedeau ee07ff5870 Fix master 2017-06-27 18:33:23 -07:00
Christopher Chedeau af309e3acd Add support for GraphQL TypeExtensionDefinition (#2306) 2017-06-27 18:26:43 -07:00
Christopher Chedeau f96fe1ea5e Initial support for GraphQL ObjectTypeDefinition (#2305)
It appears in some files inside of fb codebase
2017-06-27 18:22:04 -07:00
Christopher Chedeau 189027c7d3 GraphQL: Use spaces instead of commas (#2303)
"Daniel Schafer: Yeah, that's definitely what I'd describe as the canonical style; anytime you have two "things" on a line, use commas, but if you have a newline it's not needed."
2017-06-27 18:13:07 -07:00
Christopher Chedeau 4d46a3975b GraphQL: Remove circular dependency in ast (#2304)
The tokens are attached to the location via the prototype (so they are not visible when you JSON.stringify) but the various places where we traverse the ast see them. It causes stack overflows and comments that are not printed because they are attached to tokens instead of real nodes.

Fixes #2302
2017-06-27 18:12:30 -07:00
Christopher Chedeau 850d51a033 Tweak name 2017-06-27 17:30:13 -07:00
Joseph Frazier b47c0b4e04 Allow formatting ranges of JSON (#2298)
* Add test for https://github.com/prettier/prettier/issues/2297

* Add JSON types to isSourceElement()

See https://github.com/prettier/prettier/issues/2297

* Avoid expanding format range when possible

This fixes https://github.com/prettier/prettier/issues/2297

* Move JSON range test into tests/range_json

This is so that the AST_COMPARE=1 tests don't try to parse JSON with Flow.

* Check parser in isSourceElement()

Otherwise JSON formatting would format weird things inside of JS.
See https://github.com/prettier/prettier/pull/2298#discussion_r124407056

* Use arrow functions instead of .bind()

See https://github.com/prettier/prettier/pull/2298#discussion_r124409783

* Add test of range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Allow range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Fix lint
2017-06-27 16:04:42 -07:00
Joseph Frazier 5f063ab168 Fix locEnd() for postcss parser (#2295)
* Fix locEnd() for postcss parser

`node.source` doesn't have an `end`, but `node.nodes[-1].source` does.

Fixes https://github.com/prettier/prettier/issues/2267

* Add regression test for https://github.com/prettier/prettier/issues/2267

See https://github.com/prettier/prettier/pull/2295#issuecomment-311484343

* Make locEnd() postcss fix more focused

This passes the tests again.

* Use getLast() instead of .slice()

See https://github.com/prettier/prettier/pull/2295#discussion_r124398553

* Move CSS range test into tests/range_css

This is so that the AST_COMPARE=1 tests don't try to parse CSS with Flow.
2017-06-27 15:12:22 -07:00
Christopher Chedeau 6f4eade422 Go back to babylon beta 13 (#2289)
Fixes #2286
2017-06-27 11:51:23 -07:00
Christopher Chedeau 073a2071a8 Inline import('x') to avoid having trailing , (#2288)
Fixes #2287
2017-06-27 11:40:20 -07:00
Christopher Chedeau 803b7ff6b9 Add \n at the end of .graphql files (#2285)
We need to use the same hack as CSS unfortunately.

Fixes #2275
2017-06-27 09:49:15 -07:00
Christopher Chedeau e707bdd52f Print comments attached to {' '} (#2283)
We had two occurrences on fb codebase where people attached comments on `{' '}` which would be swallowed. Instead of dropping the comments, let's make the algorithm a bit less naive.
2017-06-27 09:35:03 -07:00
Karl O'Keeffe be600337eb Improve JSX output when there is a single expression (#2274) 2017-06-26 19:05:34 -07:00
Karl O'Keeffe 95a5f11be9 Tweak to support FB translation pipeline (#2272)
This also improves formatting when there are consecutive tag/expression elements with no white space between them.
2017-06-26 09:30:52 -07:00
Karl O'Keeffe fe7fb260a4 Fix a case where significant whitespace was dropped (#2270) 2017-06-26 03:03:13 -07:00
Cyril Junod 400f34624f Add module, class and typed nodes to sourceElements (#2266)
babylon flow typescript parsers

+ tests to cover module and class
2017-06-25 09:07:52 -07:00
Christopher Chedeau 9a55f5b2d6 Fix unstable arrow comments (#2262)
It outputted which is completely wrong

```js
<FlatList
  renderItem={info => <span>{info.item.widget.missingProp // $FlowExpectedError - bad widgetCount type 6, should be Object
    }</span>}
/>;
```
2017-06-25 12:30:09 +10:00
Christopher Chedeau f71fcd0b65 Fix variance location (#2261)
Turns out when we refactored for TS, we moved it before "static" and it no longer parses. Oops.
2017-06-25 11:46:29 +10:00
Christopher Chedeau 38d4661ba9 Forward originalText in multiparser (#2260)
If we don't, all the places where we read from the original text (mostly comments) are reading into random places.

Fixes #2258
2017-06-24 17:54:09 -07:00
Christopher Chedeau 8def8e13b0 Add caching for printing (#2259)
* Add caching for printing

For printing the last argument expansion, we need to print the same node a bit differently with a flag. It's not easy to re-print just the node that is different so we end up printing all the sub-tree twice. Since it is often nested, it means that we run into an exponential complexity.

I finally found a simple solution: we can use a Map to store the nodes and their printed values. It is really cheap to do so (I can't notice a time difference with or without on normal code) and allows us to stop going through the two sub-trees in the bad case.

Fixes #1250

* Update printer.js
2017-06-24 14:01:02 -07:00
Christopher Chedeau 6663bab8a3 Support trailing commas for function calls (#2257) 2017-06-24 12:23:34 -07:00
Christopher Chedeau cc85769231 Add support for --trailing-comma for GraphQL (#2254)
Fixes #2251
2017-06-24 11:20:45 -07:00
Christopher Chedeau 59b3a9bc56 Add support for --no-bracket-spacing for GraphQL (#2255)
Fixes #2252
2017-06-24 11:06:56 -07:00
Christopher Chedeau 2f96357884 Attach comments in multiparser (#2253)
Otherwise it doesn't print comments :(
2017-06-24 11:06:50 -07:00
Joseph Frazier 4b955a14c4 Return original input when specified range is unformattable (#2250)
* Add failing test for range-formatting whitespace

See https://github.com/prettier/prettier/issues/2247#issue-238322065

* Return original input when specified range is unformattable

Fixes https://github.com/prettier/prettier/issues/2247
2017-06-24 09:41:10 -07:00
Cyril Junod b0413fc1fe Range Formatter: Remove Program/File from valid Ancestor (#2248)
* Remove Program/File from valid Ancestor

Fix edge range formatting entire file.

* Fix lint with `yarn lint -- --fix`

See https://travis-ci.org/prettier/prettier/jobs/246569943#L242-L260
2017-06-24 12:30:27 -04:00
Lucas Azzola 3474056b36 fix(typescript): handle ObjectPattern instead of ObjectExpression inside BinaryExpression, fixes #2237 (#2238) 2017-06-23 07:53:42 -07:00
Karl O'Keeffe 0cc0ebc3bc Allow JSX lines to be recombined (#1831)
* 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
2017-06-22 09:19:44 -07:00
Christopher Chedeau 39954f7951 Handle conditions inside of a ternary (#2228)
Fixes #2122
2017-06-21 18:17:30 -07:00
Christopher Chedeau ec1b672bbf Don't indent + in object value (#2227)
This is a "regression" from when we started using the same heuristic for `=` and `:`

Fixes #2129
2017-06-21 15:58:12 -07:00
Christopher Chedeau c36dd48339 First try scss when there's an @import with comma (#2225)
It's annoying that the less parser is so lenient that it drops things instead of throwing :(

Fixes #2125
2017-06-21 15:45:55 -07:00