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

Flow to TypeScript, TypeScript to Flow #1

Open
goodmind opened this issue Mar 7, 2019 · 5 comments
Open

Flow to TypeScript, TypeScript to Flow #1

goodmind opened this issue Mar 7, 2019 · 5 comments

Comments

@goodmind
Copy link

goodmind commented Mar 7, 2019

How would this work if they are really different type systems?

@ollelauribostrom
Copy link
Contributor

@goodmind Not sure if I understand your question 🙂On a high level the transformation between Flow and TypeScript (and the other way around) will work like this:

  • The TypeScript file is parsed to an AST
  • Each node in the AST is processed
  • Base on the type of node, either perform some transformation (using recast) - or just return the node as-is (Flow and TypeScript do have some identical syntax)
  • After each node has been processed, turn the AST back into code and write it to a file

@goodmind
Copy link
Author

goodmind commented Mar 11, 2019

@ollelauribostrom yeah, but there is some syntax that can't be converted without losing type information. Or inferred types that doesn't exist in AST

@MaxGraey
Copy link

It probably could intermediate AST with greatest common factor for both type system. So more complex entities always disassembly to simpler set of entities and assemble back to higher order in the end of transform if this possible

@ollelauribostrom
Copy link
Contributor

@goodmind Sorry for the late reply. You're right, figuring out a way to deal with such cases are definitely on the roadmap for an MVP, do you have any thoughts on how to handle this?

@MaxGraey suggestion sounds like a good approach. It might also be an option to let the user manually edit any edge case syntax before continuing with the transformation (sort of like: git merge --> fix conflicts.. --> git merge --continue).

Currently, work is happening in the main repo to implement a prototype that is able to transform some really simple programs 🙂

@MaxGraey
Copy link

MaxGraey commented Mar 23, 2019

btw it may be makes sense using something like jscodeshift for that instead pure recast package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants