-
-
Notifications
You must be signed in to change notification settings - Fork 203
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
Reimagining svelte2tsx #1077
Comments
This might be a good idea. Needs quite some effort though. It might have some downside we can think of now. I think we can do some proof of concept. We can also check some old issues and add some type-check tests for them so we didn't break them. About transformation ideas here is some more transformation idea:
|
More people use JavaScript than typescript, so can there be jsdoc definitions for events and slots with this new method? This is important to library authors to provide better DX. |
Goal: Get rid of a tsx-style transformation and simplify transformations along the way sveltejs#1077
Goal: Get rid of a tsx-style transformation and simplify transformations along the way #1077 #1256 #1149 Advantages: - no messing with projects who use JSX for some other reason and then have conflicting JSX definitions - TS control flow easier to keep flowing - overall easier transformations of Svelte specific syntax like await, each etc. - better type inference in some cases, for example around svelte:component This includes: - rewriting the html2jsx part of svelte2tsx - adjusting the language server to the new transformation - adding a toggle to language-server and vs code extension to turn on the new transformation. Default "off" for now, with the plan to switch it to "on" and then removing the old transformation altogether - ensuring tests run with both new and old transformation - adjusting the TypeScript plugin. It uses the new transformation already now since it's not easily possible to add an option (on/off). Should be low-impact since TS doesn't need to know much about the contents of a Svelte file, only its public API Look at the PR of this commit to see more explanations with some of the entry points of the new transformation.
Closing as we settled on a new transformation, opening a feedback thread before making it the new default. |
svelte2tsx has come quite a long way and is successfully representing some rather advanced use cases of Svelte in a TSX-compatible way. But there are significant drawbacks that continue to pile up:
What I envision is going away from a somewhat TSX-compliant structure and reimagine the translation more in line with our needs. One possible change is to no longer try to keep the HTML structure and instead focus on the control flow structure.
Given this input:
We no longer do this:
Instead we do this:
What this means is that we no longer try to wrap the contents of a html tag with that tag, instead we place the tag at the beginning, close it at the beginning, and can continue writing our transformations without having to use lambdas because we no longer are restricted to certain operators within the tag.
Code manipulation-wise, this means a lot more usage of MagicString's
move
.The following is a not yet complete list of transformation ideas:
await
each
slot - let:x
@jasonlyu123 thoughts?
The text was updated successfully, but these errors were encountered: