Description
Other projects I've worked on that involve a lot of AST traversal and analysis, such as Rollup and Bublé, have converged on an approach that I quite like, whereby the (POJO) nodes of an AST are augmented so that they look and feel like instances of a class, like this example of a FunctionDeclaration node. (The augmentation happens here by setting node.__proto__
— hold your nose if you find that sort of thing distasteful.) The result is a codebase that's a lot neater and reason-about-able than it could easily have devolved into.
It occurred to me just now, while bashing my head against a wall trying to get nodes inside a dynamic component to remount to a new instance's slots, that Svelte would benefit a great deal from a similar approach. It would mean the various 'phases' of compilation were no longer spread across the codebase confusingly, and we could get rid of hacks like this. We could probably even unify the visitors for DOM and SSR compilers.
Definitely a chunky refactor, but now that I can picture it I'm really keen to give it a whirl.