Skip to content

Commit

Permalink
Fix #7920 - do not add comma for explicit inexact object with indexer…
Browse files Browse the repository at this point in the history
… property (#7923)

* 7920 run tests for trailingComma:es5 option as well

* 7920 example of wrong behavior - comma is always added at the end of the inexact object type

* 7920 add test cases for trailingComma: 'all'

* 7920 fix - do not force trailing comma on explicit inexact type if it has indexer or no properties

* 7920 add changelog
  • Loading branch information
DmitryGonchar committed Apr 1, 2020
1 parent 7047fad commit 964230d
Show file tree
Hide file tree
Showing 6 changed files with 588 additions and 5 deletions.
52 changes: 52 additions & 0 deletions changelog_unreleased/flow/pr-7923.md
@@ -0,0 +1,52 @@
#### Do not add comma for explicit inexact object with indexer property or no properties ([#7923](https://github.com/prettier/prettier/pull/7923) by [@DmitryGonchar](https://github.com/DmitryGonchar))

<!-- prettier-ignore -->
```jsx
// Input
type T = {
a: number,
...,
}

type T = {
[string]: number,
...,
}

type T = {
// comment
...,
}

// Prettier stable
type T = {
a: number,
...
}

type T = {
[string]: number,
...,
}

type T = {
// comment
...,
}

// Prettier master
type T = {
a: number,
...
}

type T = {
[string]: number,
...
}

type T = {
// comment
...
}
```
10 changes: 5 additions & 5 deletions src/language-js/printer-estree.js
Expand Up @@ -1416,11 +1416,11 @@ function printPathNoParens(path, options, print, args) {
const lastElem = getLast(n[propertiesField]);

const canHaveTrailingSeparator = !(
lastElem &&
(lastElem.type === "RestProperty" ||
lastElem.type === "RestElement" ||
hasNodeIgnoreComment(lastElem) ||
n.inexact)
n.inexact ||
(lastElem &&
(lastElem.type === "RestProperty" ||
lastElem.type === "RestElement" ||
hasNodeIgnoreComment(lastElem)))
);

let content;
Expand Down

0 comments on commit 964230d

Please sign in to comment.