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 change order of comments at beginning of file #10324

Closed
zaygraveyard opened this issue Aug 12, 2019 · 3 comments

Comments

@zaygraveyard
Copy link
Contributor

commented Aug 12, 2019

Bug Report

Current Behavior
@babel/plugin-transform-flow-comments change order of comments at beginning of file when the file starts with a comment followed by a flow statement

/*:: import type {A} from 'a';*/

/**/
X;

Input Code
REPL link

/**/
import type {A} from 'a';
X

Expected behavior/code

/**/
/*:: import type {A} from 'a';*/
X;

Environment

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

Possible Solution

  //...
  function attachComment(path, comment) {
    let attach = path.getPrevSibling();
    let where = "trailing";
    if (!attach.node) {
      attach = path.getNextSibling();
      where = "leading";
    }
    if (!attach.node) {
      attach = path.parentPath;
      where = "inner";
    }
    attach.addComment(where, comment);
    path.remove();
  }
  //...
@babel-bot

This comment has been minimized.

Copy link
Collaborator

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.

@JLHwung

This comment has been minimized.

Copy link
Contributor

commented Aug 12, 2019

Could you open up a PR? Besides import declaration, any other flow-only statement, i.e. type A = number; will also result to incorrect behaviour if it has no prevSibling.

@zaygraveyard

This comment has been minimized.

Copy link
Contributor Author

commented Aug 13, 2019

@JLHwung I know, I just happened to have the import case
But I'm working on a PR for any flow-only statement

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
Projects
None yet
3 participants
You can’t perform that action at this time.