vscode-svelte-component-extractor
vscode-svelte-component-extractor copied to clipboard
Correctly extrapolate imports
Absolutely love this extension.
Wondering if it's possible for the extension to be "smart" about the imports.
Let's say that the main file has imports A,B,C,D,E and A,B,C are used by main logic and C,D,E are used by the new component.
Currently, both files will have A,B,C,D,E.
It would be neat if the old file would have D and E removed since they are no longer needed, and if the new file only had C,D,E since they are the only ones needed.
I'm assuming this problem is harder than it sounds, but figured I'd mention. I think this would add a lot of value to the end user experience.
Thanks again for the extension : )
You can configure VS Code to remove unused imports on save, so it will be quite easy to fix the original file.
Ideally, extracting a component would also check if some local function(s) from the <script>
should be moved to the new component. This is not trivial to do for all cases, though, as can have arbitrary JS constructs within your extracted component.
I can imagine that a proper solution would involve running Svelte's compiler over the original file to maybe determine such things, but I'm not sure this would work.