Commit Graph

156 Commits (3375cfe6050721d2f08956ecb056e3d33155975f)

Author SHA1 Message Date
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00
James Long f6708a5cca Fix integer CLI arguments (#452) 2017-01-24 16:07:05 -05:00
Christopher Chedeau e13bb7dbba [RFC] Do not put spacing inside of arrays with bracketSpacing option enabled (#446)
Given the discussion on #296, it seems like there's debate between spaces around `{}` but no one puts spaces around `[]`. So changing the behavior to respect this.
2017-01-24 11:38:12 -08:00
James Long 45f1dc8a01 Update snapshots 2017-01-24 14:24:14 -05:00
Davy Duperron 409d4b6eb5 Ability to break on `:` for objects (#314) 2017-01-24 14:20:24 -05:00
James Long 3aa267d5e8 Remove `multilineGroup` (#450) 2017-01-24 13:54:01 -05:00
Christopher Chedeau fb52e7a5c8 Do not put a newline on empty `{}` for functions (#447)
The original intent of it was for `if then else` and `try catch` as they aren't likely to be empty, but it accidentally caught function bodys, which have many valid reasons to be empty. Let's special case those out.
2017-01-24 12:37:01 -05:00
James Long cd2f7393ef Propagate breaks upwards automatically, introduce `breakParent`, and deprecate `multilineGroup` (#440) 2017-01-23 18:47:11 -05:00
Christopher Chedeau 5861c90913 Proper parenthesis for yield and await in conditional (#436)
Turns out, we need to always parenthesis when it's the first part of a conditional for both yield and await.

Fixes #433
2017-01-23 10:25:38 -08:00
Christopher Chedeau d9d704fd00 Revert "Workaround flow bug around trailing comma" (#429) 2017-01-22 20:52:30 -08:00
Christopher Chedeau d7a44bae10 Add parenthesis when class expressions are left of a ternary (#428)
Fixes #426
2017-01-22 20:32:17 -08:00
Christopher Chedeau 4369e66017 Workaround flow bug around trailing comma (#427)
Fixes #425
2017-01-22 20:31:43 -08:00
Christopher Chedeau 3d4e0bf166 Re-run snapshot tests 2017-01-22 19:31:59 -08:00
Brian Ng 895709b4ca Fix missing parens around object in MemberExpression (#424) 2017-01-22 19:29:30 -08:00
Christopher Chedeau b13124bed4 Add parenthesis for class expression on left of member expression (#421)
Fixes #414
2017-01-22 19:05:46 -08:00
Christopher Chedeau d7992886dd Add parenthesis around export default assignments (#423)
Fixes #413
2017-01-22 19:05:33 -08:00
Christopher Chedeau 2acc3e5ea6 Add parenthesis around assignment for arrow function body (#422)
Fixes #412
2017-01-22 19:04:00 -08:00
Christopher Chedeau d57d8450dc Add parenthesis for yield inside of a conditional (#418)
Fixes #411
2017-01-22 19:03:43 -08:00
Brian Ng 2a0e7b575c Ensure computed method names don't lose quotes (#419) 2017-01-22 18:41:31 -08:00
Christopher Chedeau 105a164423 Add parenthesis around class expression when left side of call expression (#409)
Fixes #402
2017-01-22 16:22:49 -08:00
Christopher Chedeau c8615ed9a6 Add parenthesis for arrow function inside of ternary (#408)
This one is really weird

```js
if (() => {} ? 1 : 0) {}
```

parses fine but

```js
if (() => {
} ? 1 : 0) {}
```

is a syntax error. Let's always add a parenthesis.

Note that no one is every going to write this in practice, this is really useless :p
2017-01-22 16:16:57 -08:00
Christopher Chedeau 41d92c1187 Fix in inside of the first group of a for (#406)
Fixes #405
2017-01-22 15:52:35 -08:00
Christopher Chedeau 2f220de204 Fix various parenthesis issues on the left side of template (#404) 2017-01-22 15:43:57 -08:00
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
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
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
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 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
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