Commit Graph

365 Commits (3375cfe6050721d2f08956ecb056e3d33155975f)

Author SHA1 Message Date
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
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