Fix class method comments (#1074)
* Add new helper function for printing ClassBody comments. * Update tests.master
parent
41977c293e
commit
dfd42d8306
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue