Commit Graph

3090 Commits (7829caa8189217321fb55d20a517ca33b7331451)

Author SHA1 Message Date
Christopher Chedeau ad96fce6c2 Split pp.js into doc-{printer,builders,utils}.js (#334)
- doc-printer.js is now the direct implementation of the Wadler paper
- doc-builders.js are a lot of utils to generate the IR the above file needs
- doc-utils.js are small utils to traverse list of docs.
2017-01-19 12:46:57 -08:00
Christopher Chedeau ab046c6850 Remove Printer module in favor of single function (#333)
I pushed the options handling and doc->string process one level above.
2017-01-19 12:43:10 -08:00
James Long 6e57b7f2dd Print dangling comments in blocks (#331) 2017-01-19 14:46:37 -05:00
Christopher Chedeau 28e886aea1 Add tests for comments (#330)
This adds a snapshot test for all of the weird things I've seen happening with comments.
2017-01-19 14:28:40 -05:00
Christopher Chedeau 340da019d3 Add quotes around unicode keys in flow parser (#328)
There's a bug in the flow parser with keys using literal that contain unicode characters. Let's quote them for now.

Fixes #327
2017-01-19 12:37:24 -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 ed0023012d Properly escape JSXText (#329)
It's annoying that there's a bug inside of the flow parser, I raised it internally. While this is getting fixed, we can workaround it. This now makes babylon properly escape JSXText.
2017-01-19 11:30:35 -05:00
Jon LaBelle bb9d288dbb Add canonical link to Prettier SublimeText package. (#318) 2017-01-19 10:17:23 -05:00
Christopher Chedeau a6ec181566 Fix crash for single rest on class declaration (#315)
I thought I didn't need to check the length but forgot that the rest argument is not in the list for class declaration. Now it doesn't crash anymore and there's a test...
2017-01-19 10:01:31 -05:00
Christopher Chedeau a7793a66ee Add description to package.json (#320)
Fixes #319
2017-01-19 10:00:45 -05:00
James Long 9939ca7318 Tweak 0.0.0 changelog link to use version tags 2017-01-18 20:51:24 -05:00
Christopher Chedeau 0f54791582 Run prettier through the codebase (#316)
It's a good idea to run it right after we do a release when the number of outstanding pull requests is low :)
2017-01-18 15:31:46 -08:00
Christopher Chedeau b065eaa582 Update docs to 0.0.9 (#309) 2017-01-18 14:26:22 -08:00
Christopher Chedeau e4b5aaade2 Fix docs (#307)
It doesn't compile cleanly anymore:
- esutils checks for Buffer.isBuffer without ensuring that Buffer exists.
- for version, we require a json file, need a rollup extension for that.

I no longer hardcode the version number.

Note: we need to merge this pull request after we have done the release so that the version number is correct and need to rebuild the minified version in a subsequent commit.
2017-01-18 14:24:42 -08:00
Christopher Chedeau 10ff6ead26 v0.0.9 (#308) 2017-01-18 14:23:39 -08:00
James Long a7405257ac Print binary and logical expressions in a nicer format (#262)
* Print binary and logical expressions in a nicer format (fixes #89)

* Improve algorithm (wip)

* Change grouping

* Final (hopefully?) pass at binary/logical expressions

* Update snapshots

* Add tests
2017-01-18 17:01:17 -05:00
Alex Rattray 52a44610be [JSX] Split elements on newlines and preserve whitespace (w/@yamafaktory) (#234) 2017-01-18 16:25:20 -05:00
Christopher Chedeau 6146e064b2 Add --run-in-band to travis (#306)
Hopefully it'll fix spurious errors.
2017-01-18 16:22:04 -05:00
Jeffrey Horn 40973641a3 add version flag (#294)
* add version flag

* set version on the api
2017-01-18 15:45:44 -05:00
Christopher Chedeau f79e838095 Fix trailing whitespace (#300)
In the printer, remove trailing whitespace except for template literals

Fixes #222
2017-01-18 15:38:33 -05:00
Joe Fiorini 38c8d8cd0f Remove unused variable (#304) 2017-01-18 12:37:20 -08:00
Michał Pierzchała 5199144878 Fix bracketSpacing typo in tests (#299) 2017-01-18 12:22:12 -08:00
Christopher Chedeau 4c1a7b1082 Introduce second argument to ifBreak (#302) 2017-01-18 15:13:50 -05:00
Brian Ng 87b0ed3042 Fix parens around anonymous functions (#297) 2017-01-18 11:12:57 -08:00
Brian Ng c02bd6a8d5 Handle additional export default parens cases (#298) 2017-01-18 11:11:52 -08:00
Rafael Hengles 870dbd0003 Use js native String.repeat() (#293) 2017-01-18 13:33:26 -05:00
Christopher Chedeau fadbbeb4ea Use exact versions in package.json (#291) 2017-01-18 12:48:04 -05:00
Christopher Chedeau a8eb09553a Do not output trailing commas with rest arguments (#283)
It turns out that this is not valid by the spec!
2017-01-18 12:42:20 -05:00
Joe Fiorini c2d1b49b62 Allow customizing args sent to prettier-command (#289)
We require single quotes in our eslint config, which conflicts with prettier's default rules. Now the `prettier-args` custom variable allows anyone to set the arguments passed to the prettier command when it runs.

Might be nice to eventually build this up out of individual customization options (ie. `(setq prettier-single-quote t)`), but this is a pretty simple approach that works for now.
2017-01-18 12:36:59 -05:00
Christopher Chedeau 60af75b37b Update flow-parser to 0.38 (#290) 2017-01-18 12:35:42 -05:00
Christopher Chedeau a123e31e82 Workaround flow parser bug with spread in arrays (#285)
The current output of

```js
[...a, ...b]
```

is

```js
[...a, , ...b]
```

because flow parses it as

```
ArrayExpression(SpreadExpression, null, SpreadExpression)
```

This is a bug in the flow parser. Until it gets fixed, we can workaround it by deleting the `null` after a `SpreadExpression`.
2017-01-18 12:14:14 -05:00
Brian Ng 083876e66d Fix missing semi when default exporting CallExpression (#287) 2017-01-18 09:03:31 -08:00
Brian Ng b94b86331f Ensure parens on NewExpression with function callee (#282) 2017-01-17 19:45:56 -08:00
James Long 8229355508 Fix path when printing member chains so parens work properly (fixes #243) (#281) 2017-01-17 22:39:47 -05:00
Christopher Chedeau 789a3029f4 Remove +1 from newline detection (#261)
* Remove +1 from newline detection

All the changes are related to spurious `;`. Sometimes the logic is more correct, sometimes less. Since `;` are going to be removed after the first save, I don't think it matters that much.

* Handle inconsistent `end` node locations when looking for newlines
2017-01-17 22:33:55 -05:00
Benjamin Tan bc9b1fde19 Add newline after shebang if necessary. (#215) 2017-01-17 17:16:40 -05:00
Christopher Chedeau 92795a0fda Fix space missing before `,` on import with bracket spacing off (#279)
Same fix as #278. We use the same (wrong) pattern in both places
2017-01-17 17:12:56 -05:00
Christopher Chedeau b580a18f30 Fix space missing before `,` on export with bracket spacing off (#278)
I copy and pasted the code for arrays which doesn't have this problem. Would be nice to come up with an abstraction for a list of stuff separated by commas. It happens a lot of time and right now it's duplicated everywhere.

Fixes #255
2017-01-17 17:12:42 -05:00
Sorin Muntean 2dac27f777 Allow specifying the major mode that `defun-before-save` will use. (#276) 2017-01-17 17:10:47 -05:00
Christopher Chedeau b7455951e7 Workaround flow bug parsing astral unicode characters (#277)
According to @mroch, "Flow is using CESU-8, not UTF-8. http://www.unicode.org/reports/tr26/ ". While this is being fixed in flow, we can easily work around it inside of prettier. The downside of this approach is that we can't convert those strings to single or double quotes anymore.
2017-01-17 16:47:20 -05:00
James Long 6f2b01193f Update live editor to 0.0.8 2017-01-17 11:00:02 -05:00
James Long dd156c28b2 Update changelog for 0.0.8 2017-01-17 10:37:06 -05:00
James Long bc5392c2a6 v0.0.8 2017-01-17 10:31:47 -05:00
Christopher Chedeau 0192d58bc5 Preserve the way numbers were written (#257)
The goal of the pretty printer is to make sure that the indentation is correct, not to dictate how numbers should be written :)
2017-01-16 23:01:51 -05:00
Brian Ng f0d2ad4508 Fix parens for functions inside TaggedTemplateExpression (#259) 2017-01-16 19:47:13 -08:00
Christopher Chedeau f603ca4688 Make sure empty for loops generate valid code (#224)
```js
for (;;);
function f() {}
```

The `;` was dropped meaning that the line right after was executed within the for loop which is not correct.

I tried to return `;` but it looks like

```js
for (;;)
  ;
```

which looks super weird so I ended up printing `{}` which looks like

```js
for (;;) {}
```
2017-01-16 12:54:39 -05:00
Christopher Chedeau 65a2a150b5 Fix last element of an array being null (#232)
This appears in so many of the test262.
2017-01-16 12:53:39 -05:00
Brian Ng d9ea466cd3 Fix FunctionExpression parens issues (#250) 2017-01-16 12:52:55 -05:00
Brian Ng 86c65d1f81 Fix missing parenthesis for typeof and arrow functions (#249) 2017-01-16 09:08:46 -08:00
Brian Ng 1c8414e894 Fix empty export with from clause (#248) 2017-01-16 08:58:23 -08:00