Skip to content

Repository files navigation

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.

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.

Known issues

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.

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.

About

Convert flowtype syntax to valid JS

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages