Skip to content

escaton/flow-comments-codemod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.

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.

About

Convert flowtype syntax to valid JS

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published