Commit Graph

2849 Commits (b878a54e6addbc6ea745ea089549d241edb048e7)

Author SHA1 Message Date
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
Christopher Chedeau c5d7619ad6 Remove faulty location check on template literals that throws in Nuclide (#218)
There's a handful of files inside of Nuclide that throw exceptions because an assertion is raised.

```
{ AssertionError: ']' === '`'
    at fixTemplateLiteral (/Users/vjeux/random/prettier/src/util.js:105:10)
    at Object.util.fixFaultyLocations (/Users/vjeux/random/prettier/src/util.js:45:5)
    at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:25:8)
    at getSortedChildNodes (/Users/vjeux/random/prettier/src/comments.js:61:5)
    at decorateComment (/Users/vjeux/random/prettier/src/comments.js:71:20)
    at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7)
    at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7)
    at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7)
    at decorateComment (/Users/vjeux/random/prettier/src/comments.js:85:7)
    at /Users/vjeux/random/prettier/src/comments.js:129:5
```

When trying https://github.com/facebook/nuclide/blob/master/pkg/nuclide-task-runner/lib/main.js#L174

It throws in the fixTemplateLiteral method.

That method was added to fix https://github.com/benjamn/recast/issues/216 more than a year ago

```js
var x = {
  y: () => Relay.QL`
    query {
      ${foo},
      field,
    }
  `
};
```

I've checked (and added a test) and it now parses and prints correctly without that method. So it should be safe to remove.
2017-01-15 23:46:05 -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
Christopher Chedeau fe72aecce9 Fix parenthesis for UpdateExpression (#198)
```js
(this.x++).toString()
```

no longer drops the parenthesis
2017-01-14 23:37:57 -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
James Long 7f80d8dbff Add note about Sublime Test github issue in readme 2017-01-14 23:21:58 -05:00
Christopher Chedeau 281417ac1d Fix await parenthesis (#185)
This is the first time I'm adding something inside of fast-path so I'm not sure if it's correct, but it seems more correct than before!

Fixes #164
2017-01-14 23:12:17 -05:00
James Long 60c0b52fed Update live editor to 0.0.7 2017-01-13 23:33:38 -05:00
James Long e447971612 v0.0.7 2017-01-13 23:27:49 -05:00
Christopher Chedeau 6f5df0e2b6 Change test to workaround babylon bug (#184)
Babylon has a bug where it doesn't escape DirectiveLiteral properly. Except for `'use strict';`, this never happens in real world code, so let's put strings in a array in order to workaround this bug and have the same output on both parsers.

https://github.com/babel/babylon/issues/289
2017-01-13 23:17:02 -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
Christopher Chedeau ca230c2f2f Fix exponent in babylon (#181)
The type is NumericLiteral instead of Literal
2017-01-13 23:12:21 -05:00
Kent C. Dodds f49111c87c add license to package.json (#178)
Because right now it doesn't show any license on
[the npm page](https://www.npmjs.com/package/prettier).

Also, it's causing my [DependencyCI](https://dependencyci.com/github/kentcdodds/prettier-eslint/builds/5)
build to fail 😅
2017-01-13 23:11:03 -05:00
Christopher Chedeau b9a3e0650a Fix windows line-endings (#177)
The search for an empty line incorrectly does +1 which happens to be skipping a `\n`, but in case of windows line endings it skips the `\r` but sees a `\n` afterwards and incorrectly assumes that it is a empty line.

This doesn't change the behavior of doing +1 when there's not a line ending. Making it correct actually triggers a bunch of changes, where half of them are better and half of them regressions. So I'm going to send another pull request to fix that case.
2017-01-13 23:07:09 -05:00
Christopher Chedeau 23e6184309 Do not advance for forward skipSpaces (#176)
For backward, we should go one step back, but for forward we are already in the correct place. It doesn't change any tests.
2017-01-13 23:00:36 -05:00
Christopher Chedeau ca471088e6 Fix `[(0)]` (#179)
Another issue where babylon and flow ast are different. In babylon, it is NumericLiteral but flow is Literal. All the tests are running on flow so were working correctly, but the default in the command line is to use babylon, so people report bugs with it.
2017-01-13 22:59:36 -05:00
Mikael Brevik cbabefdb0f Adds various prettier-browser changes (#175)
* Adds link to GH repo in title

* Adds popular keybindings (subl) to editor

* Changes theme to base16-dark to fit better with body bg
2017-01-13 17:14:48 -05:00
James Long 3713408871 Update live editor to 0.0.6 2017-01-13 15:40:22 -05:00
James Long 4ffdb0c43f Improve CHANGELOG format again 2017-01-13 15:13:30 -05:00
James Long 2ab030b1d2 Fix CHANGELOG format 2017-01-13 15:10:21 -05:00
James Long 7e3161096b v0.0.6 2017-01-13 15:09:37 -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
Vu Tran b429b2443c include index.js in format:all script (#132) 2017-01-13 14:23:07 -05:00
Alex Rattray 47102bc3ef Add regression tests for long JSX Expression contents 2017-01-13 14:22:49 -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