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 :)

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
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
a4695b16f6
Last argument expansion works for arrow functions that return JSX ( #211 )
...
* Last argument expansion works for arrow functions that return JSX
Fixes #195
* Fixes #130
2017-01-15 00:04:50 -05:00
Christopher Chedeau
b9d2d1aac5
Fix comma when an arrow function with no arguments breaks ( #210 )
...
Fixes #118
2017-01-14 23:55:38 -05:00
Christopher Chedeau
15cc3bb778
Fix key quotes omission for flow parser ( #203 )
...
```js
echo 'var { "key": val } = 1;' | ./bin/prettier.js --stdin --flow-parser
var { key: val } = 1;
```
2017-01-14 23:40:26 -05:00
Christopher Chedeau
fe959631c1
Fix directives printing for empty functions ( #199 )
...
We were not printing the directives if the body of the function was empty in babylon. Also, we were printing way too many \n
```js
echo "function fn() { 'use strict'; }" | ./bin/prettier.js --stdin
function fn() {
"use strict";
}
```
```js
echo "function fn() { 'use strict'; }" | ./bin/prettier.js --stdin --flow-parser
function fn() {
"use strict";
}
```
2017-01-14 23:39:41 -05:00
Benjamin Tan
f70c9ec6d1
Don't break to new line if logical/loop statements are without brackets. ( #194 )
...
Closes #14 .
2017-01-14 23:37:13 -05:00
Benjamin Tan
3f31a87da1
Remove legacy Recast code and simplify API. ( #191 )
2017-01-14 23:25:30 -05:00
Christopher Chedeau
d8c51483fc
Fix DeclareInterface ( #182 )
...
DeclareInterface (flow) and InterfaceDeclaration (babylon) are the same type so should behave the same way. I am using the same `declare` trick where I only add it if you are inside of a `declare module` block.
2017-01-13 23:15:30 -05:00
Christopher Chedeau
3134b1c86c
Make declare type consistent between babylon and flow ( #183 )
...
Flow doesn't have a different ast node for `type` and `declare type`. Let's always use the heuristic to be inside of a `declare module` for both ast. This way more snapshot tests are passing between the two parsers.
2017-01-13 23:14:32 -05:00
James Long
3af7da5748
Reprint all the files!
2017-01-13 15:03:53 -05:00
James Long
6be89286bb
Wrap ForStatement in a block for const decls ( #172 )
2017-01-13 14:57:46 -05:00
Alex Rattray
4fe16bda4d
Multiline JSX opening tag breaks children out too (for #73 )
2017-01-13 14:22:49 -05:00
Alex Rattray
2e1e6eece2
JSX maintains spaces that matter ( fixes #30 and thus part of #73 )
2017-01-13 14:22:49 -05:00
Alex Rattray
b09a02084f
Break JSXOpeningElement between attributes ( fixes #15 )
2017-01-13 14:22:49 -05:00
Alex Rattray
d91a28ef81
Wrap Stateless JSX Arrow Functions and Assignment in Parens (fixes part of #73 )
2017-01-13 14:22:49 -05:00
James Long
31a07feb84
Remove leftover arrowParensAlways option ( #171 )
2017-01-13 14:18:42 -05:00
Christopher Chedeau
958ea215a6
Add trailing comma support for multiline exports ( #168 )
...
```
echo "export { aaaaaaaa, bbbbbb, cccccc, dddddddd, eeeeeee, fffffffff, ggggggggg } from 'vjeux';" | ./bin/prettier.js --stdin --trailing-comma
export {
aaaaaaaa,
bbbbbb,
cccccc,
dddddddd,
eeeeeee,
fffffffff,
ggggggggg,
} from "vjeux";
```
2017-01-13 13:00:46 -05:00
Christopher Chedeau
3dcf46c77c
Do not put spaces on empty for loop ( #169 )
...
```js
for (;;) {
```
instead of
```js
for (; ; ) {
```
2017-01-13 13:00:32 -05:00
Christopher Chedeau
8e0f97e410
Break multiline imports ( #167 )
...
Follows the same pattern as https://github.com/jlongster/prettier/pull/156/files
```js
echo "import { aaaaaaaa, bbbbbb, cccccc, dddddddd, eeeeeee, fffffffff, ggggggggg } from 'vjeux';" | ./bin/prettier.js --stdin
import {
aaaaaaaa,
bbbbbb,
cccccc,
dddddddd,
eeeeeee,
fffffffff,
ggggggggg
} from "vjeux";
```
2017-01-13 12:59:33 -05:00
James Long
fb9c1e8098
Fix misprinting of computed properties in method chains. ( #157 )
...
* Fix misprinting of computed properties in method chains.
Closes #23 , #94 .
* Fix snapshot conflict
2017-01-12 15:06:44 -05:00
James Long
aab300844f
Use group instead of conditionalGroup
2017-01-12 14:53:12 -05:00
Benjamin Tan
1549936e68
Break long exports into multiple lines.
...
Ref #19 .
2017-01-12 14:38:22 -05:00
James Long
bbe2524dab
Merge pull request #134 from vjeux/generics
...
Support method generics on babylon parser
2017-01-12 13:50:10 -05:00
Christopher Chedeau
291440b730
Support method generics on babylon parser
...
This is working on the flow parser but not babylon
```js
echo 'class C<T> { submit<T>() { } }' | ./bin/prettier.js --stdin
class C<T> {
submit<T>() {}
}
```
2017-01-12 07:48:26 -08:00
Christopher Chedeau
afca3d7e7a
Minimize string escapes
...
If there you are opting in for double quote but there's a string with a double quote in it, it's better to swap to a single quote to avoid having too many `\`. Note that if there are both single and double quotes in the string, we should use the default string instead.
Fixes #139
2017-01-12 07:44:16 -08:00
James Long
d25881530f
Merge pull request #126 from vjeux/jsx_quotes
...
Always use double quotes for JSX and properly escape
2017-01-12 10:30:42 -05:00
James Long
809aabc3bd
Merge pull request #133 from vjeux/generic_babylon
...
Support type annotation for rest argument on babylon parser
2017-01-12 10:28:57 -05:00
James Long
1ccf6b0344
Merge pull request #90 from bakkot/property-names
...
Fix #79 : omit unnecessary quotes in property names
2017-01-12 09:11:36 -05:00
Christopher Chedeau
35fb28bef2
Support type annotation for rest argument on babylon parser
...
This is working on the flow parser but not babylon
```js
echo 'function f(...flags: Array<boolean>) {}' | ./bin/prettier.js --stdin
function f(...flags: Array<boolean>) {}
```
2017-01-11 15:05:28 -08: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
Kevin Gibbons
18f54005f6
Do not unquote string properties
2017-01-11 09:31:34 -08:00
Benjamin Tan
24c3af8821
Remove trailing whitespace in broken arrow function expressions.
...
Closes #103 .
2017-01-11 23:28:13 +08:00
James Long
c2458e7dc9
Merge pull request #106 from demoneaux/fix-directives-newlines
...
Fix misprinting of directives.
2017-01-11 10:20:09 -05:00
James Long
944659194b
Merge pull request #105 from demoneaux/fix-eof
...
Add newline to EOF.
2017-01-11 10:15:15 -05:00
Benjamin Tan
030a70fd38
Fix misprinting of directives.
...
Closes #29 .
2017-01-11 22:47:22 +08:00
Benjamin Tan
03414d64cc
Add newline to EOF.
...
Closes #55 .
2017-01-11 22:39:32 +08:00
Benjamin Tan
d56365dd54
Add semicolons to export declarations.
...
Closes #22 .
2017-01-11 20:43:27 +08:00
Kevin Gibbons
be8f65d23e
Format property names consistently
2017-01-10 22:29:54 -08:00
James Long
10a8cd9122
Merge pull request #45 from danharper/fix38
...
Print Flow types with no name (fixes #38 )
2017-01-10 23:51:42 -05:00
James Long
34dc37a816
Merge pull request #67 from jmorrell/flow-type-declarations
...
Make union types pretty again
2017-01-10 23:38:27 -05:00
Dan Harper
7c21dd037f
Fix import & export bracket spacing ( fixes #24 )
2017-01-11 00:32:57 +00:00
James Long
3f949907a0
Merge pull request #72 from michaelficarra/GH-71
...
fixes #71 : don't indent block statements which are children of case clauses
2017-01-10 18:56:50 -05:00
James Long
d2d6def9be
Revert "fixes #49 : omit new parens when it has no arguments"
...
This reverts commit b5392f9468 .
2017-01-10 18:53:03 -05:00
Michael Ficarra
0461b3e6cd
fixes #71 : don't indent block stmts which are children of case clauses
2017-01-10 15:26:12 -08:00
James Long
e3b41dd6ca
Merge pull request #57 from michaelficarra/GH-56
...
fixes #56 : indent cases inside switch statements
2017-01-10 17:49:46 -05:00
Dan Harper
867b829965
Print Flow types with no name ( fixes #38 )
2017-01-10 22:49:25 +00:00
James Long
321bd6a9fa
Allow block-less arrow function expression to break ( fixes #61 )
2017-01-10 16:46:33 -05:00
Jeremy Morrell
9213d5ad7f
First attempt at making union types prettier
2017-01-10 18:31:29 -03:00