Preserving comments' placement property (#19567)
Co-authored-by: fisker <lionkay@gmail.com>
This commit is contained in:
1 parent
91bcac88ec
commit
2bb67ce8cd
3 files changed
+11
-2
No files matched your search
@@ -0,0 +1,3 @@
|
||||
#### Preserving comments' `placement` property (#19567 by @Janther)
|
||||
|
||||
Prettier@3.9.0 deleted an undocumented property on comments, which was already used by plugins, `comment.placement` is now available again after comment attach.
|
||||
@@ -174,11 +174,11 @@ function attachComments(ast, options) {
|
||||
}
|
||||
|
||||
if (attachPropertiesToComment) {
|
||||
comment.placement = placement;
|
||||
comment.enclosingNode = enclosingNode;
|
||||
comment.precedingNode = precedingNode;
|
||||
comment.followingNode = followingNode;
|
||||
}
|
||||
comment.placement = placement;
|
||||
|
||||
if (placement === "ownLine") {
|
||||
// If a comment exists on its own line, prefer a leading comment.
|
||||
@@ -256,7 +256,10 @@ function attachComments(ast, options) {
|
||||
delete comment.precedingNode;
|
||||
delete comment.enclosingNode;
|
||||
delete comment.followingNode;
|
||||
delete comment.placement;
|
||||
|
||||
// The `placement` property already used by plugins, can't delete
|
||||
// https://github.com/prettier-solidity/prettier-plugin-solidity/blob/6986134753d72095bde41fe8e9a3c795830282ea/src/slang-nodes/IfStatement.ts#L56
|
||||
// https://github.com/dangmai/prettier-plugin-apex/blob/ff35044e53e0ba30423e1f2030161d096e99ae99/packages/prettier-plugin-apex/src/printer.ts#L251
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
|
||||
"start": { "line": 1, "column": 0, "index": 0 },
|
||||
"end": { "line": 1, "column": 7, "index": 7 }
|
||||
},
|
||||
"placement": "endOfLine",
|
||||
"leading": true,
|
||||
"trailing": false,
|
||||
"nodeDescription": "ExpressionStatement"
|
||||
@@ -25,6 +26,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
|
||||
"start": { "line": 2, "column": 16, "index": 24 },
|
||||
"end": { "line": 2, "column": 23, "index": 31 }
|
||||
},
|
||||
"placement": "remaining",
|
||||
"leading": false,
|
||||
"trailing": true,
|
||||
"nodeDescription": "Identifier foo"
|
||||
@@ -38,6 +40,7 @@ exports[`prints information for debugging comment attachment with --debug-print-
|
||||
"start": { "line": 2, "column": 26, "index": 34 },
|
||||
"end": { "line": 2, "column": 30, "index": 38 }
|
||||
},
|
||||
"placement": "remaining",
|
||||
"leading": false,
|
||||
"trailing": true,
|
||||
"nodeDescription": "ExpressionStatement"
|
||||
|
||||
Reference in new issue
Block a user