parent
c669a1db72
commit
bff28023b3
|
@ -279,6 +279,7 @@ function attach(comments, ast, text) {
|
|||
) ||
|
||||
handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
|
||||
handleCommentInEmptyParens(text, enclosingNode, comment) ||
|
||||
handleMethodNameComments(enclosingNode, precedingNode, comment) ||
|
||||
handleOnlyComments(enclosingNode, ast, comment, isLastComment)
|
||||
) {
|
||||
// We're good
|
||||
|
@ -548,6 +549,24 @@ function handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) {
|
|||
return false;
|
||||
}
|
||||
|
||||
function handleMethodNameComments(enclosingNode, precedingNode, comment) {
|
||||
// This is only needed for estree parsers (flow, typescript) to attach
|
||||
// after a method name:
|
||||
// obj = { fn /*comment*/() {} };
|
||||
if (
|
||||
enclosingNode &&
|
||||
precedingNode &&
|
||||
(enclosingNode.type === "Property" ||
|
||||
enclosingNode.type === "MethodDefinition") &&
|
||||
precedingNode.type === "Identifier" &&
|
||||
enclosingNode.key === precedingNode
|
||||
) {
|
||||
addTrailingComment(precedingNode, comment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleCommentInEmptyParens(text, enclosingNode, comment) {
|
||||
if (getNextNonSpaceNonCommentCharacter(text, comment) !== ")") {
|
||||
return false;
|
||||
|
|
|
@ -138,6 +138,29 @@ exports[`member.js 1`] = `
|
|||
|
||||
`;
|
||||
|
||||
exports[`method.js 1`] = `
|
||||
|
||||
class C {
|
||||
name/*comment*/() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
({
|
||||
name/*comment*/() {
|
||||
}
|
||||
});
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
class C {
|
||||
name /*comment*/() {}
|
||||
}
|
||||
|
||||
({
|
||||
name /*comment*/() {}
|
||||
});
|
||||
|
||||
`;
|
||||
|
||||
exports[`ternary.js 1`] = `
|
||||
if (1) (class {}) ? 1 : 2;
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
@ -1 +1 @@
|
|||
run_spec(__dirname, null, ["typescript"]);
|
||||
run_spec(__dirname, null, ["babylon", "typescript"]);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
class C {
|
||||
name/*comment*/() {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
({
|
||||
name/*comment*/() {
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue