Commit Graph

49 Commits (master)

Author SHA1 Message Date
Zhongliang Wang 2cfd8fb518 Support TypeScript 3.7 (and drop Node 6 support for direct inst… (#6657)
* WIP: Support TypeScript 3.7

* Add support for `asserts` keyword; Update snapshots

* Update typescript-estree to v2.5.0 to remove the dependency on chokidar

* Update TypeScript

* Update CHANGELOG.unreleased.md

* Add examples for TypeScript 3.7

* Update TypeScript 3.7 to latest dev version

* Correct wording

* Support `declare` keyword on class members (TypeScript 3.7 feature)

* Update Changelog and downgrade TypeScript from 3.8.0-dev to 3.7.1-rc

* Add a note regarding to dropping Node 6 support for direct installation

* tweak build config to repair build

* update CHANGELOG.unreleased.md

* TSTypePredicate microrefactoring

* fix formatting

* clean up tests

* fix parens for optional chaining inside computed properties

* update CHANGELOG.unreleased.md

* unify output across parsers for template literals

* enable more tests with optional chaining

* fix unneeded parens inside computed key of OptionalMemberExpression

* fix paren issues for OptionalCallExpression

* more fixes for OptionalCallExpression

* @typescript-eslint/typescript-estree 2.5.1-alpha.4

* fix lint

* revert build hacks

* fix one more parens issue

* @typescript-eslint/typescript-estree 2.5.1-alpha.5, remove loggerFn override

* drop node 6 for direct installing from github

* fix another parens issue, disable some tests for flow

* workaround for flow bug

* fix issues with comments


Co-authored-by: Georgii Dolzhykov <thorn.mailbox@gmail.com>
2019-10-28 17:53:57 +01:00
Lucas Duailibe eca23e111f
Stop converting empty JSX elements to self-closing elements (#6127)
Co-Authored-By: Simon Lydell <simon.lydell@gmail.com>
2019-05-16 15:14:35 -03:00
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
Ika 952bc0cc03
fix: get rid of CRLF (#5494) 2018-12-08 18:28:29 +08:00
Ika 4af3dd4b07
test: improve snapshots (#5521)
- before
  ```
  ${input}${"~".repeat(printWidth)}
  ${output}
  ```
- after
  ```
  ===options===
  ${options}
  ${" ".repeat(printWidth)}| printWidth
  ====input====
  ${input}
  ===output====
  ${output}
  =============
  ```
2018-11-25 16:21:14 +08:00
Ika 40f46740f6
fix(jsx): consistent quotes in JSX expression (#5349) 2018-11-06 15:38:50 +08:00
Ika b6691ba615
fix(javascript): no regression for jsx in arrow function in jsx (#5343) 2018-11-06 15:38:30 +08:00
Stefan Mirea e17512adcd Add an option to print single quotes in JSX (#4798)
* feat(option-singleQuote-jsx): Added jsSingleQuote

* feat(option-singleQuote-jsx): Refactored to use a simple jsxSingleQuote flag

* feat(option-singleQuote-jsx): Fixed borked rebase

* feat(option-singleQuote-jsx): Updated snapshots

* feat(option-singleQuote-jsx): Resolved pending comments

* feat(option-singleQuote-jsx): Removed assert

* Fixed merge conflicts

* Updated snapshots after merge conflicts
2018-11-04 16:36:00 -05:00
Lucas Duailibe ed6a2d9055
Prevent JSX from breaking a logical expression chain (#5092) 2018-10-10 14:11:37 -03:00
Lucas Duailibe b020a5606f
Keep simple JSXOpeningTag's unbroken (#5078) 2018-09-11 11:15:50 -03:00
Ika 4d488e8b81
fix: no false positive for arrow function in jsx expression (#5063) 2018-09-07 09:39:59 +08:00
Simen Bekkhus 51b7c02e12 Upgrade jest to 22 (#4782)
* chore: upgrade Jest

* chore: update snapshots

* chore: lock down babel dependency using invalid syntax

* 2 args to test.skip

* use jest 22 for now

* Revert "2 args to test.skip"

This reverts commit 691fdc3f99e320f2303958f2b503f7b4c93fa455.

* remove snapshot name from matcher

* fix standalone tests skips
2018-07-03 03:06:29 -03:00
Suchipi cb5e1db4a5
Revert "Ternary Operators in JSX Expression Containers (#4731)" (#4736)
This reverts commit 12046cd01b.
2018-06-22 10:32:38 -06:00
tyrerexus 12046cd01b Ternary Operators in JSX Expression Containers (#4731)
This pull request aims to fix the issue of excessive nesting brought up in the following comment: https://github.com/prettier/prettier/issues/737#issuecomment-392541493

This "fix" is very simple. It adds a new possible way to activate JSX mode for ternary operators. If the first non-conditional parent of the expression is a JSX expression container, then JSX mode gets activated.

This branch also contains a test case for said scenario.
2018-06-22 10:30:53 -06:00
Lucas Duailibe cb1c52ad08
Break JSX in arrow functions in JSX expressions (#4601) 2018-06-08 15:15:50 -03:00
Lucas Duailibe 7f75499dd2 Prevent adding softline after arrow attribute with comments (#3641)
* failing test

* fix
2018-01-03 12:12:01 -08:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Duailibe 1dfffd14e7 Don't inline trailing } for arrow functions in JSX 2017-11-04 01:52:27 -02:00
Lucas Duailibe 21c6d4f501 Prevent inlining JSXAttribute if it has comments (#3132) 2017-11-01 09:56:04 -06:00
Lucas Duailibe 6ccf5c0246 fix(jsx): Don't inline trailing } for arrow functions attributes (#3110) 2017-10-26 11:32:57 -06:00
Lucas Duailibe 2c37697f82 Fix chained logical expressions with objects/array/etc inlined 2017-09-07 21:57:07 -06:00
Lucas Duailibe f964be5f8a Remove unnecessary tests 2017-09-07 21:29:53 -06:00
Lucas Duailibe 541e929b43 Change how JSX mode is activated in ternaries 2017-09-07 21:29:53 -06: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
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 ffc1b3702e Remove parenthesis for JSX inside of arrow functions (#1733)
I didn't intend for putting parenthesis there in the first place but it slept through. Since it was going to trigger a ton of changes I held up changing it, but I feel like we need to do it sooner than later otherwise we're not going to be able to do it. A lot of people writing functional components are going to be very happy about this change :)
2017-05-25 16:26:49 -07:00
Christopher Chedeau 5d3a750b92 Put JSX comments inside of the parenthesis (#1712)
This is very unfortunate that we have to change the generic function that prints code but we want the JSXElement node to handle its comments printing itself in order to write them inside of the parenthesis instead of outside.

Fixes #555
2017-05-24 13:19:47 -07:00
Christopher Chedeau bb232d48a3 Inline chained conditionals inside of jsx attribute (#1519)
Fixes #1515
2017-05-05 21:44:50 -07:00
Christopher Chedeau 3161bd0787 Upgrade flow parser to 0.45 (#1447)
This fixes all the unicode issues and spacing between elements in array.

Fixes #1336
Fixes #1427
Fixes #770
2017-04-27 14:59:18 -07:00
Jan Kassens b82220b20f Prittier printing of snapshots (#1190)
This uses a custom snapshot serializer to reduce escaping in snapshot files and
make them easier to read.

Snapshot serializers are documented here:
https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string
2017-04-12 13:41:51 -07:00
Davy Duperron d1191adce6 Fix ampersand in jsx href and src (#1056)
* Add exceptions for html escape usage in href and src attributes.

* Add new test cases.

* Remove useless spaces.

* Do not escape if the parser does not do so.

* Implement a different heuristic for keeping along with the parser.

* Update tests.

* Forgot passing options as param.

* Experimental alternative implementation.

* Remove other function.

* Push test after merge.

* Update getJsXRawValue in order to return the unprocessed raw value.

Latest Babylon version includes a fix that allow us to directly
inject the unprocessed raw value available in the `extra.rawValue`
property of the node. A last transformation is applied by replacing
double quotes to `&quot;` entities.

* Drop unused htmlEscapeInsideDoubleQuote function.

* Move getJSXRawValue function logic to the its only call, drop it.

A simple check is performed to determine if the parser is babylon or
flow via `n.value.extra`. Thus, the corresponding raw value is
extracted. If we are converting a string from single quotes to
double quotes, we need to make sure that double quotes are converted
to &quot;.

* Remove ambiguous comment.

* Add Babylon parser.

* Update test cases accordingly, revert regression introduced previously.
2017-04-08 07:55:50 -07:00
ChristianHersevoort 04c959d687 Feature/verify against same snapshot (#1087)
* 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
2017-03-25 08:10:17 -07:00
Christopher Chedeau c3199359b0 Revert "Improve snapshot naming" (#1070)
* 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.
2017-03-21 17:38:28 -07:00
ChristianHersevoort 4f7ae4815b Make it clear what parser was used in each snapshot (#1068) 2017-03-21 14:47:23 -07:00
Christopher Chedeau 3a80345e0c re-run snapshot tests 2017-03-15 18:54:34 -07:00
Brian Ng b8a7e5166b Add parens for ConditionalExpression inside JSXSpreadAttribute (#1015) 2017-03-15 18:52:31 -07:00
Christopher Chedeau 9ef8c709bb fix_tests 2017-03-09 08:59:23 -08:00
Brian Ng b8bdb6c243 Inline BinaryExpressions inside JSXExpression (#965) 2017-03-09 07:59:53 -08:00
James Henry 72456bf06f [WIP] TypeScript Parser (#915)
* WIP immediate feedback

* typescript parser is drop-in replacement for flow parser

* Add new TypeScript Parser snapshots where drop-in replacement possible

* Snapshot updates after rebasing

* Remove unnecessary stripping of properties on TypeScript parser AST

* Remove annotated issues

* Move TS dependencies to dev for now
2017-03-08 13:18:13 -08:00
Alex Rattray 50602aecbb [JSX] Break if opening element breaks (#942) 2017-03-07 17:19:05 -08:00
Brian Ng 860a9fd6d4 Ensure no parens for JSX inside of an ArrayExpression (#895) 2017-03-05 08:56:07 -08:00
Alex Rattray 475208d22a [JSX] Don't wrap JSX Elements in parentheses if they are inside JSX Expression Containers (#845) 2017-03-01 12:05:57 -08:00
Rogelio Guzman d45e157563 Upgrade to Jest 19 (#762)
* Upgrade to Jest 19

* Use exact versions for Jest
2017-02-21 13:59:19 -08:00
Davy Duperron 6efad59300 565 jsx parentheses fix (#580)
* Add JSXElement in ShouldPrintSameLine helper function.

* Add tests 🚀.
2017-02-02 16:25:34 -08:00
Alex Rattray 72c9424c53 Indent ternaries (#484) 2017-01-26 11:58:40 -08:00
Christopher Chedeau 573936aacc [RFC] Hug Conditionals in JSX (#473)
Conditionals are very common in JSX and it is unfortunate that they take up so much vertical space in the current prettier.

This pull request does a few tweaks:
 - It hugs ConditionalExpression (ternary) and LogicalExpression (&&) inside of `{}` in a jsx child, not an attribute
 - It doesn't output parenthesis if your parent is a LogicalExpression (&&)

Fixes #317
2017-01-26 14:51:08 -05:00
Christopher Chedeau a4dd760a38 Hug objects and arrays inside of JSXExpressionContainer (#213)
Fixes #197
2017-01-19 12:37:02 -05:00
Christopher Chedeau a6cdede9f6 Always use double quotes for JSX and properly escape
JSX quotes are unfortunately using html escaping. Also, we should disregard the single-quote option for JSX quotes as we always want double quotes.
2017-01-11 11:40:24 -08:00