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.
typeArg={data: number}functionfn(arg: Arg): void{console.log(arg)}/*:: type Arg = { data: number } */functionfn(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:
varf=(d: any): number);varf=(((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.