Skip to content

Print comment type includes as comments #3493

@duailibe

Description

@duailibe

Prettier 1.9.2
Playground link

--parser flow

Input:

/*::

/* this is a comment *-/

type MyType = {
  key: string
}
*/

let foo: MyType = {key: "hello"}

Output:

/* this is a comment */

type MyType = {
  key: string
};
let foo: MyType = { key: "hello" };

The /*:: ... */ comment syntax simply parses the comment as if it wasn't a comment at all and the flow parser exposes those as regular nodes.. so we'd need to access the original code to find out if those are comments or not.

I have the following idea:

  1. before printing every node, go backwards from node.loc.start in original text skipping whitespace and check for /*::.. if found, prepend the node with that.
  2. after printing every node, skip whitespace for node.loc.end for */.
  3. I think those are safe if we only skip whitespace...
  4. Figure out a way to handle comments in that case, because they aren't nodes when traversing the API to use the logic above

I'm experimenting with this already but I wanted to gather feedback/opinions/suggestions as well... if anyone wants to collaborate as well let me know

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:flow comment typeslang:flowIssues affecting Flow-specific constructs (not general JS issues)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions