Skip to content

Commit

Permalink
Extract JSX related print functions (#9714)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Nov 19, 2020
1 parent 7acaa55 commit b12e869
Show file tree
Hide file tree
Showing 3 changed files with 781 additions and 702 deletions.
32 changes: 32 additions & 0 deletions src/language-js/comments.js
Expand Up @@ -15,6 +15,10 @@ const {
isBlockComment,
getFunctionParameters,
isPrettierIgnoreComment,
isJSXNode,
hasFlowShorthandAnnotationComment,
hasFlowAnnotationComment,
hasIgnoreComment,
} = require("./utils");
const { locStart, locEnd } = require("./loc");

Expand Down Expand Up @@ -857,6 +861,33 @@ function isTypeCastComment(comment) {
);
}

function willPrintOwnComments(path /*, options */) {
const node = path.getValue();
const parent = path.getParentNode();

return (
((node &&
(isJSXNode(node) ||
hasFlowShorthandAnnotationComment(node) ||
(parent &&
(parent.type === "CallExpression" ||
parent.type === "OptionalCallExpression") &&
(hasFlowAnnotationComment(node.leadingComments) ||
hasFlowAnnotationComment(node.trailingComments))))) ||
(parent &&
(parent.type === "JSXSpreadAttribute" ||
parent.type === "JSXSpreadChild" ||
parent.type === "UnionTypeAnnotation" ||
parent.type === "TSUnionType" ||
((parent.type === "ClassDeclaration" ||
parent.type === "ClassExpression") &&
parent.superClass === node)))) &&
(!hasIgnoreComment(path) ||
parent.type === "UnionTypeAnnotation" ||
parent.type === "TSUnionType")
);
}

module.exports = {
handleOwnLineComment,
handleEndOfLineComment,
Expand All @@ -865,4 +896,5 @@ module.exports = {
isTypeCastComment,
getGapRegex,
getCommentChildNodes,
willPrintOwnComments,
};

0 comments on commit b12e869

Please sign in to comment.