Prettier 1.9.2
Playground link
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:
- 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.
- after printing every node, skip whitespace for
node.loc.end for */.
- I think those are safe if we only skip whitespace...
- 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
Prettier 1.9.2
Playground link
Input:
Output:
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:
node.loc.startin original text skipping whitespace and check for/*::.. if found, prepend the node with that.node.loc.endfor*/.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