This codemod converts Flow syntax into valid JS, but keep it valid Flow.
Such transformation may be useful with gradual migration from Flow to Typescript.
type Arg = { data: number }
function fn(arg: Arg): void {
console.log(arg)
}
/*:: type Arg = { data: number } */
function fn(arg/*: Arg*/)/*: void*/ {
console.log(arg)
}
More examples here
Compared to @babel/plugin-transform-flow-comments this transformation better handles comment line breaks and doesn't touch unchanged code.
In some cases the result may look a bit messy:
var f = (d: any): number);
var f = (((d/*: any*/)/*: number*/));
so i recommend to apply Prettier after transformation.
This tool is based on jscodeshift
npm install -g jscodeshift
git clone https://github.com/escaton/flow-comments-codemod.git
jscodeshift -t <codemod-script> <file>
Use the -d
option for a dry-run and use -p
to print the output for
comparison.