Fix missing comments in assignment pattern (#704)
* Add handleAssignmentPatternComments helper function.
* Add new tests 🎉.
* Remove unecessary arg in function.
* Reorder it.
* Experimental fix for key comments in the printComments function.
* Pull master and switch to @vjeux implementation.
* Fix bad rebase.
* Add additional checking for enclosingNode in handleObjectProperty function.
master
parent
01b0692307
commit
d613f92f60
|
@ -179,7 +179,8 @@ function attach(comments, ast, text) {
|
|||
addDanglingComment(ast, comment);
|
||||
}
|
||||
} else {
|
||||
if (handleIfStatementComments(enclosingNode, followingNode, comment)) {
|
||||
if (handleIfStatementComments(enclosingNode, followingNode, comment) ||
|
||||
handleObjectProperty(enclosingNode, precedingNode, comment)) {
|
||||
// We're good
|
||||
} else if (precedingNode && followingNode) {
|
||||
// Otherwise, text exists both before and after the comment on
|
||||
|
@ -395,6 +396,19 @@ function handleConditionalExpressionComments(
|
|||
return false;
|
||||
}
|
||||
|
||||
function handleObjectProperty(enclosingNode, precedingNode, comment) {
|
||||
if (enclosingNode &&
|
||||
(enclosingNode.type === "ObjectProperty" ||
|
||||
enclosingNode.type === "Property") &&
|
||||
enclosingNode.shorthand &&
|
||||
enclosingNode.key === precedingNode &&
|
||||
enclosingNode.value.type === "AssignmentPattern") {
|
||||
addTrailingComment(enclosingNode.value.left, comment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function printComment(commentPath) {
|
||||
const comment = commentPath.getValue();
|
||||
comment.printed = true;
|
||||
|
|
|
@ -1087,3 +1087,25 @@ try {
|
|||
}
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test assignment-pattern.js 1`] = `
|
||||
"const { a /* comment */ = 1 } = b;
|
||||
|
||||
const { c = 1 /* comment */ } = d;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const { a /* comment */ = 1 } = b;
|
||||
|
||||
const { c = 1 /* comment */ } = d;
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`test assignment-pattern.js 2`] = `
|
||||
"const { a /* comment */ = 1 } = b;
|
||||
|
||||
const { c = 1 /* comment */ } = d;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
const { a /* comment */ = 1 } = b;
|
||||
|
||||
const { c = 1 /* comment */ } = d;
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
const { a /* comment */ = 1 } = b;
|
||||
|
||||
const { c = 1 /* comment */ } = d;
|
Loading…
Reference in New Issue