Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip flow types #256

Closed
Kronuz opened this issue Feb 20, 2019 · 25 comments
Closed

Strip flow types #256

Kronuz opened this issue Feb 20, 2019 · 25 comments

Comments

@Kronuz
Copy link

Kronuz commented Feb 20, 2019

Babel has this module: @babel/plugin-transform-flow-strip-types, which simply ignores flow types. There are quite a few modules out there that use babel to compile, yet have flow typing.

Please add support for stripping types, no need for full Flow support (issue #174), just ignore/strip them.

@kdy1
Copy link
Member

kdy1 commented May 28, 2021

Closing as flow decided to focus on internal usages.

@kdy1 kdy1 closed this as completed May 28, 2021
@FezVrasta
Copy link

That doesn't mean external projects can't use it. There are a lot of projects that still use Flow.

@kdy1
Copy link
Member

kdy1 commented Oct 3, 2021

@FezVrasta If you send a PR, I'll happily accept it and maintain it.

@kdy1
Copy link
Member

kdy1 commented Oct 3, 2021

@FezVrasta Maybe it's unrelated question, can you show me some projects using flow?
I've been working on swc for few years and I didn't have time to look at the source code of other js/ts projects.

@FezVrasta
Copy link

I maintain Popper, which is used by approximately a couple million websites around the world, and it's entirely wrote with Flow.

https://popper.js.org

@FezVrasta
Copy link

FezVrasta commented Oct 3, 2021

@FezVrasta If you send a PR, I'll happily accept it and maintain it.

The best way to implement it would be to use flow-remove-types since it's a standalone binary (no Babel involved) and it's maintained by the Flow core team.

This is an example of how to use it programmatically with JavaScript:

https://github.com/leebyron/rollup-plugin-flow/blob/master/index.js

I'd be happy to send a PR, I just need to understand if integrating flow-remove-types would be an acceptable approach, and some guidance on where to start.

@kdy1
Copy link
Member

kdy1 commented Oct 3, 2021

Hmm... I don't think using js module is acceptable.
I'll just try implementing it in rust when I have some free time. (Hopefully tomorrow, as it's holiday)

@kdy1 kdy1 reopened this Oct 3, 2021
@FezVrasta
Copy link

Thanks that'd be awesome! The whole Flow community will be grateful for this 🤗

@kdy1 kdy1 modified the milestones: v1.2.94, v1.2.93 Oct 3, 2021
@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

I found that I have a task with higher priority, so I'm postponing this.

@kdy1 kdy1 removed this from the v1.2.94 milestone Oct 4, 2021
@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

I looked at the source code of flow-remove-types, and it depends on flow-parser, which means lots of jobs.

@FezVrasta
Copy link

FezVrasta commented Oct 4, 2021

Yes it depends on the JS-compiled OCaml compiler. Considering how fast the OCaml compiler it is I wonder if swc could directly interface with it?

TBH a simple plugin-like approach where each file is feeded through the Flow parser would be all it's needed to address this.

@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

Is there a way to see the size of the compiled flow stripper?
I don't want to bloat the binary size.

@FezVrasta
Copy link

FezVrasta commented Oct 4, 2021

It's between 30-40 MB depending by the target platform:

CleanShot 2021-10-04 at 13 27 18@2x

From my understanding, the Babel plugin to strip Flow types doesn't depend on the Flow compiler though, so maybe you could use their source code as reference for a Rust implementation?

https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-flow-strip-types/src/index.js

@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

From my understanding, the Babel plugin to strip Flow types doesn't depend on the Flow compiler though, so maybe you could use their source code as reference for a Rust implementation?

Yes. But it means lots of work. It's really enormous amount of work.

@FezVrasta
Copy link

From my understanding, the Babel plugin to strip Flow types doesn't depend on the Flow compiler though, so maybe you could use their source code as reference for a Rust implementation?

Yes. But it means lots of work. It's really enormous amount of work.

What about the approach I described above?

TBH a simple plugin-like approach where each file is feeded through the Flow parser would be all it's needed to address this.

@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

I'm fine with it.
But currently, there's no plugin api for parser, so we need to make some decisions about the api.

@FezVrasta
Copy link

Ok that sounds great, this way the Flow support will be implementable at plugin level and the core is not tied to it.

Is there anything else I can do to help to move this effort forward? Do you have an RFC or other kind of documentation where the API is being designed?

@kdy1
Copy link
Member

kdy1 commented Oct 4, 2021

Can you join discord server at https://discord.gg/GnHbXTdZz6 ?

I'm not sure about the RFC, but I think people in discord server may provide some ideas about the api.

@FezVrasta
Copy link

For anyone interested, I started a conversation here https://discord.com/channels/889779439272075314/889780921002246154/894551464410763314

@noppa
Copy link

noppa commented Oct 4, 2021

Facebook's Hermes project also has parsers for both TypeScript and Flow, written in C++, if that's any help.

@FezVrasta
Copy link

Facebook's Hermes project also has parsers for both TypeScript and Flow, written in C++, if that's any help.

That's great! It also seems to expose a Rust API?

@mikeduminy
Copy link

react-native also uses flow which need to be stripped away in production builds

@langri-sha
Copy link

Shooting from the hip: there's only a few differences between the TS and Flow type syntaxes, so perhaps it's possible to reuse a goodly portion of the TS transformer and take it from there?

@kwonoj
Copy link
Member

kwonoj commented Jul 24, 2023

I'm going to suggest to close this. /cc @kdy1 before actually closing it.

Given the scope of the SWC's feature and codebase, I don't think we have enough bandwidth to support this continuously. Probably the best way forward is someone making a userland parser based on the existing implementation of SWC.

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 24, 2023
@swc-bot
Copy link
Collaborator

swc-bot commented Aug 24, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Aug 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

8 participants