Flow: Print dangling comments for empty inexact object type (#7892)
* Remove unnecessary group * Print dangling comment for inexact type * Add changelog * Fix changelog
This commit is contained in:
1 parent
8a48ca2e3d
commit
0f56b4aa62
4 files changed
+221
-1
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Print dangling comments for inexact object type ([#7892](https://github.com/prettier/prettier/pull/7892) by [@sosukesuzuki](https://github.com/sosukesuzuki))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
|
||||
// Prettier stable
|
||||
Error: Comment "comment" was not printed. Please report this error!
|
||||
|
||||
// Prettier master
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
```
|
||||
@@ -1386,7 +1386,31 @@ function printPathNoParens(path, options, print, args) {
|
||||
});
|
||||
|
||||
if (n.inexact) {
|
||||
props.push(concat(separatorParts.concat(group("..."))));
|
||||
let printed;
|
||||
if (hasDanglingComments(n)) {
|
||||
const hasLineComments = !n.comments.every(
|
||||
handleComments.isBlockComment
|
||||
);
|
||||
const printedDanglingComments = comments.printDanglingComments(
|
||||
path,
|
||||
options,
|
||||
/* sameIndent */ true
|
||||
);
|
||||
printed = concat([
|
||||
printedDanglingComments,
|
||||
hasLineComments ||
|
||||
hasNewline(
|
||||
options.originalText,
|
||||
options.locEnd(n.comments[n.comments.length - 1])
|
||||
)
|
||||
? hardline
|
||||
: line,
|
||||
"...",
|
||||
]);
|
||||
} else {
|
||||
printed = "...";
|
||||
}
|
||||
props.push(concat(separatorParts.concat(printed)));
|
||||
}
|
||||
|
||||
const lastElem = getLast(n[propertiesField]);
|
||||
|
||||
@@ -1,5 +1,128 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`comments.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
printWidth: 80
|
||||
trailingComma: "none"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = { /* comment */
|
||||
...};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
=====================================output=====================================
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`test.js 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["flow", "babel"]
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
// @flow
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = { /* comment */ ... };
|
||||
|
||||
type Foo = { /* comment */
|
||||
...};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
...,
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
// comment0
|
||||
// comment1
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
|
||||
type Foo = {
|
||||
/* comment0 */
|
||||
/* comment1 */
|
||||
foo: string,
|
||||
...
|
||||
};
|
||||
Reference in new issue
Block a user