Handle comments between function name and open paren (#2979)
parent
3c00979530
commit
23f7e92162
|
@ -298,7 +298,8 @@ function attach(comments, ast, text) {
|
||||||
handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
|
handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
|
||||||
handleCommentInEmptyParens(text, enclosingNode, comment) ||
|
handleCommentInEmptyParens(text, enclosingNode, comment) ||
|
||||||
handleMethodNameComments(text, enclosingNode, precedingNode, comment) ||
|
handleMethodNameComments(text, enclosingNode, precedingNode, comment) ||
|
||||||
handleOnlyComments(enclosingNode, ast, comment, isLastComment)
|
handleOnlyComments(enclosingNode, ast, comment, isLastComment) ||
|
||||||
|
handleFunctionNameComments(text, enclosingNode, precedingNode, comment)
|
||||||
) {
|
) {
|
||||||
// We're good
|
// We're good
|
||||||
} else if (precedingNode && followingNode) {
|
} else if (precedingNode && followingNode) {
|
||||||
|
@ -641,6 +642,31 @@ function handleMethodNameComments(text, enclosingNode, precedingNode, comment) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleFunctionNameComments(
|
||||||
|
text,
|
||||||
|
enclosingNode,
|
||||||
|
precedingNode,
|
||||||
|
comment
|
||||||
|
) {
|
||||||
|
if (getNextNonSpaceNonCommentCharacter(text, comment) !== "(") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
precedingNode &&
|
||||||
|
enclosingNode &&
|
||||||
|
(enclosingNode.type === "FunctionDeclaration" ||
|
||||||
|
enclosingNode.type === "FunctionExpression" ||
|
||||||
|
enclosingNode.type === "ClassMethod" ||
|
||||||
|
enclosingNode.type === "MethodDefinition" ||
|
||||||
|
enclosingNode.type === "ObjectMethod")
|
||||||
|
) {
|
||||||
|
addTrailingComment(precedingNode, comment);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function handleCommentInEmptyParens(text, enclosingNode, comment) {
|
function handleCommentInEmptyParens(text, enclosingNode, comment) {
|
||||||
if (getNextNonSpaceNonCommentCharacter(text, comment) !== ")") {
|
if (getNextNonSpaceNonCommentCharacter(text, comment) !== ")") {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -294,6 +294,40 @@ call((/*object*/ row) => {});
|
||||||
KEYPAD_NUMBERS.map(num => ( // Buttons 0-9
|
KEYPAD_NUMBERS.map(num => ( // Buttons 0-9
|
||||||
<div />
|
<div />
|
||||||
));
|
));
|
||||||
|
|
||||||
|
function f /* f */() {}
|
||||||
|
function f (/* args */) {}
|
||||||
|
function f () /* returns */ {}
|
||||||
|
function f /* f */(/* args */) /* returns */ {}
|
||||||
|
|
||||||
|
function f /* f */(/* a */ a) {}
|
||||||
|
function f /* f */(a /* a */) {}
|
||||||
|
function f /* f */(/* a */ a) /* returns */ {}
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
f1 /* f */() {},
|
||||||
|
f2 (/* args */) {},
|
||||||
|
f3 () /* returns */ {},
|
||||||
|
f4 /* f */(/* args */) /* returns */ {},
|
||||||
|
};
|
||||||
|
|
||||||
|
(function f /* f */() {})();
|
||||||
|
(function f (/* args */) {})();
|
||||||
|
(function f () /* returns */ {})();
|
||||||
|
(function f /* f */(/* args */) /* returns */ {})();
|
||||||
|
|
||||||
|
class C {
|
||||||
|
f/* f */() {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f(/* args */) {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f() /* returns */ {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f/* f */(/* args */) /* returns */ {}
|
||||||
|
}
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
function a(/* comment */) {} // comment
|
function a(/* comment */) {} // comment
|
||||||
function b() {} // comment
|
function b() {} // comment
|
||||||
|
@ -303,6 +337,49 @@ KEYPAD_NUMBERS.map((
|
||||||
num // Buttons 0-9
|
num // Buttons 0-9
|
||||||
) => <div />);
|
) => <div />);
|
||||||
|
|
||||||
|
function f /* f */() {}
|
||||||
|
function f(/* args */) {}
|
||||||
|
function f() /* returns */ {
|
||||||
|
}
|
||||||
|
function f /* f */(/* args */) /* returns */ {
|
||||||
|
}
|
||||||
|
|
||||||
|
function f /* f */(/* a */ a) {}
|
||||||
|
function f /* f */(a /* a */) {}
|
||||||
|
function f /* f */(/* a */ a) /* returns */ {
|
||||||
|
}
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
f1 /* f */() {},
|
||||||
|
f2(/* args */) {},
|
||||||
|
f3() /* returns */ {
|
||||||
|
},
|
||||||
|
f4 /* f */(/* args */) /* returns */ {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
(function f /* f */() {})();
|
||||||
|
(function f(/* args */) {})();
|
||||||
|
(function f() /* returns */ {
|
||||||
|
})();
|
||||||
|
(function f /* f */(/* args */) /* returns */ {
|
||||||
|
})();
|
||||||
|
|
||||||
|
class C {
|
||||||
|
f /* f */() {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f(/* args */) {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f() /* returns */ {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f /* f */(/* args */) /* returns */ {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`if.js 1`] = `
|
exports[`if.js 1`] = `
|
||||||
|
|
|
@ -5,3 +5,37 @@ call((/*object*/ row) => {});
|
||||||
KEYPAD_NUMBERS.map(num => ( // Buttons 0-9
|
KEYPAD_NUMBERS.map(num => ( // Buttons 0-9
|
||||||
<div />
|
<div />
|
||||||
));
|
));
|
||||||
|
|
||||||
|
function f /* f */() {}
|
||||||
|
function f (/* args */) {}
|
||||||
|
function f () /* returns */ {}
|
||||||
|
function f /* f */(/* args */) /* returns */ {}
|
||||||
|
|
||||||
|
function f /* f */(/* a */ a) {}
|
||||||
|
function f /* f */(a /* a */) {}
|
||||||
|
function f /* f */(/* a */ a) /* returns */ {}
|
||||||
|
|
||||||
|
const obj = {
|
||||||
|
f1 /* f */() {},
|
||||||
|
f2 (/* args */) {},
|
||||||
|
f3 () /* returns */ {},
|
||||||
|
f4 /* f */(/* args */) /* returns */ {},
|
||||||
|
};
|
||||||
|
|
||||||
|
(function f /* f */() {})();
|
||||||
|
(function f (/* args */) {})();
|
||||||
|
(function f () /* returns */ {})();
|
||||||
|
(function f /* f */(/* args */) /* returns */ {})();
|
||||||
|
|
||||||
|
class C {
|
||||||
|
f/* f */() {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f(/* args */) {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f() /* returns */ {}
|
||||||
|
}
|
||||||
|
class C {
|
||||||
|
f/* f */(/* args */) /* returns */ {}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue