Commit Graph

281 Commits (a7793a66eec0d1257e09acc3b009b79b3938fe53)

Author SHA1 Message Date
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
Christopher Chedeau 74bc9e7a4d Add newline for empty blocks {} (#205)
I find it weird to put `{}` together. So I figured I would change it to have an empty line and ask for feedback :)

![image](https://cloud.githubusercontent.com/assets/197597/21739279/062adc80-d44c-11e6-8bb7-5e0768f3ddde.png)

Beware: most of the test cases are not representative of real code, you almost never define blocks with no content in practice.
2017-01-16 11:31:32 -05:00
Christopher Chedeau c9af5a6c3b Escape strings using jsesc (#229)
The current implementation with `JSON.stringify()` is clever but unfortunately generates incorrect JavaScript. Using `jsesc` seems like a better and safer option. https://github.com/mathiasbynens/jsesc It doesn't have any dependencies and is pretty small.

I opted for escaping all the non ascii characters, so we don't display emojis anymore. I don't think that the world is ready yet for having random unicode characters inside of source files, there still are so many parts of the toolchain that breaks with them. If we want to revert back on this decision, there's a `minimal` option on jsesc which only escapes values that need to in order to generate valid JavaScript file (assuming the encoding of the file is set to utf8).

Also, while working on React Native, we've seen that there is an optimization inside of jsc for js files that are all ascii: it doesn't do a copy for the conversion to ucs16.

Fixes #163
2017-01-16 11:03:59 -05:00
Brian Ng b1138bdfd9 Fix parens issue with nested UrnaryExpressions (#237)
* Fix parens issue with nested UrnaryExpressions

* special case + and -
2017-01-16 07:51:16 -08:00
James Long 2ff1ba8494 Consolidate badges in readme 2017-01-16 10:08:06 -05:00
Henry Zhu 4343488c83 Add npm version badge (#240) 2017-01-16 10:06:47 -05:00
Brian Ng 470f80c17a Fix issue with ArrowFunctionExpression parens (#236) 2017-01-15 22:42:42 -08:00
Brian Ng 340a39b414 Fix cases of missing parens with NewExpression (#230) 2017-01-15 23:56:40 -05:00
Christopher Chedeau 0e1afd6312 Fix empty exports (#225)
```js
export {};
```

was printed as

```js
export
```

which is invalid.

This was discovered by #223
2017-01-15 23:53:41 -05:00
Christopher Chedeau 05be0eb31b Add flow parser experimental options (#221)
The Nuclide codebase uses features that are still proposals which require a flag to be enabled. Babylon parses them fine without any flags.

Let's enable them by default as it doesn't cost much, you either are using those features and you don't want the parser to break, or you are not and you don't care.

After this and #218, none of the nuclide files are throwing exceptions! (yay!)
2017-01-15 23:46:27 -05:00