Commit Graph

20 Commits (master)

Author SHA1 Message Date
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 a4e8aaf7a1
fix(jsx): do not move trailing char to the next line as leading char (#5354) 2018-11-07 07:41:34 +08:00
Yulia Galuzo 0c7c1bfde4 fix: splitting jsx text correctly (#5006)
Fixes: #4941
2018-09-02 19:59:28 +02: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
Karl O'Keeffe 7a3ac3a693
Handle JSX whitespace separately from fbt whitespace (#4717)
* Hande JSX whitespace separately from fbt whitespace

* Extra test cases

* Further tweak to JSX handling

* Possible improvement of single character text

* More tests

* Pull out separator code

* More tests for fbt
2018-06-25 19:11:40 +01:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Duailibe 482c83df20
Don't break self closing elements with no attributes (#3250) 2017-11-13 02:20:17 -02:00
Lucas Duailibe 38b15f7899 Improve template literal expresions line breaks (#3124) 2017-10-31 14:31:27 -06:00
Karl O'Keeffe fa83ce3f3f Fix calculation of whether doc parts fit (#3081) 2017-10-22 07:54:23 +01:00
Karl O'Keeffe e9b82074a6 Collapse multiple JSX whitespaces 2017-10-03 21:15:49 +01: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
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
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
Karl O'Keeffe 73432c2ce7 Position JSX whitespace (`{" "}`) at the end of lines (#1964)
* Position JSX whitespace at the end of lines

Currently we place JSX whitespace at the beginning of lines.

* Use `isLiteral` when determining JSX whitespace
2017-06-05 21:52:54 +01:00
Karl O'Keeffe f4ef1c2c97 JSX whitespace on the same line as text (#1829)
This tweaks our JSX formatting to only put a JSX whitespace `{" "}` on a line by itself when it comes before or after a multiline element.

When preceding a text or single line element it appear on the same line as that element.
2017-05-31 10:16:50 -07:00
Karl O'Keeffe a680cd8534 Fix unstable JSX output by ensuring we follow `fill` rules. (#1827)
* Fix unstable JSX output by ensuring we follow `fill` rules.

This changes makes us more strict about ensuring our JSX children follow the alternating content/whitespace format expected by the `fill` primitive.

Previously there were some cases where could get out of sync which would throw out the formatting.

* Simplify whitespace wrangling

# Conflicts:
#	src/printer.js
2017-05-31 09:42:36 -07:00
Karl O'Keeffe 2512497288 Hug JSX text after multi line tags (#1671)
* Hug JSX text after multi line tags

* Hug text to beginning of tags
2017-05-23 11:56:21 -07:00
Karl O'Keeffe 4083d92ad1 Fix fill wrapping when text starts with whitespace (#1666) 2017-05-22 15:32:57 -07:00
Karl O'Keeffe 5cda955efc New primitive to fill a line with as many doc parts as possible (#1120)
* Add new fill primitive and use it to wrap text in JSX

This adds a new `fill` primitive that can be used to fill lines with as much code as possible before moving to a new line with the same indentation.

It is used here layout JSX children. This gives us nicer wrapping for JSX elements containings lots of text interspersed with tags.

* Quick fix for jsx whitespace regressions

* Fix a couple more bugs

* Tidy up the `fill` algorithm

Attempt to make the algorithm a little more regular, and improve the naming of variables to make it a little easier to understand (I hope!).

* Small tidy up of JSX whitespace declarations

* Remove unnecessary code

It turns out that `children` is only used in the case when the element is printed on a single line, in which case all the types of JSX whitespaces behave the same, so we don't need to special case leading/trailing/solitary whitespace.

* A little more tidy up based on PR feedback

* Fix up tests after rebasing

* Make it explicit that we keep multiple consecutive spaces

* Add an explanatory comment

* Fix broken snapshot in master

* Ignore existing commands when deciding whether content will fit when using fill

* Fix a bug where children would get incorrectly filled onto a line

* Tidy up JSX whitespace names
2017-05-10 16:13:21 -07:00