Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow comments plugin moves the generic type arguments of the left hand side of the `extends` keyword to its right side #10323

zaygraveyard opened this issue Aug 12, 2019 · 3 comments


Copy link

commented Aug 12, 2019

Bug Report

Current Behavior
@babel/plugin-transform-flow-comments moves the generic type arguments of the left hand side of the extends keyword to its right side

class A extends B /*:: <X>*/ {}

Input Code
REPL link

class A<X> extends B {}

Expected behavior/code

class A /*:: <X>*/ extends B {}


  • Babel version(s): v7.5.5
  • How you are using Babel: Online REPL

Possible Solution

  return {
    visitor: {
      ClassDeclaration(path) {
        if (path.parentPath.isFlow()) {

        const { node } = path;
        if (node.typeParameters) {
          const typeParameters = path.get("typeParameters");
          const id = path.get("id");
          id.addComment("trailing", generateComment(typeParameters, node));

This comment has been minimized.

Copy link

commented Aug 12, 2019

Hey @zaygraveyard! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.


This comment has been minimized.

Copy link

commented Aug 12, 2019

Could you open a PR? I think it suffices to add trailing comments to id here

const block = path.get("body");
block.addComment("leading", ":: " + comments.join(" "));

Oh I just see you have submitted #10321.

Note that we also need check superTypeAnnotation and extract it to comments. The following snippet is not working currently:

class Foo extends Bar<X> {}

This comment has been minimized.

Copy link
Contributor Author

commented Aug 13, 2019

I'm working on a PR

nicolo-ribaudo added a commit that referenced this issue Aug 14, 2019

Fix flow comments plugin issues (#10329)
* Fix issues in flow-comments to preserve comments and there order (fixes #10324)

* Add support in flow-comments for extends in class declarations (fixes #10323, #10321)

* Refactoring and cleanup of flow-comments plugin

* Fix comments preservation logic of flow-comments

* Fix flow-comments where comments are class identifier and extends keyword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.