Fix comment for call( // comment (#858)
This is a pretty exotic way to put a comment and it's been a long time since I have seen prettier output be as broken :) Fixes #857
This commit is contained in:
1 parent
735f07fa4f
commit
fe38dab45a
3 files changed
+70
No files matched your search
@@ -173,6 +173,7 @@ function attach(comments, ast, text, options) {
|
||||
) ||
|
||||
handleImportSpecifierComments(enclosingNode, comment) ||
|
||||
handleTemplateLiteralComments(enclosingNode, comment) ||
|
||||
handleCallExpressionComments(precedingNode, enclosingNode, comment) ||
|
||||
handleClassComments(enclosingNode, comment)
|
||||
) {
|
||||
// We're good
|
||||
@@ -501,6 +502,16 @@ function handleImportSpecifierComments(enclosingNode, comment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function handleCallExpressionComments(precedingNode, enclosingNode, comment) {
|
||||
if (enclosingNode && enclosingNode.type === "CallExpression" &&
|
||||
precedingNode && enclosingNode.callee === precedingNode &&
|
||||
enclosingNode.arguments.length > 0) {
|
||||
addLeadingComment(enclosingNode.arguments[0], comment);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function printComment(commentPath) {
|
||||
const comment = commentPath.getValue();
|
||||
comment.printed = true;
|
||||
|
||||
@@ -52,6 +52,56 @@ exports[`blank.js 2`] = `
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`call_comment.js 1`] = `
|
||||
"render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
|
||||
React.render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
render(
|
||||
// Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
|
||||
React.render(
|
||||
// Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`call_comment.js 2`] = `
|
||||
"render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
|
||||
React.render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
render(
|
||||
// Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
|
||||
React.render(
|
||||
// Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`dangling.js 1`] = `
|
||||
"var x = {/* dangling */};
|
||||
var x = {
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
|
||||
React.render( // Warm any cache
|
||||
<ChildUpdates renderAnchor={true} anchorClassOn={true} />,
|
||||
container
|
||||
);
|
||||
Reference in new issue
Block a user