-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Import globals from internals #2963
Conversation
Unfortunately this breaks tree-shaking — all the globals, used or not, end up in bundles. Haven't come up with a decent solution yet |
Darn I had hoped Rollup would be able to cope with this. Would it be more treeshakable if we declared each variable separately, instead of destructuring all of them? |
I had thought it would, but no :( It's possible that it thinks |
(And even if Rollup could deal, there's still Other Bundlers to worry about) |
Another idea from @mrkishi on how to handle this - have a single |
Rebased on master and resolved conflicts - going to look into implementing the idea from the previous comment now. |
There are still a couple of clunky things here, but the tests are passing for me locally, hopefully CI will agree. |
@mrkishi Could you take a look at what I have here now? I'm wondering whether the change I had to make to the I did undo your change to |
2daf33d
to
f7c81cd
Compare
Yeah, the thing with Should we maybe start running tests inside the JSDOM vm instead of globally? |
Okay, I think we can worry about that in a separate PR. I've pushed an update to this one so that in |
I'm thinking it would make sense to only generate local aliases for globals that actually do conflict and need to be renamed. This would produce more normal-looking code more of the time. It might impact minifiability/gzipability, but I'm guessing that in general it really won't matter after gzip. If there aren't conflicts, this would produce the same code we are now without these changes. I have changes locally to do this, and will tidy them up and push. |
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.
Other than this typo, this looks good to go, no?
Good thing I decided to comb one (last? please?) time. I don't see any more! (it said, again..) I don't think it's worth it trying to improve the existing globals test because on top of defining the global we have to use relevant features to trigger the right codegen branch, and each time a new one is added we have to remember to update it. While we should still drop the Thoughts? That would go on a different PR though, of course. |
Hopefully fixes #2612 and #2947 and other similar types of potential issues. All (unless we missed some) globals used in code generated by Svelte now come from
svelte/internals
, so that we can avoid issues where other user variables shadow them.This makes it an error to say
@foo
iffoo
is not actually exported fromsvelte/internal
. All this affected currently wasadd_css
, which has been rewritten slightly to involve a manual call toget_unique_name
.Thanks to @mrkishi for finishing this up!