Skip to content

Commit 2bb67ce

Browse files
Jantherfisker
andauthored
Preserving comments' placement property (#19567)
Co-authored-by: fisker <[email protected]>
1 parent 91bcac8 commit 2bb67ce

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎changelog_unreleased/misc/19567.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#### Preserving comments' `placement` property (#19567 by @Janther)
2+
3+
[email protected] deleted an undocumented property on comments, which was already used by plugins, `comment.placement` is now available again after comment attach.

‎src/main/comments/attach.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ function attachComments(ast, options) {
174174
}
175175

176176
if (attachPropertiesToComment) {
177-
comment.placement = placement;
178177
comment.enclosingNode = enclosingNode;
179178
comment.precedingNode = precedingNode;
180179
comment.followingNode = followingNode;
181180
}
181+
comment.placement = placement;
182182

183183
if (placement === "ownLine") {
184184
// If a comment exists on its own line, prefer a leading comment.
@@ -256,7 +256,10 @@ function attachComments(ast, options) {
256256
delete comment.precedingNode;
257257
delete comment.enclosingNode;
258258
delete comment.followingNode;
259-
delete comment.placement;
259+
260+
// The `placement` property already used by plugins, can't delete
261+
// https://github.com/prettier-solidity/prettier-plugin-solidity/blob/6986134753d72095bde41fe8e9a3c795830282ea/src/slang-nodes/IfStatement.ts#L56
262+
// https://github.com/dangmai/prettier-plugin-apex/blob/ff35044e53e0ba30423e1f2030161d096e99ae99/packages/prettier-plugin-apex/src/printer.ts#L251
260263
}
261264
}
262265
}

‎tests/integration/__tests__/__snapshots__/debug-print-comments.js.snap‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
1212
"start": { "line": 1, "column": 0, "index": 0 },
1313
"end": { "line": 1, "column": 7, "index": 7 }
1414
},
15+
"placement": "endOfLine",
1516
"leading": true,
1617
"trailing": false,
1718
"nodeDescription": "ExpressionStatement"
@@ -25,6 +26,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
2526
"start": { "line": 2, "column": 16, "index": 24 },
2627
"end": { "line": 2, "column": 23, "index": 31 }
2728
},
29+
"placement": "remaining",
2830
"leading": false,
2931
"trailing": true,
3032
"nodeDescription": "Identifier foo"
@@ -38,6 +40,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
3840
"start": { "line": 2, "column": 26, "index": 34 },
3941
"end": { "line": 2, "column": 30, "index": 38 }
4042
},
43+
"placement": "remaining",
4144
"leading": false,
4245
"trailing": true,
4346
"nodeDescription": "ExpressionStatement"

0 commit comments

Comments
 (0)