Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.4 KB

README.md

File metadata and controls

46 lines (35 loc) · 1.4 KB

flow-comments-codemod Build Status

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.

Known issues

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.

Setup & Run

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.