Skip to content

Refactor — eliminate 'hidden classes' #1316

Closed
@Rich-Harris

Description

@Rich-Harris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions