Skip to content

Flow comments change order of comments at beginning of file #10324

@ziadkh0

Description

@ziadkh0

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();
  }
  //...

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commentsarea: flowoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions