svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Expose Svelte AST node types from `svelte/compiler` to public

Open xeho91 opened this issue 1 year ago • 5 comments

Describe the problem

As per thread on Discord.

I was working on addon for Storybook - @storybook/addon-svelte-csf. It uses svelte/compiler to extract Svelte AST nodes and analyss them for further code transformation.

Then I upgraded Svelte version. And I have noticed that since this release [email protected] AST nodes from svelte/compiler are no longer exposed to public.

Such as:

  • Component (AST version)
  • Root
  • SnippetBlock
  • SvelteNode
  • ... etc.

Possibly related PR: https://github.com/Rich-Harris/dts-buddy/pull/82

Describe the proposed solution

I would like to be able to access those Svelte AST nodes, so I can have a better typings experience on those AST data structures.

Importance

would make my life easier

xeho91 avatar Jul 04 '24 04:07 xeho91

We also need need this to get SvelteKit passing against the ecosystem CI since enhanced-img uses things like TemplateNode, BaseDirective, Attribute, and SpreadAttribute

https://github.com/sveltejs/kit/blob/43544107269013e8b5160d268da25f1e003b6f6f/packages/enhanced-img/src/preprocessor.js#L44 https://github.com/sveltejs/kit/blob/43544107269013e8b5160d268da25f1e003b6f6f/packages/enhanced-img/src/preprocessor.js#L216

benmccann avatar Jul 06 '24 21:07 benmccann

If we expose them again I'd like us to make sure somehow to not expose the internal properties of the AST nodes (for example metadata)

dummdidumm avatar Jul 06 '24 21:07 dummdidumm

Hey @dummdidumm, is it just the metadata that needs to be omitted from the public interfaces or is there more? Not having these types is blocking us on a couple of things, so we are willing to attempt a PR with some guidance.

I imagine the desire is to incorporate this into the build script rather than just exporting with Omit right?

huntabyte avatar Aug 08 '24 22:08 huntabyte

Yeah metadata is basically all that needs to be removed (and if there's a parent property, then that, too). I have no opinion at this time how it should be accomplished, as long as it's low maintenance, stable and relatively straightforward

dummdidumm avatar Aug 09 '24 19:08 dummdidumm

@huntabyte there was some additional discussion in the original Discord thread FYI: https://discord.com/channels/457912077277855764/1258093339232702556

vnphanquang avatar Aug 10 '24 04:08 vnphanquang