Commit Graph

598 Commits (02639da9a9a31133ae85b047d565c00fe16fc052)

Author SHA1 Message Date
Lucas Azzola 02639da9a9 Improve coverage and remove some dead code (#2504)
* Improve test coverage

* Clean up some un-used code

* Lower patch requirements on codecov
2017-07-17 23:31:42 +10:00
Lucas Azzola d62d1c5c56 Preserve parens with keyof, enforce parens with arrows with type params (#2503)
* Force parens around argument of simple arrow function if type annotation is present

* Preserve parens inside keyof operator
2017-07-17 13:32:33 +02:00
Lucas Azzola 71b2004391 Cleanup unused nodes, and turn on importMeta babylon plugin (#2498)
* Cleanup unused AST nodes

* Add tests for JSXNamespacedName

* Turn on importMeta babylon plugin

* Add tests for DeclareTypeAlias

* Add back TS*Keyword nodes, fix TS optional destructuring
2017-07-16 23:59:49 +10:00
Lucas Azzola b7fa01af17 Enable code coverage in CI (#2497)
* Enable code coverage in CI

* Disable codecov comment

* Ignore some statements from coverage reports
2017-07-16 21:49:37 +10:00
Lucas Azzola 188c466cd5 Don't call shouldHugType for function arguments, fixes #2458 (#2496) 2017-07-16 11:53:01 +02:00
Lucas Azzola 028d9e0ea7 Improve bind expression formatting (#2493)
* Improve bind expression formatting, fixes #1400

* Fix parenthesis with bind expressions, fixes #1446
2017-07-16 11:47:06 +02:00
Lucas Azzola b9b3da6ee9 Implement prettier-ignore inside JSX (#2487)
* Implement prettier-ignore inside JSX, closes #2467

* Re-enable babylon and typescript verification
2017-07-15 20:21:43 +10:00
Stephen Scott 3ed2bae1b4 Improve JSX ternary formatting
* Now JSX-mode ternaries only break if they need to. 
* Only the outermost ternary in a chain of JSX-mode ternaries will become a group.
* We don't wrap null in parens when breaking JSX-mode ternaries.

This commit also improves the test coverage and explanation in tests/jsx/conditional-expression.js.
2017-07-13 10:21:58 -06:00
Stephen Scott 757037948a Improve JSX Formatting
* Arrow Function Expressions returning JSX will now add parens when the JSX breaks
* Conditional expressions within (or containing) JSX are formatted in a more natural way (for JSX), especiall when chained
* JSX in logical expressions (|| or &&) is always wrapped in parens

Fixes #2208
2017-07-13 10:20:42 -06:00
John Backus 1691b85322 Fix <this.Component /> (#2472)
This is a workaround while waiting on
https://github.com/eslint/typescript-eslint-parser/issues/337.

Fixes #2471
2017-07-13 17:21:46 +10:00
Karl O'Keeffe 5e76ea7bdd Allow single expressions in JSX to be inline 2017-07-10 20:02:30 +01:00
Lucas Azzola b25935d7a3 TypeScript: allow type assertions to hug (#2439)
* TypeScript: allow type assertions to hug, fixes #2437

* Update snapshots
2017-07-10 22:37:43 +10:00
Simen Bekkhus 1b4846b67d Format prettier with newer prettier (#2431) 2017-07-08 14:07:39 +02:00
Lucas Azzola 7e96e01fba Add more supervisory parens, closes #187 (#2423) 2017-07-07 15:57:17 +02:00
Dan Wang 86c88ff278 Print TypeParameter even when unary function type (#2406) 2017-07-06 19:13:30 +10:00
Kevin Gibbons f490dba609 switch a use of .map to .each (#2395) 2017-07-05 02:03:18 +02:00
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 6f32a40edd Fix multiparser in website, fixes #2328 (#2374) 2017-07-01 18:14:21 +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
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 073a2071a8 Inline import('x') to avoid having trailing , (#2288)
Fixes #2287
2017-06-27 11:40:20 -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
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 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
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 aac0d1dda0 Support inline template for new calls (#2222)
I merged the implementation of new and call expressions in this PR.

Fixes #2215
2017-06-21 15:45:44 -07:00
Joseph Frazier 63c47c85e0 JSON: Print trailing newline (#2226)
* JSON: Append trailing newline

This partially addresses https://github.com/prettier/prettier/issues/2223

* Dedupe printing of JSON trailiing newline

* JSON: Add tests for newlines after boolean/null/number/string

* JSON: Fix tests for newlines after boolean/null/number/string, simplify code

This fixes https://github.com/prettier/prettier/issues/2223
2017-06-21 15:40:19 -07:00
Karl O'Keeffe 04c41f6758 Fix up empty JSX element detection (#2220) 2017-06-21 13:48:02 -07:00
Lucas Azzola e78e07e2ad refactor(multiparser): move css expression doc printing to transformCssDoc (#2214) 2017-06-21 13:41:24 -07:00
Joseph Frazier 69808cebfb Format JSON literals like object literals (#2181)
* Format JSON literals like object literals

Following up on commit a42db30 (https://github.com/prettier/prettier/issues/2173),
this change makes it so that literals in JSON files are formatted as
they would be in an object literal. This normalizes trailing zeroes,
exponential notation, unnecessarily escaped characters, etc.

It works by using babylon to parse literals as expressions, and putting
the result in the AST instead of a `json-literal` node. Since JSON
string literals have to be double-quoted, there's a new
`__prettier__isJson` flag on each node, which is used by the printer to
force double-quotes.

* json: Check options.parser when formatting StringLiteral

This is instead of having a custom AST property. See
https://github.com/prettier/prettier/pull/2181#discussion_r122578251

* multiparser: Use babylon.parseExpression

See https://github.com/prettier/prettier/pull/2181#discussion_r122578354

* json: Don't split result AST node into two

See https://github.com/prettier/prettier/pull/2181#discussion_r122578499

* json: Don't use babylon parser to build expression nodes

See https://github.com/prettier/prettier/pull/2181#discussion_r122579052

* Revert "multiparser: Use babylon.parseExpression"

This reverts commit 3d7a4362880d39fac0cea88b5d0186a29538cf6f.

* Remove unused parameter from babylon parser

* json: Remove unused constructorTypes
2017-06-17 20:49:22 -04:00
Joseph Frazier a42db30946 Add JSON support (#2173)
* Add JSON support

This fixes https://github.com/prettier/prettier/issues/1973 by using
[json-to-ast] to parse JSON, then converting the AST into a
mostly-Babylon AST, so as to piggyback on the existing printer logic.

Identifiers and literals are currently printed verbatim from the input,
but this could be improved upon later (at least for literals, not sure
about identifiers).

[json-to-ast]: https://github.com/vtrushin/json-to-ast

* Rename `json-to-ast` parser to `json`

See https://github.com/prettier/prettier/pull/2173#discussion_r122574644

* json: Use createError to have a pretty error

See https://github.com/prettier/prettier/pull/2173#discussion_r122574748

* json: Transform AST without mutations

See https://github.com/prettier/prettier/pull/2173#discussion_r122574690
2017-06-17 10:36:42 -10:00
Lucas Azzola c669a1db72 TypeScript: group function params in call/construct signatures, fixes #2163 (#2169) 2017-06-17 12:09:18 +10:00
Stephen Wan a005211c96 Fix extra semicolon in ambient typescript declaration emit (#2165) (#2167)
* fix(typescript): add failing ambient declaration test

* fix(typescript): fix failing test case for ambient function exports
2017-06-16 08:20:59 -10:00
Lucas Azzola 7e60d70f97 fix(typescript): always break interfaces onto multiple lines, fixes #2159 (#2161) 2017-06-15 14:34:54 -10:00
Lucas Azzola 9e7b02d50e Print {} in import if it's in the source, fixes #2145 (#2150) 2017-06-15 20:19:01 +10:00
Lucas Azzola b7e1c366e0 Vue: pretty-print binding syntax (#2108)
* feat(vue): pretty-print :class attributes

* feat(vue): switch to brand new custom parser API! 🎉

* refactor(vue): move AST manipulation to post-parse
2017-06-14 22:33:15 +10:00
Christopher Chedeau abfdbe1896 Upgrade typescript to 2.4 (#2120)
Fixes #2117
2017-06-13 09:47:40 -07:00
Rodrigo Pombo 8dd0cb2a05 Format CSS in template literals with expressions (#2102)
* Add support for styled-jsx with expressions

* Lint

* Fix require for Node 4

* Re-create template-literal document when replacing placeholders

* Add support for styled-components with expressions

* Fix merge

* Move css library detection to functions
2017-06-13 09:45:16 -07:00
Lucas Azzola fbf9064090 refactor(multiparser): move some logic from printer.js to multiparser.js (#2109) 2017-06-12 08:06:41 -07:00
Lucas Azzola 486a89bfdc fix(typescript): workaround - don't wrap directives in parens, fixes #2074 (#2107) 2017-06-11 19:10:56 -07:00
Lucas Azzola e8f12cf621 TypeScript: Remove parens from type annotations where possible (#2098)
* fix(typescript): remove parens from union types where possible, fixes #1885

* fix(typescript): ensure parenthesis removal is stable

* fix(typescript): don't strip parens around function type
2017-06-11 18:06:47 -07:00
Lucas Azzola 9c608d2ec1 fix(typescript): use printFunctionParams for call/construct signature, fixes #2105 (#2106) 2017-06-11 16:06:38 -07:00
Lucas Azzola ec7d99439d fix(typescript): print arrow function type params on same line as params, fixes #2099 (#2101) 2017-06-11 07:30:51 -07:00