Commit Graph

478 Commits (f73ae2978e0a0940483b96fcc53e17d402653d10)

Author SHA1 Message Date
Christopher Chedeau e45a9b0582 Also do the class extend parenthesis for class expressions (#403) 2017-01-22 15:35:45 -08:00
Christopher Chedeau 4a47eff474 Fix +++x (#401)
Fixes #379
2017-01-22 15:21:25 -08:00
Christopher Chedeau 95df4ff655 Remove trailing comma for array destructuring with rest (#400)
Fixes #394
2017-01-22 15:20:47 -08:00
Brian Ng badab37dd1 Remove unneeded parens for FunctionExpression inside LogicalExpression (#399) 2017-01-22 15:00:13 -08:00
Christopher Chedeau bf32905c3f Fix parenthesis in object as left-hand-side of template (#398)
Fixes #392
2017-01-22 14:33:34 -08:00
Christopher Chedeau b77703a942 Fix class inside of binary expression missing parenthesis (#397)
Fixes #395
2017-01-22 14:33:04 -08:00
Christopher Chedeau fac5cd0801 Fix class extends parenthesis (#396)
This should fix all of the issues with the fuzzer :)

Fixes #387
2017-01-22 14:19:53 -08:00
Charles Pick 9a71a907e5 add formatAST() for formatting ASTs directly (#393) 2017-01-22 14:00:23 -08:00
Christopher Chedeau 7be4994d1a Empty switch should not have an empty line (#384)
Fixes #368
2017-01-22 12:40:46 -08:00
Christopher Chedeau 3d95e8317b Fix forced trailing comma (#382)
We shouldn't output trailing commas when there is a forced one when we break.

Fixes #380
2017-01-22 12:34:35 -08:00
Christopher Chedeau 1f92218a06 Fix empty labels (#383)
We actually need this `;` for EmptyStatement, otherwise it applies to the next block of code. (Creating a label with an empty statement is completely useless, but it triggers a lot in the fuzz testing tool)

Fixes #376
2017-01-22 12:34:27 -08:00
Christopher Chedeau 58a97ab597 Fix missing semi-colon in for loop and var body (#388)
We avoid adding a `;` for a variable declaration in for loop but this is only meant if the var declaration is inside of the `()` part of the for loop. Not if the body part.

Fixes #385
2017-01-22 12:34:14 -08:00
Christopher Chedeau 1a9e5e9022 Support multiple standalones in import (#389)
There was an assertion that there would be only one, it turned out not to be the case.

Fixes #386
2017-01-22 12:34:00 -08:00
Christopher Chedeau d944ebf6db Ignore EmptyStatement inside of switch case (#391)
Fixes #378
2017-01-22 12:33:21 -08:00
Simon Lydell 8ed75acf46 Output strings with the minimum amount of escaped quotes (#390)
* Add tests for quotes

* Update test snapshots

* Output strings with the minimum amount of escaped quotes

* Update test snapshots

* Move tests/prettier/quotes.js into tests/quotes/strings.js

* Update test snapshots
2017-01-22 12:32:43 -08:00
Brian Ng e31203f4bf Fix some parens cases for UpdateExpressions (#381) 2017-01-21 20:14:22 -08:00
Simon Lydell 40748a2dc9 Fix CLI options (#369)
- Add missing options to minimist. This removes "Ignored unknown
  option:" warnings for options that actually exists.
- Put more interesting options closer to the top.
- Consistenly use full sentences.
2017-01-21 16:48:18 -08:00
Simon Lydell b8ecf6e5ad s/jscodefmt/prettier/ (#370) 2017-01-21 16:42:13 -08:00
Simon Lydell 4611020214 Warn if using deprecated CLI options (#364)
* Warn if using deprecated CLI options

* Warn if using deprecated API options
2017-01-21 09:23:29 -08:00
Simon Lydell e4f67d8a2f Exit with an error if an unknown CLI option is passed (#365)
* Exit with an error if an unknown CLI option is passed

* Only warn for unknown CLI options
2017-01-21 09:11:34 -08:00
Christopher Chedeau 4bc859b1fc Fix export extension output (#361)
Fixes #360
cc @randycoulman
2017-01-20 19:20:31 -08:00
Brian Ng b953ff0835 Add parens for default export FunctionExpressions (#345)
* Add parens for default export FunctionExpressions

* add exception for ArrowFunctionExpression

* add additional test cases

* thanks bakkot :)
2017-01-20 19:17:16 -08:00
Henry Zhu 237e6f44bc Use a Symbol instead of the private dep (#359) 2017-01-20 15:55:24 -08:00
Christopher Chedeau 21729d8207 Drop jsesc (#357)
Even though JSON.stringify is not 100% correct, this is only used for debugging and doesn't warrant adding a dependency for it.
2017-01-20 14:55:41 -08:00
Christopher Chedeau 080b7f8ec4 Swap quotes (#355)
- During the first iteration, we printed the unescaped values which let to printing invalid JavaScript characters and bad things like invisible characters.
- During the second iteration, we escaped everything, which generated valid JavaScript but you lost your emojis and chinese/cyrillic characters

In this iteration, which I hope will be the last one, we maintain the string exactly as encoded and only swap quotes. The swap quotes implementation is a bit convoluted but I think it works.
2017-01-20 14:47:52 -08:00
Christopher Chedeau d20a580655 Run prettier on the codebase (#354) 2017-01-20 10:12:37 -08:00
Christopher Chedeau 92f14d79df v0.0.10 (#353) 2017-01-20 10:00:01 -08:00
Christopher Chedeau c468fde106 Add debugging support for doc IR (#347)
This PR adds two things:

`--debug-print-doc` command that prints the formatted doc

```js
echo "<div>&lt;</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
  groupConditional(
    group([
      group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
      "&lt;",
      "</",
      "div",
      ">"
    ]),
    [
      group([
        group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
        "&lt;",
        "</",
        "div",
        ">"
      ]),
      group([
        group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
        indent(2, groupBreak([ hardline(), "&lt;" ])),
        hardline(),
        "</",
        "div",
        ">"
      ])
    ]
  ),
  ";",
  hardline()
];
```

The ability to view the IR in real time on the browser display:

![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)

The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 09:54:32 -08:00
Christopher Chedeau 896bb5b26d Indent while test the same way as if test (#352)
Fixes #312
2017-01-20 09:42:16 -08:00
Brian Ng 9fc85eb30d Remove parens around AwaitExpression in ternary (#346) 2017-01-19 19:18:02 -08:00
Christopher Chedeau d8d5c7bc55 Introduce --parser/parser option and deprecate --flow-parser/useFlowParser (#342)
The previous API was inconsistent. The new one is

```js
--parser flow
--parser babylon

{parser: 'flow'}
{parser: 'babylon'}
```

if we ever want to add new parsers in the future it'll allow that more easily.

I put a console.log in parser.js in both functions and tested that the test suite worked both with and without the change in run_spec. I also tested that both the previous and new command line options are working.

At some point in the future we'll likely want to get rid of the old api but might as well keep supporting it so we don't break anyone for now.
2017-01-19 14:35:12 -08:00
Kevin Gibbons a8ca2b21f4 Add semicolon to more default exports (#343) 2017-01-19 14:30:36 -08:00
Christopher Chedeau 658998c5b1 Refactor index.js (#340)
Extracted out parse and attachComments. Moved the options normalization in the exported function.

This way, we have a super clean format function :)

```js
function format(text, opts) {
  const ast = parse(text, opts);
  attachComments(text, ast, opts)
  const doc = printAstToDoc(ast, opts)
  const str = printDocToString(doc, opts.printWidth)
  return str;
}
```
2017-01-19 14:18:22 -08:00
Christopher Chedeau 8202a6c3b5 Normalize exports (#339)
Make all the files have a single module.exports call at the end of the file.

I added a missing `"use strict";` and removed a few unused functions from utils at the same time.
2017-01-19 13:45:36 -08:00
Christopher Chedeau aef3e387f8 Extract parser.js (#338)
Before, we would parse things inline in both index.js and run_spec. Extracting it should make it easier to manage and understand what is going on.
2017-01-19 13:23:04 -08:00
Christopher Chedeau 4e5084386d Kill fromString (#335)
This is a leftover from recast. But it doesn't do anything now.
2017-01-19 13:20:03 -08:00
Christopher Chedeau 9682c16de5 Remove unused functions from recast (#337)
Grepped in the codebase and ran the tests
2017-01-19 13:19:52 -08:00
Christopher Chedeau 173f63f043 Fix node 4 (#336)
It complained that it couldn't recognize const outside of `"use strict";`. It's a good idea to add this anyway.
2017-01-19 12:57:23 -08:00
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