Fix duplicated comments on prettier-ignored super class (#18168)
This commit is contained in:
1 parent
d548a87684
commit
48100c323d
3 files changed
+18
-15
No files matched your search
@@ -151,32 +151,26 @@ function canAttachComment(node, ancestors) {
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function willPrintOwnComments(path) {
|
||||
const { node, parent, key } = path;
|
||||
const { key, parent } = path;
|
||||
if (
|
||||
(key === "types" && isUnionType(parent)) ||
|
||||
(key === "argument" && parent.type === "JSXSpreadAttribute") ||
|
||||
(key === "expression" && parent.type === "JSXSpreadChild")
|
||||
(key === "expression" && parent.type === "JSXSpreadChild") ||
|
||||
(key === "superClass" &&
|
||||
(parent.type === "ClassDeclaration" ||
|
||||
parent.type === "ClassExpression")) ||
|
||||
// Not tested, don't know how to
|
||||
(key === "patterns" && parent.type === "MatchOrPattern")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const { node } = path;
|
||||
if (hasNodeIgnoreComment(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isJsxElement(node) || isUnionType(node)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!parent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
parent.type === "MatchOrPattern" ||
|
||||
(path.key === "superClass" &&
|
||||
(parent.type === "ClassDeclaration" || parent.type === "ClassExpression"))
|
||||
);
|
||||
return isJsxElement(node) || isUnionType(node);
|
||||
}
|
||||
|
||||
function isGap(text, { parser }) {
|
||||
|
||||
@@ -97,6 +97,9 @@ class C2 // comment
|
||||
extends Base
|
||||
{ foo(){} }
|
||||
|
||||
(class A10 extends /* a */ /* prettier-ignore */B {});
|
||||
class A10 extends /* a */ /* prettier-ignore */B {}
|
||||
|
||||
=====================================output=====================================
|
||||
class A // comment 1
|
||||
// comment 2
|
||||
@@ -142,5 +145,8 @@ class C2 // comment
|
||||
foo() {}
|
||||
}
|
||||
|
||||
(class A10 extends /* a */ /* prettier-ignore */ B {});
|
||||
class A10 extends /* a */ /* prettier-ignore */ B {}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -38,3 +38,6 @@ class c extends d
|
||||
class C2 // comment
|
||||
extends Base
|
||||
{ foo(){} }
|
||||
|
||||
(class A10 extends /* a */ /* prettier-ignore */B {});
|
||||
class A10 extends /* a */ /* prettier-ignore */B {}
|
||||
Reference in new issue
Block a user