Fix trailing JSDoc comments with trailing regular comments (#4414)
parent
bafa76f613
commit
8e1b60e943
|
@ -5508,7 +5508,21 @@ function printComment(commentPath, options) {
|
||||||
case "CommentBlock":
|
case "CommentBlock":
|
||||||
case "Block": {
|
case "Block": {
|
||||||
if (isJsDocComment(comment)) {
|
if (isJsDocComment(comment)) {
|
||||||
return printJsDocComment(comment);
|
const printed = printJsDocComment(comment);
|
||||||
|
// We need to prevent an edge case of a previous trailing comment
|
||||||
|
// printed as a `lineSuffix` which causes the comments to be
|
||||||
|
// interleaved. See https://github.com/prettier/prettier/issues/4412
|
||||||
|
if (
|
||||||
|
comment.trailing &&
|
||||||
|
!privateUtil.hasNewline(
|
||||||
|
options.originalText,
|
||||||
|
options.locStart(comment),
|
||||||
|
{ backwards: true }
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return concat([hardline, printed]);
|
||||||
|
}
|
||||||
|
return printed;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isInsideFlowComment =
|
const isInsideFlowComment =
|
||||||
|
|
|
@ -1637,6 +1637,60 @@ exports[`trailing_space.js 1`] = `
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`trailing-jsdocs.js 1`] = `
|
||||||
|
const CONNECTION_STATUS = exports.CONNECTION_STATUS = {
|
||||||
|
CLOSED: Object.freeze({ kind: 'CLOSED' }),
|
||||||
|
CONNECTED: Object.freeze({ kind: 'CONNECTED' }),
|
||||||
|
CONNECTING: Object.freeze({ kind: 'CONNECTING' }),
|
||||||
|
NOT_CONNECTED: Object.freeze({ kind: 'NOT_CONNECTED' }) };
|
||||||
|
|
||||||
|
/* A comment */ /**
|
||||||
|
* A type that can be written to a buffer.
|
||||||
|
*/ /**
|
||||||
|
* Describes the connection status of a ReactiveSocket/DuplexConnection.
|
||||||
|
* - NOT_CONNECTED: no connection established or pending.
|
||||||
|
* - CONNECTING: when \`connect()\` has been called but a connection is not yet
|
||||||
|
* established.
|
||||||
|
* - CONNECTED: when a connection is established.
|
||||||
|
* - CLOSED: when the connection has been explicitly closed via \`close()\`.
|
||||||
|
* - ERROR: when the connection has been closed for any other reason.
|
||||||
|
*/ /**
|
||||||
|
* A contract providing different interaction models per the [ReactiveSocket protocol]
|
||||||
|
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
|
||||||
|
*/ /**
|
||||||
|
* A single unit of data exchanged between the peers of a \`ReactiveSocket\`.
|
||||||
|
*/
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
const CONNECTION_STATUS = (exports.CONNECTION_STATUS = {
|
||||||
|
CLOSED: Object.freeze({ kind: "CLOSED" }),
|
||||||
|
CONNECTED: Object.freeze({ kind: "CONNECTED" }),
|
||||||
|
CONNECTING: Object.freeze({ kind: "CONNECTING" }),
|
||||||
|
NOT_CONNECTED: Object.freeze({ kind: "NOT_CONNECTED" })
|
||||||
|
});
|
||||||
|
|
||||||
|
/* A comment */
|
||||||
|
/**
|
||||||
|
* A type that can be written to a buffer.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Describes the connection status of a ReactiveSocket/DuplexConnection.
|
||||||
|
* - NOT_CONNECTED: no connection established or pending.
|
||||||
|
* - CONNECTING: when \`connect()\` has been called but a connection is not yet
|
||||||
|
* established.
|
||||||
|
* - CONNECTED: when a connection is established.
|
||||||
|
* - CLOSED: when the connection has been explicitly closed via \`close()\`.
|
||||||
|
* - ERROR: when the connection has been closed for any other reason.
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* A contract providing different interaction models per the [ReactiveSocket protocol]
|
||||||
|
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* A single unit of data exchanged between the peers of a \`ReactiveSocket\`.
|
||||||
|
*/
|
||||||
|
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`try.js 1`] = `
|
exports[`try.js 1`] = `
|
||||||
// comment 1
|
// comment 1
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
const CONNECTION_STATUS = exports.CONNECTION_STATUS = {
|
||||||
|
CLOSED: Object.freeze({ kind: 'CLOSED' }),
|
||||||
|
CONNECTED: Object.freeze({ kind: 'CONNECTED' }),
|
||||||
|
CONNECTING: Object.freeze({ kind: 'CONNECTING' }),
|
||||||
|
NOT_CONNECTED: Object.freeze({ kind: 'NOT_CONNECTED' }) };
|
||||||
|
|
||||||
|
/* A comment */ /**
|
||||||
|
* A type that can be written to a buffer.
|
||||||
|
*/ /**
|
||||||
|
* Describes the connection status of a ReactiveSocket/DuplexConnection.
|
||||||
|
* - NOT_CONNECTED: no connection established or pending.
|
||||||
|
* - CONNECTING: when `connect()` has been called but a connection is not yet
|
||||||
|
* established.
|
||||||
|
* - CONNECTED: when a connection is established.
|
||||||
|
* - CLOSED: when the connection has been explicitly closed via `close()`.
|
||||||
|
* - ERROR: when the connection has been closed for any other reason.
|
||||||
|
*/ /**
|
||||||
|
* A contract providing different interaction models per the [ReactiveSocket protocol]
|
||||||
|
* (https://github.com/ReactiveSocket/reactivesocket/blob/master/Protocol.md).
|
||||||
|
*/ /**
|
||||||
|
* A single unit of data exchanged between the peers of a `ReactiveSocket`.
|
||||||
|
*/
|
Loading…
Reference in New Issue