-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Refactor #453
Refactor #453
Conversation
…t tests for codegen. add test for #433
Should any big changes wait for this? |
@PaulBGD I think so, yes — sorry! Actively working on it (in the sense of writing lots of code and then immediately deleting it, these sorts of refactors are always a bit painful. Better to suffer that pain now though), hoping to have it ready soon... did you have any particular changes in mind? |
I'm just checking before I get invested into working on some more features, take your time though. |
Will this mean API changes? I was just about to try Svelte, but I haven't seen anywhere anything about API stability. I assume it follows semver? |
No API changes, doubly so for the components it generates. This is just about moving some of the internal code generation logic around so that it's a bit better structured — at the moment some of the work happens in weird places, and I have a hunch that it would slow our ability to make improvements in the future if we don't wrestle with it now. |
👍 Will look at this soon-ish, but the description so far sounds good. |
Alright, there's probably some more stuff that can happen here but I think it's ready for merge — any extra improvements can be made on top of this, I think the 'structure' is basically where it needs to be. Essentially, this clarifies a few internal concepts and moves some logic to more, well, logical places. Previously, as we walked the template AST, we tracked the current 'fragment' (which could be the template as a whole, an if/each block, or an element) as Instead, there's now a clean separation between blocks — things that result in Since node visitors are now responsible for visiting their own children, there's no need for hacks like I renamed a few things for consistency, e.g. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looked at it quite superficially, but the changes look really good!
#456 is ready to go and depends on this, so I'll merge it in |
Just a few high-level thoughts for now, since I'm about to leave my desk but want to get this out in the open. I have a completely unscientific feeling that there's a better way to handle a lot of the code generation stuff, that will be more readable, more maintainable and perhaps even more extensible, eventually.
I'd like to create a new
Fragment
class (or maybeBlock
) that handles some of the workGenerator
currently does. At the moment, there's a lot of weird indirection, e.g.generator.addElement
basically just hands over to the current fragment'sinit
builder, which is a little confusing.I also think that node visitors should be responsible for visiting their own children, since that makes it easier to control the order in which stuff happens, and makes it possible to pass parameters down to child nodes without awkwardly sticking properties on objects all over the place.
One of the immediate goals following this work is to hoist event handlers (where applicable), so this PR will need to bear that in mind (or include that work).