Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
thorn0 committed Sep 10, 2022
1 parent 98d4265 commit 5751d96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/language-js/parse/postprocess/index.js
Expand Up @@ -159,22 +159,24 @@ function postprocess(ast, options) {

/* eslint-disable prettier-internal-rules/no-node-comments */
if (isNonEmptyArray(ast.comments)) {
let followingComment = getLast(ast.comments);
for (let i = ast.comments.length - 2; i >= 0; i--) {
const comment = ast.comments[i];
const nextComment = ast.comments[i + 1];
if (
locEnd(comment) === locStart(followingComment) &&
isBlockComment(comment) &&
isIndentableBlockComment(comment) &&
isBlockComment(nextComment) &&
isIndentableBlockComment(nextComment) &&
locEnd(comment) === locStart(nextComment)
isBlockComment(followingComment) &&
isIndentableBlockComment(followingComment)
) {
ast.comments.splice(i + 1, 1);
ast.comments[i] = {
followingComment = ast.comments[i] = {
...comment,
value: comment.value + "*//*" + nextComment.value,
range: [locStart(comment), locEnd(nextComment)],
value: comment.value + "*//*" + followingComment.value,
range: [locStart(comment), locEnd(followingComment)],
};
} else {
followingComment = comment;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/format/js/comments/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -3177,6 +3177,7 @@ function value(type, value) {
/** Trailing nestled comment 1
*//** Trailing nestled comment 2
*//** Trailing nestled comment 3
*/
=====================================output=====================================
Expand Down Expand Up @@ -3206,6 +3207,7 @@ function value(type, value) {
/** Trailing nestled comment 1
*//** Trailing nestled comment 2
*//** Trailing nestled comment 3
*/
================================================================================
Expand Down Expand Up @@ -3243,6 +3245,7 @@ function value(type, value) {
/** Trailing nestled comment 1
*//** Trailing nestled comment 2
*//** Trailing nestled comment 3
*/
=====================================output=====================================
Expand Down Expand Up @@ -3272,6 +3275,7 @@ function value(type, value) {
/** Trailing nestled comment 1
*//** Trailing nestled comment 2
*//** Trailing nestled comment 3
*/
================================================================================
Expand Down
1 change: 1 addition & 0 deletions tests/format/js/comments/jsdoc-nestled.js
Expand Up @@ -24,4 +24,5 @@ function value(type, value) {

/** Trailing nestled comment 1
*//** Trailing nestled comment 2
*//** Trailing nestled comment 3
*/

0 comments on commit 5751d96

Please sign in to comment.