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

Refactor — eliminate 'hidden classes' #1316

Closed
Rich-Harris opened this issue Apr 4, 2018 · 0 comments
Closed

Refactor — eliminate 'hidden classes' #1316

Rich-Harris opened this issue Apr 4, 2018 · 0 comments

Comments

@Rich-Harris
Copy link
Member

This Rollup issue got me thinking. #992 moved away from the concept of 'visitors' to the current approach, whereby AST nodes are converted into classes that implement common methods like build alongside more specialised ones.

It works, but:

  • it means we have to clone the AST, so that it can be included in the svelte.compile output
  • there are performance downsides to changing prototypes
  • we're locked in to the structure of the AST generated by svelte.parse, which isn't necessarily the best structure for later phases (e.g. bindings and event handlers are lumped in with attributes). I don't think there's any guarantee that the parser could create the optimal structure

So what I propose, in essence, is that instead of augmenting the existing AST nodes we create entirely new objects. Instead of

Object.setPrototypeOf(node, EachBlock.prototype);

it would be

new EachBlock(node);

and the EachBlock constructor would be responsible for instantiating its children.

Rich-Harris added a commit that referenced this issue Apr 23, 2018
Rich-Harris added a commit that referenced this issue Apr 23, 2018
@Rich-Harris Rich-Harris mentioned this issue Apr 23, 2018
Rich-Harris added a commit that referenced this issue Apr 29, 2018
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

1 participant