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

Refactoring generator code #204

Merged
merged 15 commits into from
Dec 17, 2016
Merged

Refactoring generator code #204

merged 15 commits into from
Dec 17, 2016

Conversation

Rich-Harris
Copy link
Member

This is far from finished, but I thought it worth explaining where I'm going with this before picking it up again tomorrow.

As per #202, there's a lot we can do to reduce duplication between the SSR and DOM compilers. If we ever add other compilers (canvas? webgl? native?) or make compilers pluggable (first-class MobX/Redux support?), that work would also benefit from some better-factored code generation.

My thinking is that we have a generic base Generator class, which is created with a set of visitors specific to each compiler. Things that need to happen for all compilers (gathering imports, figuring out whether we have computed properties, contextualising expressions, dealing with sourcemaps, etc) are built-in to the generator. Stuff that is specific to a compiler like createMountStatement gets removed from the generator, and is instead handled as events (i.e. a visitor can do generator.fire('createMountStatement, {...}), and the compiler can have a corresponding event listener).

@codecov-io
Copy link

codecov-io commented Dec 16, 2016

Current coverage is 92.42% (diff: 95.29%)

Merging #204 into master will decrease coverage by 0.03%

@@             master       #204   diff @@
==========================================
  Files            61         71    +10   
  Lines          1698       1663    -35   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits           1570       1537    -33   
+ Misses          128        126     -2   
  Partials          0          0          

Powered by Codecov. Last update 27d34cf...c849912

@Rich-Harris
Copy link
Member Author

Removing the WIP tag as I think this is ready to merge. Should be a bit easier now to keep the two (and eventually, possible, more) compilers in sync as and when new features get added and bugs get squashed.

@Rich-Harris Rich-Harris changed the title [WIP] Refactoring generator code Refactoring generator code Dec 16, 2016
@Swatinem
Copy link
Member

I think the use of events here feels really strange.
What you essentially want it to extend (subclass?) the generator with some methods, right? That would be a lot better understandable, and also better for static analysis tools (such as flow) than a stringly-typed api.

Other than that, I think the code organization is much better this way.

@Rich-Harris Rich-Harris merged commit 7cd8683 into master Dec 17, 2016
@Rich-Harris Rich-Harris deleted the gh-202 branch December 17, 2016 17:13
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

Successfully merging this pull request may close these issues.

3 participants