fix flow-comments - class type paramters and implements (#9897)

This commit is contained in:
Tan Li Hau 2019-04-27 04:23:13 +08:00 committed by Nicolò Ribaudo
parent 71013088ef
commit ca3c53ae0b
7 changed files with 36 additions and 7 deletions

View File

@ -146,15 +146,32 @@ export default declare(api => {
Class(path) {
const { node } = path;
if (node.typeParameters || node.implements) {
const comments = [];
if (node.typeParameters) {
const typeParameters = path.get("typeParameters");
const block = path.get("body");
block.addComment(
"leading",
generateComment(typeParameters, typeParameters.node),
comments.push(
generateComment(typeParameters, typeParameters.node).replace(
/^:: /,
"",
),
);
typeParameters.remove();
}
if (node.implements) {
const impls = path.get("implements");
comments.push(
"implements " +
impls
.map(impl => generateComment(impl).replace(/^:: /, ""))
.join(", "),
);
delete node["implements"];
}
const block = path.get("body");
block.addComment("leading", ":: " + comments.join(" "));
}
},
},
};

View File

@ -0,0 +1 @@
class Foo implements Bar, Baz {}

View File

@ -0,0 +1,3 @@
class Foo
/*:: implements Bar, Baz*/
{}

View File

@ -0,0 +1 @@
class Foo<S, T> implements Bar, Baz {}

View File

@ -0,0 +1,3 @@
class Foo
/*:: <S, T> implements Bar, Baz*/
{}

View File

@ -0,0 +1,3 @@
class Foo
/*:: <T>*/
{}