Skip to content

Commit fc998c9

Browse files
committed
Add handleAssignmentPatternComments helper function.
1 parent f3d64b0 commit fc998c9

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/comments.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ function attach(comments, ast, text) {
175175
} else {
176176
if (handleIfStatementComments(enclosingNode, followingNode, comment)) {
177177
// We're good
178+
} else if (handleAssignmentPatternComments(enclosingNode, followingNode, comment)) {
179+
// We're good
178180
} else if (precedingNode && followingNode) {
179181
// Otherwise, text exists both before and after the comment on
180182
// the same line. If there is both a preceding and following
@@ -381,6 +383,20 @@ function handleConditionalExpressionComments(enclosingNode, followingNode, comme
381383
return false;
382384
}
383385

386+
function handleAssignmentPatternComments(enclosingNode, followingNode, comment) {
387+
if (
388+
enclosingNode &&
389+
(enclosingNode.type === "Property" || enclosingNode.type === "ObjectProperty") &&
390+
enclosingNode.value && enclosingNode.value.type === "AssignmentPattern"
391+
) {
392+
addTrailingComment(enclosingNode.value.left, comment);
393+
394+
return true;
395+
}
396+
397+
return false;
398+
}
399+
384400
function printComment(commentPath) {
385401
const comment = commentPath.getValue();
386402
comment.printed = true;

0 commit comments

Comments
 (0)