Use { parse } from 'svelte/compiler'
Benefits
svelte ecosystemesrapDownsides
esrapDepends on Rich-Harris/esrap#13. Currently published as esrap-typescript-temp for ease of use for testing. Otherwise, this would require using pnpm link locally with the branch mentioned before.
If we want to proceed with this (which i think we should), this needs to be done
packages/ast-tooling/ts-estree.ts seperately so that it can also be used inside esrap. Later they should probably live inside acorn-typescript once we fork itesrap understand what a TSModuleDeclaration is and how to print itesrap according to the types above. This will probably also require way more types in this new packageesrap and publish itCloses #44 Closes #118 Relates #100
This basically duplicates #100 at this point. See #100 for up and downsides of this approach.
I was initially intending to get rid of a lot more dependencies (like the dependencies for handling html) and use svelte-ast-print instead, but this was opening too many issues at the same time. That's why I opted to "only" switch to acorn and esrap here, the rest can be done later.
Relevant PR's / issues
Benefits
svelte ecosystemrecastesrapDownsides
TSEstree as no good public alternative exists, that matches acorns output. We do have @typescript-eslint/types but that was just the one with the smallest pain points. Still exploring other options.Closes #94 Closes svelte-add/svelte-add#193 Closes svelte-add/svelte-add#507
This is a pretty rough poc to try and make sv work better with .svelte files. Under the hood, this uses svelte-ast-print
Step 1 (support for svelte files):
@attach, self closing component tags, transitions, etc)parseSveltesvelte-ast-print support indentation and quote styles (I think some of that already works)svelte-ast-print (first write up: xeho91/js-ast#128)Step 2 (reduce deps, different pr probably)
svelte/compiler and svelte-ast-print. Check which hoops we need to jump to make that happen. We could potentially drop the following deps:
recast is using babel, which is much less used in the Svelte ecosystem, so folks wouldn't generally be as familiar with it
Same problem as with using acorn-typescript directly. The discussion about this started in Rich-Harris/esrap#13 and continued in TyrealHu/acorn-typescript#60.
Also this would likely require different handling for "native" js / ts, or a workaround. The workaround seems quite reasonable on the other hand.
Actually, a similar workaround could also be used for html. This would probably significantly bring down our bundle size and make @sveltejs/ast-tooling useless.
But once we have the ast, we will still need to do some serialization afterwards. And then we land on svelte-ast-print which brings us back up Rich-Harris/esrap#13 closing the circle 😆
i've never used recast before this project (only used acorn) and i've really come to hate it. it has many stupid quirks like this: #96 (comment), along with inadequate types (like for loc), so it would be great if we can switch off of it
Yeah, there are shortcomings of { parse } from 'svelte/compiler' from acorn-typescript for sure. There's an issue open in the Svelte repo about this: sveltejs/svelte#13439
I think the lack of types might not be too much of an issue for finding nodes as we'll mostly be looking for JS nodes?
For serialization, maybe we can do a more surgical approach like svelte-migrate? (I started to prototype this in #74)
Relates: svelte-add/svelte-add#507 Relates: svelte-add/svelte-add#193