Fix class method comments (#1074)

* Add new helper function for printing ClassBody comments.

* Update tests.
master
Davy Duperron 2017-03-22 17:26:27 +01:00 committed by Christopher Chedeau
parent 41977c293e
commit dfd42d8306
3 changed files with 45 additions and 1 deletions

View File

@ -196,7 +196,8 @@ function attach(comments, ast, text, options) {
handleCallExpressionComments(precedingNode, enclosingNode, comment) ||
handlePropertyComments(enclosingNode, comment) ||
handleExportNamedDeclarationComments(enclosingNode, comment) ||
handleOnlyComments(enclosingNode, ast, comment, isLastComment)
handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
handleClassMethodComments(enclosingNode, comment)
) {
// We're good
} else if (precedingNode) {
@ -666,6 +667,14 @@ function handleAssignmentPatternComments(enclosingNode, comment) {
return false;
}
function handleClassMethodComments(enclosingNode, comment) {
if (enclosingNode && enclosingNode.type === "ClassMethod") {
addTrailingComment(enclosingNode, comment);
return true;
}
return false;
}
function printComment(commentPath) {
const comment = commentPath.getValue();
comment.printed = true;

View File

@ -26,6 +26,13 @@ class A extends /* a */ B {}
(class A /* a */ extends B {});
(class A extends B /* a */ {});
(class A extends /* a */ B {});
class x {
focus() // do nothing
{
// do nothing
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// comment 1
// comment 2
@ -54,6 +61,13 @@ class A extends /* a */ B {}
(class A extends B /* a */ {
});
(class A extends /* a */ B {});
class x {
focus() // do nothing
{
// do nothing
}
}
"
`;
@ -83,6 +97,13 @@ class A extends /* a */ B {}
(class A /* a */ extends B {});
(class A extends B /* a */ {});
(class A extends /* a */ B {});
class x {
focus() // do nothing
{
// do nothing
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// comment 1
// comment 2
@ -111,5 +132,12 @@ class A extends /* a */ B {}
(class A extends B /* a */ {
});
(class A extends /* a */ B {});
class x {
focus() // do nothing
{
// do nothing
}
}
"
`;

View File

@ -23,3 +23,10 @@ class A extends /* a */ B {}
(class A /* a */ extends B {});
(class A extends B /* a */ {});
(class A extends /* a */ B {});
class x {
focus() // do nothing
{
// do nothing
}
}