matthewmueller / joy

A delightful Go to Javascript compiler (ON HOLD)
https://mat.tm/joy
GNU General Public License v3.0
1.32k stars 35 forks source link

V2 (strikes back) #39

Closed matthewmueller closed 6 years ago

matthewmueller commented 6 years ago

Implementing interfaces required a much richer understanding the each variable and definition.

With this version:

  1. We first build an index. This is a shallow walk through every definition in our project. The purpose of this is to know where everything is when we need it. The building of the index is done in golly/db (name will change), though most of the work is done in golly/defs

  2. We progressively process our definitions starting with the main() functions. We look at every variable, the documentation, etc. to build a dependency graph and attach metadata to each definition (like if it's async or not.) This is a deep walk of the AST, but it's only performed on the dependencies we find (not the whole project)

  3. For each main(), we topologically sort this dependency graph, prune unwanted definitions (e.g. methods without constructors), and group into a list of modules (packages in golang), and finally into a script (1 script per main()).

  4. Lastly, we walk over each of the scripts, their modules, their definitions and finally their AST, translating Go AST fragments into their corresponding JS AST fragments, using information in the definition (obtained in step 2) to help inform the translation.

  5. Step 4 will produce a JS AST that we will then pass through jsast/assemble to produce a valid JS string.