Commit Graph

845 Commits (4629db6b0dbc88c6d7f7e8eb23996138f96dbda9)

Author SHA1 Message Date
Lucas Azzola 4629db6b0d TypeScript: improve handling of computed properties (#1532)
* fix(typescript): improve handling of computed properties

* test(typescript): add Symbol computed property test

* fix(typescript): do not print brackets for literals
2017-05-06 08:00:26 -07:00
Prathik Shetty c2bdcbe996 Include pre-commit plugin (#1493)
* Update README.md

* Update README.md

* Update README.md

* Update README.md
2017-05-06 07:59:23 -07:00
Simen Bekkhus ed24bff251 Upgrade jest (#1534)
* Upgrade jest

* yarn upgrade
2017-05-06 07:40:40 -07:00
Lucas Azzola c337c83043 fix(typescript): workaround eslint/typescript-eslint-parser#257 (#1533) 2017-05-06 06:19:33 -07:00
Lucas Azzola 11e3d8241f TypeScript: print modifiers on TSIndexSignature and TSPropertySignature (#1531)
* fix(typescript): print modifiers on TSIndexSignature

* fix(typescript): print modifiers on TSPropertySignature and reformat TSMappedType
2017-05-06 06:18:23 -07:00
Lucas Azzola 8a8a67b9fe fix(typescript): print typeArguments in TSExpressionWithTypeArguments (#1530) 2017-05-06 06:17:48 -07:00
Igor Oleinikov f51822c16d fix(TypeScript): define TSFunctionType AST node (#1529)
- fixes printing of comments inside function type node
2017-05-05 22:14:12 -07:00
Christopher Chedeau bb232d48a3 Inline chained conditionals inside of jsx attribute (#1519)
Fixes #1515
2017-05-05 21:44:50 -07:00
Christopher Chedeau c63e21b52b Do not put parens for single argument with end of line comment (#1518)
Fixes #1517
2017-05-05 21:44:42 -07:00
Christopher Chedeau 3d964b18bb Add parens around `as` (#1528)
I put it at the same place where `a in b` is handled.

Fixes #1524
2017-05-05 21:39:20 -07:00
Christopher Chedeau c8984f392a Fix TypeScript regex (#1527)
Turns out n.value is NaN for regexes in typescript, go figure. Just moving the two if statements is working to fix the issue.

Fixes #1526
2017-05-05 21:39:11 -07:00
Lucas Azzola b9a7549e47 TypeScript: correctly print nested namespaces (#1522)
* fix(typescript): correctly print nested namespaces

* test(typescript): update snapshots
2017-05-05 21:14:07 -07:00
Lucas Azzola b23c16d05d fix(typescript): print typeParameters on TSMethodSignature (#1523) 2017-05-05 21:11:13 -07:00
Lucas Azzola c689f2a0e7 Fix module block, add enum initializers and fix type parameters (#1501)
* fix(typescript): fix module block, add enum initializers and fix type parameters

* fix(typescript): use printStatementSequence for TSModuleBlock

* fix(type-params): move typeParameters out of printFunctionParams

* refactor(type-params): move typeParameters out of printArgumentList
2017-05-05 19:44:26 -07:00
Dorian Karter d3d5d57984 Use setlocal in all vim examples (#1403) 2017-05-05 09:13:08 -07:00
Paul Carduner af754adb7b Make prettier into a global minor mode that can be toggled on and off (#1496) 2017-05-05 09:10:59 -07:00
Jake Trent 3cfc37d411 Options readme (#1406)
* add options table to readme

* remove options from api usage in favor of options table

and link a few paragraphs to the options section
2017-05-05 09:10:23 -07:00
Kevin Gibbons e290514a9e Parenthesize `new F(await a)` and `x[await a]` correctly (#1513) 2017-05-05 08:10:56 -07:00
Brian Ng ccf509abb6 Fix empty line with flow union (#1511) 2017-05-04 19:06:30 -07:00
Christopher Chedeau 1a1e6fc1dd Print empty member lookup (#1506)
I have no idea if it's even valid but it threw on 8 typescript tests, now it doesn't.

```js
TypeError: Cannot read property 'type' of null
at printMemberLookup (prettier/src/printer.js:3062:16)
```
2017-05-04 11:20:52 -07:00
Danny Arnold 1fca1eeddf add TSTypeParameter to typescript ast nodes (#1508) 2017-05-04 11:20:35 -07:00
Danny Arnold 14636947b6 add TSParameterProperty to typescript ast nodes (#1507) 2017-05-04 11:19:50 -07:00
Danny Arnold c1a8ee011d add TSAbstractKeyword (#1505) 2017-05-04 09:48:24 -07:00
Christopher Chedeau bdf6050434 Do not throw on an empty file with a ; (#1503)
Fixes "TypeError: Cannot read property 'replace' of undefined"

This was discovered by #1480 and also affects non-typescript
2017-05-04 09:40:11 -07:00
Danny Arnold e6eee0467d add TSConstKeyword (#1502) 2017-05-04 09:37:00 -07:00
CodinCat b354fbd6dc Update repo link in github page (#1500) 2017-05-04 07:46:42 -07:00
Kevin Gibbons 886f70fcdf Put loop bodies on the same line when possible (#1498) 2017-05-03 15:50:48 -07:00
Christopher Chedeau 515a565a66 1.3.1 (hotfix) 2017-05-03 14:44:08 -07:00
Christopher Chedeau 8613046fd2 Respect template inline-ness (#1497)
In 1.3.0, we shipped a change that makes template literal always inlined as single arguments of a function. The problem with template literals is that they whitespace is significant so we can't change it. There are two cases:

```js
call(`
  template
  template
`);
```

and

```js
call(
  `template
   template`
);
```

If you always make the same decision to inline, you're going to be wrong for the other use case. The solution that I found that works is to figure out if there's a `\n` before the backtick `` ` ``. If that's the case, then don't inline, otherwise do. We're trying to avoid looking at the source as much as possible but this is one example where we actually don't have a choice if we want to keep the output sane.

1.3.0 made the jest codebase significantly worse because of this. The issue is that once things have been moved, this heuristic won't be able to undo it. So people need to have this fix applied before they run 1.3.0, otherwise it's going to damage their codebase unless they manually change everything back, which is a pain. So I'm going to land this as a hotfix in 1.3.1.

Fixes #1492
2017-05-03 14:35:58 -07:00
Davy Duperron 9e345c8527 Drop htmlEscapeInsideAngleBracket function in favour of raw/extra.raw from Flow/Babylon parsers (#1165)
* Make slice simpler.

* Drop htmlEscapeInsideAngleBracket function.

Use child.extra.raw (Babylon) and child.raw (Flow) to get the value instead.

* Remove unused htmlEscapeInsideAngleBracket function.

* Update test cases accordingly.

* Fix merge conflict.

* Update tests via `npm test -- -u`.

* Fix multiple consecutive spaces preservation in printJSXChildren.

* Update tests accordingly.
2017-05-03 08:47:15 -07:00
Lucas Azzola aeeaffca35 Fix handling of new keyword and call signatures and improve type parameter formatting (#1491)
* fix(typescript): fix handling of new keyword

* fix(typescript): fix handling of call signatures

* feat(typescript): share type parameter formatting with flow
2017-05-03 08:01:45 -07:00
Lucas Azzola 59b348f550 Implement TypeScript keywords, namespace functions and class heritage (#1483)
* feat(typescript): #1480: implement *Keyword, namespace function and class heritage

* feat(typescript): add type params and modifiers to interfaces

* chore(style): add squigly wings to if/else blocks

* fix(typescript): remove hardline before declare
2017-05-02 17:06:25 -07:00
Danny Arnold e8a80ca0aa fix #1484 (#1487)
* don't print colon if there is no `typeAnnotation`
* print prefix also for empty interfaces
2017-05-02 16:03:51 -07:00
Danny Arnold 5cf1659acf add TSDecorator (#1488) 2017-05-02 16:03:23 -07:00
Christopher Chedeau b481c57470 1.3.0 docs 2017-05-02 16:00:33 -07:00
Christopher Chedeau a81d5c1cd1 1.3.0 2017-05-02 13:15:15 -07:00
Christopher Chedeau 078572631f Inline template literals as arrow body (#1485)
Turns out I wrote the wrong one :(

Fixes #1465
2017-05-02 09:17:20 -07:00
Christopher Chedeau f59aeef865 Break inline object first in function arguments (#1453) (#1173)
This is getting subtle where the groups need to be in a precise position but that works :)

Fixes #1409
2017-05-01 19:12:53 -07:00
Christopher Chedeau 8f9bb3a223 Break inline object first in function arguments (#1453)
This is getting subtle where the groups need to be in a precise position but that works :)

Fixes #1409
2017-05-01 14:49:03 -07:00
Christopher Chedeau 54b8cac0a7 Reorder flow object props (#1451)
This is very sad, but we need to do this to get the correct result :(

Fixes #1448
2017-05-01 14:42:52 -07:00
Christopher Chedeau c99a877b9f Do not break on [0] (#1441)
In practice, we never want to break on `[0]`. By not doing that, it forces prettier to find a more suitable break placement.

Fixes #1418
2017-05-01 14:41:34 -07:00
Christopher Chedeau acfb14f577 Don't break on empty arrays and objects (#1440)
We never want to break on those at it looks very weird. The reason why I didn't add this yet is because whenever it triggered in the past, the root cause was something else and it helped identify things to fix. But now the remaining ones I'm seeing are no longer underlying issues and they're just about this breaking unnecessarily, so we should just fix it.
2017-05-01 14:41:18 -07:00
Christopher Chedeau bafd72418e Don't break for unparenthesised single argument flow function (#1452)
This has been reported internally. It looks --very-- weird to have it indented the way it was.
2017-05-01 14:39:46 -07:00
Christopher Chedeau a335c26253 Add space around `=` for flow generics default arguments (#1476)
We have a space for function arguments and it looks weird without.
2017-05-01 14:39:15 -07:00
Christopher Chedeau 4b7d265000 Fix windows line ending on template literals (#1439)
Fixes #1432
2017-05-01 14:39:03 -07:00
Christopher Chedeau e39209386c Only add parenthesis on ternaries inside of arrow functions if doesn't break (#1450)
This was added in order to follow some eslint rule but it's only confusing when it doesn't break, when it breaks the indentation makes it clear what is happening and you don't need parenthesis.

Fixes #1379
2017-05-01 14:32:52 -07:00
Christopher Chedeau 93cad97b14 Preserve inline comment as last argument (#1390)
We already had the logic but only applied it for comments on their own line, we should also do it if they are inline.

Fixes #1380
2017-05-01 14:29:03 -07:00
Christopher Chedeau 314e96322c Add parenthesis for unusual nested ternaries (#1386)
All of the discussions around ternaries are for the form

```js
cond1 ? elem1_if : cond2 ? elem2_if : elem_else
```

but some of them are for the form

```js
cond1 ? cond2 ? elem2_if : elem2_else : elem1_else
```

which is more rare and would be good to call out by adding parenthesis.

```js
cond1 ? (cond2 ? elem2_if : elem2_else) : elem1_else
```

Note that we only want parenthesis if it's written inline, otherwise the indentation is good enough to understand the flow:

```js
cond1
  ? cond2 ? elem2_if : elem2_else
  : elem1_else
```
2017-05-01 14:28:36 -07:00
Christopher Chedeau 13f05fb763 Proper indentation for template literals (#1385)
Right now, expressions inside of template literals are have the level of indentation of the start of the template literal. But oftentimes, expressions are nested inside of template literals and therefore the expression should have this level of nesting.

The heuristic i'm using to decide when to use the template literal nesting is if it's not the first line and if there isn't another expression before on the same line.
2017-05-01 14:28:11 -07:00
Christopher Chedeau c521406385 [RFC] Do not indent calls with a single template literal argument (#873)
I'm not sure that this is a good idea. A current workaround is to remove the parenthesis.

Fixes #786
2017-05-01 14:27:00 -07:00