-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
(feat) rewrite svelte2tsx #1237
Conversation
Goal: Get rid of a tsx-style transformation and simplify transformations along the way sveltejs#1077
…ingsNamespace setting (better name for that? good API yet?)
…e, because of hover etc: This will make map deleted characters to the whitespace
… and better rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. Besides those listed in the review comment. I also found some other problems:
- this would fail to transform because of magic string edits overlap
<script>
import { readable } from "svelte/store";
const store = readable(11);
</script>
<div {...$store}></div>
- style directive and const tag doesn’t seem to have an
expectedv2.json
- if you rename component
on:some-event
it would only show the first character of the event name in the input.
*p.s I deleted two outdated comments made a while ago. Can't delete it before I submit XD.
packages/language-server/src/plugins/typescript/features/RenameProvider.ts
Outdated
Show resolved
Hide resolved
Thanks! I adressed your review comments. I also noticed that I should tweak Document Symbols a little, and that we need to update the TS plugin as well. Since there's no way to tell the TS plugin to either use the new or old version I decided to switch on the new version for the TS plugin by default. Need to test this more though. I also added the possibility to add a namespace to the tsconfig for targets like SvelteNative like we discussed in Discord. @jasonlyu123 in your opinion, will this new transformation enable us to enhance svelte2tsx with new transformations more easily? Is the transformation code easier or worse to read now in your opion? |
I think It's more focused on the core transformation. Overall should be easier to read. On another note. I forgot to mention a problem yesterday. I found that the props transformation moves the props value now. So this causes the trailing property access to be removed under For example: <Component props={obj.} /> But this can also be done later. I'm thinking if we can detect this trailing property access while transforming. It should also be applied to the if block and await block so that the completion is right. Edit: I tried and it seems possible. I think I'll have a PR for both v1 and v2 later once this is mered. Another thing I found it's worth noting for users to migrate in the future is: Because we're now transforming it into direct component class instantiate. If you have a component typedef like this export class Component {
$$prop_def: SomePropsType
} You can change this to use the export class Component extends SvelteComponentTyped<SomeProps> {} if you're extending a component class that has different props types. Be sure to also override the constructor type. |
This looks great. I appreciate the work you did to guard it behind a feature flag 👍 which should allow us keen users to get our hands on it early and help work out any kinks. |
Goal: Get rid of a tsx-style transformation and simplify transformations along the way
#1077
#1256
#1149
Advantages:
This includes:
Notes to self:
#each foo as foo
and#await foo then foo
are both valid Svelte code but the transformation is invalid ("variable used before declaration"). Solution could be to move the firstfoo
into a different block like{const $$foo = foo; { const foo = await $$foo; } }
. UPDATE this is handled now<Component validPropWrongType1={true} invalidProp1={true} />
will only show an error forvalidPropWrongType1
and forinvalidProp1
only after the first error is fixed. It will also underlinevalidPropWrongType1
and nottrue
. This is a hit I'm okay to take.