Open ottomated opened 2 hours ago
We'll fork in the short term but keep an eye out for how the other variants mature over time. The main blocker for adopting other parsers has been that AFAIK no other has a feature like Acorn's "parse expression", which we need for JS-like snippets within the template.
Looking into this. SWC doesn't expose a function like that but their Rust API exposes a parse_epxr()
function that can take something like () => foo++}>increment</button>
and spit out an AST (below).
This is what you need, right? In order to make this work, it would take a custom rust package that imports swc_ecma_parser
and exposes the custom methods you need to call from JS. This could either be wasm (probably easier) or node bindings (probably faster, but requires different binaries for each platform).
{
"type": "ArrowFunctionExpression",
"span": {
"start": 1,
"end": 12
},
"ctxt": 0,
"params": [],
"body": {
"type": "UpdateExpression",
"span": {
"start": 7,
"end": 12
},
"operator": "++",
"prefix": false,
"argument": {
"type": "Identifier",
"span": {
"start": 7,
"end": 10
},
"ctxt": 0,
"value": "foo",
"optional": false
}
},
"async": false,
"generator": false,
"typeParameters": null,
"returnType": null
}
Describe the problem
There are many issues that have
acorn-typescript
as the upstream cause (#13179, #13125, #13409, #13188, more), butacorn-typescript
is abandoned. It also has several open issues that would need to be addressed once forked or collaboration access is granted.Describe the proposed solution
One of the following:
acorn-typescript
. The svelte team would become the primary maintainers but it wouldn't require any changes to the svelte source code.swc
oroxc
. SWC seems to use the same AST types as acorn, but oxc advertises faster speeds. These parsers are much more mature thanacorn-typescript
and are obviously actively maintained. (note: oxc would require changes to both esrap and the svelte source)My vote would be for the latter. The downsides (bigger dependencies and changes to svelte's source) are outweighed by the long-term advantage of using a more reliable library.
Importance
nice to have