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
[fix] do not generate unused-export-let inside <script context="module"> #7232
Conversation
Fixes sveltejs#7055 I think this might be the best way to fix the linked issue, and I think it's a reasonable change. Since code inside <script context="module"> is basically just regular JS, warnings like this can be delegated to userland tools--I don't think it needs to be the Svelte compiler's business especially when these compiler warnings cannot be ignored inline.
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.
I tend to agree with this change, but I don't know how other maintainers feel about it
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.
Makes sense to me.
Here's a quick summary of the issue. When you do
The Svelte compiler then gives a warning that I don't see any way to get TypeScript to generate Separately, it also seems that the warning may be broken and giving false positives even outside of using TypeScript: https://svelte.dev/repl/6650478bb7fc474f8c43f82c92694b76?version=3.46.4 I guess my only question would be what happens in the non-TypeScript case. Can we have |
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.
https://github.com/sveltejs/eslint-plugin-svelte3#features says it handles script
blocks and @rgossiaux reported that https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-mutable-exports.md worked. That's good enough for me
I did a deeper dive on exactly what's going on here. You can see in this REPL that this warning seems to be generated for every From this code: svelte/src/compiler/compile/Component.ts Lines 176 to 186 in 9b7b814
You can see that the compiler first checks the module JS, then the instance JS, the template, and finally the instance JS again. Since the module JS is processed first before everything else, it doesn't know about any references in the other parts, so referencing something in the instance script doesn't actually affect whether it's considered "unused" for the purposes of this warning. As for references inside the module script, as far as I can tell, the compiler doesn't actually process them (after all, there's no need to; it's just normal JS). I confirmed with the In short, this |
…"> (sveltejs#7232) Fixes sveltejs#7055. This warning can be delegated to userland tools like eslint
Incorporate specification changes of this PR. sveltejs/svelte#7232
Fixes #7055
I think this might be the best way to fix the linked issue, and I think it's a reasonable change. Since code inside
<script context="module">
is basically just regular JS, warnings like this can be delegated to userland tools--I don't think it needs to be the Svelte compiler's business especially when these compiler warnings cannot be ignored inline.Before submitting the PR, please make sure you do the following
[feat]
,[fix]
,[chore]
, or[docs]
.Tests
npm test
and lint the project withnpm run lint