Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/escaton/flow-comments-codemod
Convert flowtype syntax to valid JS
https://github.com/escaton/flow-comments-codemod
Last synced: 3 months ago
JSON representation
Convert flowtype syntax to valid JS
- Host: GitHub
- URL: https://github.com/escaton/flow-comments-codemod
- Owner: escaton
- Created: 2019-05-23T13:46:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T22:28:56.000Z (about 2 years ago)
- Last Synced: 2024-08-02T07:14:31.361Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.08 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - flow-comments-codemod - Convert flowtype syntax to valid JS. (JavaScript)
README
## flow-comments-codemod [![Build Status](https://travis-ci.org/escaton/flow-comments-codemod.svg)](https://travis-ci.org/escaton/flow-comments-codemod)
This codemod converts [Flow](https://flow.org) syntax into valid JS, but keep it [valid Flow](https://flow.org/en/docs/types/comments/).
Such transformation may be useful with gradual migration from Flow to Typescript.
```js
type Arg = { data: number }
function fn(arg: Arg): void {
console.log(arg)
}
```
```js
/*:: type Arg = { data: number } */
function fn(arg/*: Arg*/)/*: void*/ {
console.log(arg)
}
```
More examples [here](https://github.com/escaton/flow-comments-codemod/tree/master/src/__testfixtures__)Compared to [@babel/plugin-transform-flow-comments](https://babeljs.io/docs/en/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:
```js
var f = (d: any): number);
```
```js
var f = (((d/*: any*/)/*: number*/));
```
so i recommend to apply [Prettier](http://prettier.io/) after transformation.### Setup & Run
This tool is based on [jscodeshift](https://github.com/facebook/jscodeshift)
```sh
npm install -g jscodeshift
git clone https://github.com/escaton/flow-comments-codemod.git
jscodeshift -t
```Use the `-d` option for a dry-run and use `-p` to print the output for
comparison.