Skip to content

Commit

Permalink
fix flow-comments - class type paramters and implements (#9897)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and nicolo-ribaudo committed Apr 26, 2019
1 parent 7101308 commit ca3c53a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
31 changes: 24 additions & 7 deletions packages/babel-plugin-transform-flow-comments/src/index.js
Expand Up @@ -146,14 +146,31 @@ export default declare(api => {

Class(path) {
const { node } = path;
if (node.typeParameters) {
const typeParameters = path.get("typeParameters");
if (node.typeParameters || node.implements) {
const comments = [];
if (node.typeParameters) {
const typeParameters = path.get("typeParameters");
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",
generateComment(typeParameters, typeParameters.node),
);
typeParameters.remove();
block.addComment("leading", ":: " + comments.join(" "));
}
},
},
Expand Down
@@ -0,0 +1 @@
class Foo implements Bar, Baz {}
@@ -0,0 +1,3 @@
class Foo
/*:: implements Bar, Baz*/
{}
@@ -0,0 +1 @@
class Foo<S, T> implements Bar, Baz {}
@@ -0,0 +1,3 @@
class Foo
/*:: <S, T> implements Bar, Baz*/
{}
@@ -0,0 +1 @@
class Foo<T> {}
@@ -0,0 +1,3 @@
class Foo
/*:: <T>*/
{}

0 comments on commit ca3c53a

Please sign in to comment.